From b92ab1e75f4e8a5ca72b8fc1632716f00b2f03ca Mon Sep 17 00:00:00 2001 From: Christopher Rigor Date: Tue, 5 Jan 2021 21:13:03 +0800 Subject: [PATCH 1/2] Add support for Rails 6.0 and 6.1 --- .../activerecord_5_0_0/polymorphic_array_value_extension.rb | 3 ++- polymorphic_integer_type.gemspec | 2 +- spec/polymorphic_integer_type_spec.rb | 4 ++-- spec/spec_helper.rb | 4 +++- 4 files changed, 8 insertions(+), 5 deletions(-) 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..4978fa9 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,8 @@ module PolymorphicArrayValueExtension # end def type_to_ids_mapping - association = @associated_table.send(:association) + association_method = Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("6.1.0") ? :reflection : :association + association = @associated_table.send(association_method) name = association.name default_hash = Hash.new { |hsh, key| hsh[key] = [] } values.each_with_object(default_hash) do |value, hash| diff --git a/polymorphic_integer_type.gemspec b/polymorphic_integer_type.gemspec index d0d882e..68a0e45 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" + spec.add_dependency "activerecord" spec.add_development_dependency "bundler" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" diff --git a/spec/polymorphic_integer_type_spec.rb b/spec/polymorphic_integer_type_spec.rb index 9ca0fbf..563fa49 100644 --- a/spec/polymorphic_integer_type_spec.rb +++ b/spec/polymorphic_integer_type_spec.rb @@ -164,7 +164,7 @@ context "and when it already has a polymorphic record" do let(:target) { kibble } - before { link.update_attributes(target: target) } + before { link.update(target: target) } include_examples "proper source" include_examples "proper target" @@ -178,7 +178,7 @@ context "and when it already has a polymorphic id and type" do let(:target) { kibble } - before { link.update_attributes(target_id: target.id, target_type: target.class.to_s) } + before { link.update(target_id: target.id, target_type: target.class.to_s) } include_examples "proper source" include_examples "proper target" end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 915c894..3c0256c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -18,7 +18,9 @@ config.before(:suite) do database_config = YAML.load(File.open("#{File.dirname(__FILE__)}/support/database.yml")) ActiveRecord::Base.establish_connection(database_config) - if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("5.2.0") + if Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("6.0.0") + ActiveRecord::MigrationContext.new("#{File.dirname(__FILE__)}/support/migrations", ActiveRecord::Base.connection.schema_migration).migrate + elsif Gem::Version.new(ActiveRecord::VERSION::STRING) >= Gem::Version.new("5.2.0") ActiveRecord::MigrationContext.new("#{File.dirname(__FILE__)}/support/migrations").migrate end end From 8c54ceab3ac421adf4c51aa83862e5c390bf53ea Mon Sep 17 00:00:00 2001 From: Christopher Rigor Date: Tue, 5 Jan 2021 21:16:42 +0800 Subject: [PATCH 2/2] Add gemfiles for Rails 6.0 and 6.1 --- gemfiles/Gemfile.rails-6.0-stable | 7 +++ gemfiles/Gemfile.rails-6.0-stable.lock | 74 ++++++++++++++++++++++++++ gemfiles/Gemfile.rails-6.1-stable | 7 +++ gemfiles/Gemfile.rails-6.1-stable.lock | 73 +++++++++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 gemfiles/Gemfile.rails-6.0-stable create mode 100644 gemfiles/Gemfile.rails-6.0-stable.lock create mode 100644 gemfiles/Gemfile.rails-6.1-stable create mode 100644 gemfiles/Gemfile.rails-6.1-stable.lock diff --git a/gemfiles/Gemfile.rails-6.0-stable b/gemfiles/Gemfile.rails-6.0-stable new file mode 100644 index 0000000..8b85563 --- /dev/null +++ b/gemfiles/Gemfile.rails-6.0-stable @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +gemspec path: ".." + +gem "activerecord", github: "rails/rails", branch: "6-0-stable" diff --git a/gemfiles/Gemfile.rails-6.0-stable.lock b/gemfiles/Gemfile.rails-6.0-stable.lock new file mode 100644 index 0000000..595c71c --- /dev/null +++ b/gemfiles/Gemfile.rails-6.0-stable.lock @@ -0,0 +1,74 @@ +GIT + remote: https://github.com/rails/rails.git + revision: f64f7c649d7d6c05bd1a0309f6dd3936ff2c4644 + branch: 6-0-stable + specs: + activemodel (6.0.3.4) + activesupport (= 6.0.3.4) + activerecord (6.0.3.4) + activemodel (= 6.0.3.4) + activesupport (= 6.0.3.4) + activesupport (6.0.3.4) + 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 (2.3.1) + activerecord + +GEM + remote: https://rubygems.org/ + specs: + byebug (11.1.3) + coderay (1.1.3) + concurrent-ruby (1.1.7) + diff-lcs (1.4.4) + i18n (1.8.7) + concurrent-ruby (~> 1.0) + method_source (1.0.0) + minitest (5.14.2) + 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.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-support (3.10.1) + 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/gemfiles/Gemfile.rails-6.1-stable.lock b/gemfiles/Gemfile.rails-6.1-stable.lock new file mode 100644 index 0000000..a82582c --- /dev/null +++ b/gemfiles/Gemfile.rails-6.1-stable.lock @@ -0,0 +1,73 @@ +GIT + remote: https://github.com/rails/rails.git + revision: 6fb3884ca9dcc08765dc8b7852d8d139b885ca03 + branch: 6-1-stable + specs: + activemodel (6.1.0) + activesupport (= 6.1.0) + activerecord (6.1.0) + activemodel (= 6.1.0) + activesupport (= 6.1.0) + activesupport (6.1.0) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (>= 1.6, < 2) + minitest (>= 5.1) + tzinfo (~> 2.0) + zeitwerk (~> 2.3) + +PATH + remote: .. + specs: + polymorphic_integer_type (2.3.1) + activerecord + +GEM + remote: https://rubygems.org/ + specs: + byebug (11.1.3) + coderay (1.1.3) + concurrent-ruby (1.1.7) + diff-lcs (1.4.4) + i18n (1.8.7) + concurrent-ruby (~> 1.0) + method_source (1.0.0) + minitest (5.14.2) + 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.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.10.0) + rspec-support (3.10.1) + sqlite3 (1.4.2) + tzinfo (2.0.4) + concurrent-ruby (~> 1.0) + zeitwerk (2.4.2) + +PLATFORMS + ruby + +DEPENDENCIES + activerecord! + bundler + polymorphic_integer_type! + pry-byebug + rake + rspec + sqlite3 + +BUNDLED WITH + 2.1.4