Skip to content

Commit 01be377

Browse files
authored
Support for Rails 6.1.4.1 and onward (Until 7) + Supporting CI Changes. (#47)
* Support for rails below * formatting * run bundle install before bundle exec. * cache bad. * delete lock files. * rails 6.1 test * add force:false * conditional force:false * set fail fast to be false * use association or reflection depending on version.
1 parent 24eb372 commit 01be377

9 files changed

+31
-304
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ jobs:
1111
runs-on: ubuntu-latest
1212

1313
strategy:
14+
fail-fast: false
1415
matrix:
1516
gemfile:
1617
- Gemfile.rails-5.0-stable
1718
- Gemfile.rails-5.1-stable
1819
- Gemfile.rails-5.2-stable
1920
- Gemfile.rails-6.0-stable
21+
- Gemfile.rails-6.1-stable
2022
env:
2123
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
2224
steps:
@@ -25,6 +27,8 @@ jobs:
2527
uses: ruby/setup-ruby@v1
2628
with:
2729
ruby-version: "2.6"
28-
bundler-cache: true
30+
- name: Install dependencies
31+
run: bundle install
2932
- name: Run tests
30-
run: bundle exec rspec
33+
run:
34+
bundle exec rspec

gemfiles/Gemfile.rails-5.0-stable.lock

Lines changed: 0 additions & 74 deletions
This file was deleted.

gemfiles/Gemfile.rails-5.1-stable.lock

Lines changed: 0 additions & 74 deletions
This file was deleted.

gemfiles/Gemfile.rails-5.2-stable.lock

Lines changed: 0 additions & 74 deletions
This file was deleted.

gemfiles/Gemfile.rails-6.0-stable.lock

Lines changed: 0 additions & 74 deletions
This file was deleted.

gemfiles/Gemfile.rails-6.1-stable

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
gemspec path: ".."
6+
7+
gem "activerecord", github: "rails/rails", branch: "6-1-stable"

lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ module PolymorphicArrayValueExtension
1010
# end
1111

1212
def type_to_ids_mapping
13-
association = @associated_table.send(:association)
13+
if ACTIVE_RECORD_VERSION < Gem::Version.new("6.1")
14+
association = @associated_table.send(:association)
15+
else
16+
association = @associated_table.send(:reflection)
17+
end
18+
1419
name = association.name
1520
default_hash = Hash.new { |hsh, key| hsh[key] = [] }
1621
values.each_with_object(default_hash) do |value, hash|

lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
module ActiveRecord
22
module Associations
33
class BelongsToPolymorphicAssociation < BelongsToAssociation
4-
private def replace_keys(record)
5-
super
6-
unless record.nil?
7-
owner[reflection.foreign_type] = record.class.base_class
4+
private
5+
6+
if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("6.1")
7+
def replace_keys(record)
8+
super
9+
owner[reflection.foreign_type] = record.class.base_class unless record.nil?
10+
end
11+
elsif
12+
def replace_keys(record, force: false)
13+
super
14+
owner[reflection.foreign_type] = record.class.base_class unless record.nil?
815
end
916
end
1017
end

polymorphic_integer_type.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
1818
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
1919
spec.require_paths = ["lib"]
2020

21-
spec.add_dependency "activerecord", "< 6.1"
21+
spec.add_dependency "activerecord", "< 7"
2222
spec.add_development_dependency "bundler"
2323
spec.add_development_dependency "rake"
2424
spec.add_development_dependency "rspec"

0 commit comments

Comments
 (0)