diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bd52a15..e5fcb0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,12 +11,14 @@ jobs: runs-on: ubuntu-latest strategy: + fail-fast: false matrix: gemfile: - Gemfile.rails-5.0-stable - Gemfile.rails-5.1-stable - Gemfile.rails-5.2-stable - Gemfile.rails-6.0-stable + - Gemfile.rails-6.1-stable env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }} steps: @@ -25,6 +27,8 @@ jobs: uses: ruby/setup-ruby@v1 with: ruby-version: "2.6" - bundler-cache: true + - name: Install dependencies + run: bundle install - name: Run tests - run: bundle exec rspec + run: + bundle exec rspec diff --git a/gemfiles/Gemfile.rails-5.0-stable.lock b/gemfiles/Gemfile.rails-5.0-stable.lock deleted file mode 100644 index 300c6b1..0000000 --- a/gemfiles/Gemfile.rails-5.0-stable.lock +++ /dev/null @@ -1,74 +0,0 @@ -GIT - remote: https://github.com/rails/rails.git - revision: ac6aa32f7cf66264ba87eabed7c042bb60bcf3a2 - branch: 5-0-stable - specs: - activemodel (5.0.7.2) - activesupport (= 5.0.7.2) - activerecord (5.0.7.2) - activemodel (= 5.0.7.2) - activesupport (= 5.0.7.2) - arel (~> 7.0) - activesupport (5.0.7.2) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - -PATH - remote: .. - specs: - polymorphic_integer_type (3.0.0) - activerecord (< 6.1) - -GEM - remote: https://rubygems.org/ - specs: - arel (7.1.4) - byebug (11.1.3) - coderay (1.1.3) - concurrent-ruby (1.1.8) - diff-lcs (1.4.4) - i18n (1.8.10) - concurrent-ruby (~> 1.0) - method_source (1.0.0) - minitest (5.14.4) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - rake (13.0.3) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - sqlite3 (1.3.13) - thread_safe (0.3.6) - tzinfo (1.2.9) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activerecord! - bundler - polymorphic_integer_type! - pry-byebug - rake - rspec - sqlite3 (~> 1.3.6) - -BUNDLED WITH - 2.1.4 diff --git a/gemfiles/Gemfile.rails-5.1-stable.lock b/gemfiles/Gemfile.rails-5.1-stable.lock deleted file mode 100644 index 070ca95..0000000 --- a/gemfiles/Gemfile.rails-5.1-stable.lock +++ /dev/null @@ -1,74 +0,0 @@ -GIT - remote: https://github.com/rails/rails.git - revision: 663206d20aec374a28a24bb43bc7b1233042ed9b - branch: 5-1-stable - specs: - activemodel (5.1.7) - activesupport (= 5.1.7) - activerecord (5.1.7) - activemodel (= 5.1.7) - activesupport (= 5.1.7) - arel (~> 8.0) - activesupport (5.1.7) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - -PATH - remote: .. - specs: - polymorphic_integer_type (3.0.0) - activerecord (< 6.1) - -GEM - remote: https://rubygems.org/ - specs: - arel (8.0.0) - byebug (11.1.3) - coderay (1.1.3) - concurrent-ruby (1.1.8) - diff-lcs (1.4.4) - i18n (1.8.10) - concurrent-ruby (~> 1.0) - method_source (1.0.0) - minitest (5.14.4) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - rake (13.0.3) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - sqlite3 (1.4.2) - thread_safe (0.3.6) - tzinfo (1.2.9) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activerecord! - bundler - polymorphic_integer_type! - pry-byebug - rake - rspec - sqlite3 - -BUNDLED WITH - 2.1.4 diff --git a/gemfiles/Gemfile.rails-5.2-stable.lock b/gemfiles/Gemfile.rails-5.2-stable.lock deleted file mode 100644 index d12ecde..0000000 --- a/gemfiles/Gemfile.rails-5.2-stable.lock +++ /dev/null @@ -1,74 +0,0 @@ -GIT - remote: https://github.com/rails/rails.git - revision: 48661542a2607d55f436438fe21001d262e61fec - branch: 5-2-stable - specs: - activemodel (5.2.6) - activesupport (= 5.2.6) - activerecord (5.2.6) - activemodel (= 5.2.6) - activesupport (= 5.2.6) - arel (>= 9.0) - activesupport (5.2.6) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - -PATH - remote: .. - specs: - polymorphic_integer_type (3.0.0) - activerecord (< 6.1) - -GEM - remote: https://rubygems.org/ - specs: - arel (9.0.0) - byebug (11.1.3) - coderay (1.1.3) - concurrent-ruby (1.1.8) - diff-lcs (1.4.4) - i18n (1.8.10) - concurrent-ruby (~> 1.0) - method_source (1.0.0) - minitest (5.14.4) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - rake (13.0.3) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - sqlite3 (1.4.2) - thread_safe (0.3.6) - tzinfo (1.2.9) - thread_safe (~> 0.1) - -PLATFORMS - ruby - -DEPENDENCIES - activerecord! - bundler - polymorphic_integer_type! - pry-byebug - rake - rspec - sqlite3 - -BUNDLED WITH - 2.1.4 diff --git a/gemfiles/Gemfile.rails-6.0-stable.lock b/gemfiles/Gemfile.rails-6.0-stable.lock deleted file mode 100644 index 07288b4..0000000 --- a/gemfiles/Gemfile.rails-6.0-stable.lock +++ /dev/null @@ -1,74 +0,0 @@ -GIT - remote: https://github.com/rails/rails.git - revision: ef97441036e0ebbe1aa2108d59c408707f998ffd - branch: 6-0-stable - specs: - activemodel (6.0.3.7) - activesupport (= 6.0.3.7) - activerecord (6.0.3.7) - activemodel (= 6.0.3.7) - activesupport (= 6.0.3.7) - activesupport (6.0.3.7) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) - -PATH - remote: .. - specs: - polymorphic_integer_type (3.0.0) - activerecord (< 6.1) - -GEM - remote: https://rubygems.org/ - specs: - byebug (11.1.3) - coderay (1.1.3) - concurrent-ruby (1.1.8) - diff-lcs (1.4.4) - i18n (1.8.10) - concurrent-ruby (~> 1.0) - method_source (1.0.0) - minitest (5.14.4) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - rake (13.0.3) - rspec (3.10.0) - rspec-core (~> 3.10.0) - rspec-expectations (~> 3.10.0) - rspec-mocks (~> 3.10.0) - rspec-core (3.10.1) - rspec-support (~> 3.10.0) - rspec-expectations (3.10.1) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-mocks (3.10.2) - diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.10.0) - rspec-support (3.10.2) - sqlite3 (1.4.2) - thread_safe (0.3.6) - tzinfo (1.2.9) - thread_safe (~> 0.1) - zeitwerk (2.4.2) - -PLATFORMS - ruby - -DEPENDENCIES - activerecord! - bundler - polymorphic_integer_type! - pry-byebug - rake - rspec - sqlite3 - -BUNDLED WITH - 2.1.4 diff --git a/gemfiles/Gemfile.rails-6.1-stable b/gemfiles/Gemfile.rails-6.1-stable new file mode 100644 index 0000000..a50681f --- /dev/null +++ b/gemfiles/Gemfile.rails-6.1-stable @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gemspec path: ".." + +gem "activerecord", github: "rails/rails", branch: "6-1-stable" diff --git a/lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb b/lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb index eb386ee..7f1fc5e 100644 --- a/lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb +++ b/lib/polymorphic_integer_type/activerecord_5_0_0/polymorphic_array_value_extension.rb @@ -10,7 +10,12 @@ module PolymorphicArrayValueExtension # end def type_to_ids_mapping - association = @associated_table.send(:association) + if ACTIVE_RECORD_VERSION < Gem::Version.new("6.1") + association = @associated_table.send(:association) + else + association = @associated_table.send(:reflection) + end + name = association.name default_hash = Hash.new { |hsh, key| hsh[key] = [] } values.each_with_object(default_hash) do |value, hash| diff --git a/lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb b/lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb index edb21cd..8840fc2 100644 --- a/lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb +++ b/lib/polymorphic_integer_type/belongs_to_polymorphic_association_extension.rb @@ -1,10 +1,17 @@ module ActiveRecord module Associations class BelongsToPolymorphicAssociation < BelongsToAssociation - private def replace_keys(record) - super - unless record.nil? - owner[reflection.foreign_type] = record.class.base_class + private + + if Gem::Version.new(ActiveRecord::VERSION::STRING) < Gem::Version.new("6.1") + def replace_keys(record) + super + owner[reflection.foreign_type] = record.class.base_class unless record.nil? + end + elsif + def replace_keys(record, force: false) + super + owner[reflection.foreign_type] = record.class.base_class unless record.nil? end end end diff --git a/polymorphic_integer_type.gemspec b/polymorphic_integer_type.gemspec index 1230f50..b226df3 100644 --- a/polymorphic_integer_type.gemspec +++ b/polymorphic_integer_type.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |spec| spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] - spec.add_dependency "activerecord", "< 6.1" + spec.add_dependency "activerecord", "< 7" spec.add_development_dependency "bundler" spec.add_development_dependency "rake" spec.add_development_dependency "rspec"