From e53044ecc3eb9d49992f932181cfbf5290842a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 4 Mar 2022 13:53:37 +0100 Subject: [PATCH 1/5] Remove duplicated command in contributing docs --- CONTRIBUTING.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2c2c5f1e..57437fd3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -66,8 +66,6 @@ Here's a quick guide: 3. Install the development dependencies by running `bundle install`. To install rails other than latest (set in Gemfile): `RAILS='5-2-stable' bundle install` - $ RAILS='5-2-stable' bundle install - 4. Begin by running the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate: From 9b683d6d0115f4b67789e076d6e86347fe2ab23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 4 Mar 2022 13:56:25 +0100 Subject: [PATCH 2/5] Remove strange comments at the top of two files --- lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb | 1 - lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb b/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb index e2ce3e3e..201cb535 100644 --- a/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb +++ b/lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb @@ -1,4 +1,3 @@ -# active_record_6.0_ruby_2/join_dependency.rb module Polyamorous module JoinDependencyExtensions # Replaces ActiveRecord::Associations::JoinDependency#build diff --git a/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb b/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb index 81253e87..f9cd1d8c 100644 --- a/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb +++ b/lib/polyamorous/activerecord_6.1_ruby_2/join_dependency.rb @@ -1,4 +1,3 @@ -# active_record_6.1_ruby_2/join_dependency.rb module Polyamorous module JoinDependencyExtensions # Replaces ActiveRecord::Associations::JoinDependency#build From ffa7bb70654dfbb8daa7759dce604fb150fbe07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 4 Mar 2022 13:57:11 +0100 Subject: [PATCH 3/5] Remove redundant checks We only support Rails versions higher than this. --- lib/ransack/helpers/form_helper.rb | 2 +- spec/ransack/helpers/form_helper_spec.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/ransack/helpers/form_helper.rb b/lib/ransack/helpers/form_helper.rb index 03a84ca5..fa8f82a5 100644 --- a/lib/ransack/helpers/form_helper.rb +++ b/lib/ransack/helpers/form_helper.rb @@ -145,7 +145,7 @@ def html_options(args) private def parameters_hash(params) - if ::ActiveRecord::VERSION::MAJOR >= 5 && params.respond_to?(:to_unsafe_h) + if params.respond_to?(:to_unsafe_h) params.to_unsafe_h else params diff --git a/spec/ransack/helpers/form_helper_spec.rb b/spec/ransack/helpers/form_helper_spec.rb index d8edd081..0b1d338a 100644 --- a/spec/ransack/helpers/form_helper_spec.rb +++ b/spec/ransack/helpers/form_helper_spec.rb @@ -469,8 +469,7 @@ module Helpers it { should match /exist\=existing/ } end - context 'using a real ActionController::Parameter object', - if: ::ActiveRecord::VERSION::MAJOR > 3 do + context 'using a real ActionController::Parameter object' do describe 'with symbol q:, #sort_link should include search params' do subject { @controller.view_context.sort_link(Person.ransack, :name) } From 9b0fb3a50b723e1651ad51169e6464ae8f7065c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 4 Mar 2022 13:57:44 +0100 Subject: [PATCH 4/5] Remove dead spec It only runs on Rails 5.1 or older, no longer supported. --- spec/polyamorous/join_dependency_spec.rb | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/spec/polyamorous/join_dependency_spec.rb b/spec/polyamorous/join_dependency_spec.rb index c40e72a3..4800c2b8 100644 --- a/spec/polyamorous/join_dependency_spec.rb +++ b/spec/polyamorous/join_dependency_spec.rb @@ -77,21 +77,5 @@ module Polyamorous specify { expect(subject.send(:join_root).drop(1)[1].table_name) .to eq 'comments' } end - - context '#left_outer_join in Rails 5 overrides join type specified', - if: ActiveRecord::VERSION::MAJOR >= 5 && ActiveRecord::VERSION::MAJOR < 6 && ActiveRecord::VERSION::MINOR < 2 do - - let(:join_type_class) do - new_join_dependency( - Person, - new_join(:articles) - ).join_constraints( - [], - Arel::Nodes::OuterJoin - ).first.joins.map(&:class) - end - - specify { expect(join_type_class).to eq [Arel::Nodes::OuterJoin] } - end end end From feed41cb8ab47557cd6b36ec54427febfa46d73f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Fri, 4 Mar 2022 13:58:28 +0100 Subject: [PATCH 5/5] Drop Rails 5.2 support --- .github/workflows/test.yml | 18 ----- CONTRIBUTING.md | 2 +- README.md | 2 +- .../join_association.rb | 20 ----- .../join_dependency.rb | 79 ------------------- .../activerecord_5.2_ruby_2/reflection.rb | 11 --- .../join_association.rb | 21 ++++- .../activerecord_6.0_ruby_2/reflection.rb | 12 ++- .../active_record/ransack/nodes/condition.rb | 2 +- ransack.gemspec | 4 +- 10 files changed, 36 insertions(+), 135 deletions(-) delete mode 100644 lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb delete mode 100644 lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb delete mode 100644 lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9632cd61..cc3809c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,8 +15,6 @@ jobs: - v6.1.4 - v6.0.4 - 6-0-stable - - 5-2-stable - - v5.2.4 ruby: - 3.0.2 - 2.7.4 @@ -24,10 +22,6 @@ jobs: exclude: - rails: v7.0.0 ruby: 2.6.7 - - rails: v5.2.4 - ruby: 3.0.2 - - rails: 5-2-stable - ruby: 3.0.2 env: DB: sqlite3 RAILS: ${{ matrix.rails }} @@ -52,8 +46,6 @@ jobs: - v6.1.4 - v6.0.4 - 6-0-stable - - 5-2-stable - - v5.2.4 ruby: - 3.0.2 - 2.7.4 @@ -61,10 +53,6 @@ jobs: exclude: - rails: v7.0.0 ruby: 2.6.7 - - rails: v5.2.4 - ruby: 3.0.2 - - rails: 5-2-stable - ruby: 3.0.2 env: DB: mysql RAILS: ${{ matrix.rails }} @@ -98,8 +86,6 @@ jobs: - v6.1.4 - v6.0.4 - 6-0-stable - - 5-2-stable - - v5.2.4 ruby: - 3.0.2 - 2.7.4 @@ -107,10 +93,6 @@ jobs: exclude: - rails: v7.0.0 ruby: 2.6.7 - - rails: v5.2.4 - ruby: 3.0.2 - - rails: 5-2-stable - ruby: 3.0.2 env: DB: postgres RAILS: ${{ matrix.rails }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 57437fd3..c71f5e73 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -64,7 +64,7 @@ Here's a quick guide: 2. Create a thoughtfully-named branch for your changes (`git checkout -b my-new-feature`). 3. Install the development dependencies by running `bundle install`. - To install rails other than latest (set in Gemfile): `RAILS='5-2-stable' bundle install` + To install rails other than latest (set in Gemfile): `RAILS='6-0-stable' bundle install` 4. Begin by running the tests. We only take pull requests with passing tests, and it's great to know that you have a clean slate: diff --git a/README.md b/README.md index 2a688c22..c20b6574 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ or controller layer, you're probably not looking for Ransack. ## Getting started -Ransack is supported for Rails 7.0, 6.x, 5.2 on Ruby 2.6.6 and later. +Ransack is supported for Rails 7.0, 6.x on Ruby 2.6.6 and later. In your Gemfile, for the last officially released gem: diff --git a/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb b/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb deleted file mode 100644 index fd836fa1..00000000 --- a/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Polyamorous - module JoinAssociationExtensions - include SwappingReflectionClass - def self.prepended(base) - base.class_eval { attr_reader :join_type } - end - - def initialize(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin) - @join_type = join_type - if polymorphic_class && ::ActiveRecord::Base > polymorphic_class - swapping_reflection_klass(reflection, polymorphic_class) do |reflection| - super(reflection, children) - self.reflection.options[:polymorphic] = true - end - else - super(reflection, children) - end - end - end -end diff --git a/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb b/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb deleted file mode 100644 index 58b9f674..00000000 --- a/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb +++ /dev/null @@ -1,79 +0,0 @@ -module Polyamorous - module JoinDependencyExtensions - # Replaces ActiveRecord::Associations::JoinDependency#build - def build(associations, base_klass) - associations.map do |name, right| - if name.is_a? Join - reflection = find_reflection base_klass, name.name - reflection.check_validity! - reflection.check_eager_loadable! - - klass = if reflection.polymorphic? - name.klass || base_klass - else - reflection.klass - end - JoinAssociation.new(reflection, build(right, klass), name.klass, name.type) - else - reflection = find_reflection base_klass, name - reflection.check_validity! - reflection.check_eager_loadable! - - if reflection.polymorphic? - raise ActiveRecord::EagerLoadPolymorphicError.new(reflection) - end - JoinAssociation.new(reflection, build(right, reflection.klass)) - end - end - end - - def join_constraints(joins_to_add, join_type, alias_tracker) - @alias_tracker = alias_tracker - - construct_tables!(join_root) - joins = make_join_constraints(join_root, join_type) - - joins.concat joins_to_add.flat_map { |oj| - construct_tables!(oj.join_root) - if join_root.match?(oj.join_root) && join_root.table.name == oj.join_root.table.name - walk join_root, oj.join_root - else - make_join_constraints(oj.join_root, join_type) - end - } - end - - private - def make_constraints(parent, child, join_type = Arel::Nodes::OuterJoin) - foreign_table = parent.table - foreign_klass = parent.base_klass - join_type = child.join_type || join_type if join_type == Arel::Nodes::InnerJoin - joins = child.join_constraints(foreign_table, foreign_klass, join_type, alias_tracker) - joins.concat child.children.flat_map { |c| make_constraints(child, c, join_type) } - end - - module ClassMethods - # Prepended before ActiveRecord::Associations::JoinDependency#walk_tree - # - def walk_tree(associations, hash) - case associations - when TreeNode - associations.add_to_tree(hash) - when Hash - associations.each do |k, v| - cache = - if TreeNode === k - k.add_to_tree(hash) - else - hash[k] ||= {} - end - walk_tree(v, cache) - end - else - super(associations, hash) - end - end - end - - end -end diff --git a/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb b/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb deleted file mode 100644 index bea4b972..00000000 --- a/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Polyamorous - module ReflectionExtensions - def join_scope(table, foreign_table, foreign_klass) - if respond_to?(:polymorphic?) && polymorphic? - super.where!(foreign_table[foreign_type].eq(klass.name)) - else - super - end - end - end -end diff --git a/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb b/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb index 7a03623a..fd836fa1 100644 --- a/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +++ b/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb @@ -1 +1,20 @@ -require 'polyamorous/activerecord_5.2_ruby_2/join_association' +module Polyamorous + module JoinAssociationExtensions + include SwappingReflectionClass + def self.prepended(base) + base.class_eval { attr_reader :join_type } + end + + def initialize(reflection, children, polymorphic_class = nil, join_type = Arel::Nodes::InnerJoin) + @join_type = join_type + if polymorphic_class && ::ActiveRecord::Base > polymorphic_class + swapping_reflection_klass(reflection, polymorphic_class) do |reflection| + super(reflection, children) + self.reflection.options[:polymorphic] = true + end + else + super(reflection, children) + end + end + end +end diff --git a/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb b/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb index 54ff04e8..bea4b972 100644 --- a/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +++ b/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb @@ -1 +1,11 @@ -require 'polyamorous/activerecord_5.2_ruby_2/reflection' +module Polyamorous + module ReflectionExtensions + def join_scope(table, foreign_table, foreign_klass) + if respond_to?(:polymorphic?) && polymorphic? + super.where!(foreign_table[foreign_type].eq(klass.name)) + else + super + end + end + end +end diff --git a/lib/ransack/adapters/active_record/ransack/nodes/condition.rb b/lib/ransack/adapters/active_record/ransack/nodes/condition.rb index a461736c..d6e09421 100644 --- a/lib/ransack/adapters/active_record/ransack/nodes/condition.rb +++ b/lib/ransack/adapters/active_record/ransack/nodes/condition.rb @@ -54,7 +54,7 @@ def value_from(predicate) if predicate.respond_to?(:value) predicate.value # Rails 6.1 elsif predicate.respond_to?(:val) - predicate.val # Rails 5.2, 6.0 + predicate.val # Rails 6.0 end end diff --git a/ransack.gemspec b/ransack.gemspec index 89ea9502..be992ad8 100644 --- a/ransack.gemspec +++ b/ransack.gemspec @@ -15,8 +15,8 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.6' s.license = 'MIT' - s.add_dependency 'activerecord', '>= 5.2.4' - s.add_dependency 'activesupport', '>= 5.2.4' + s.add_dependency 'activerecord', '>= 6.0.4' + s.add_dependency 'activesupport', '>= 6.0.4' s.add_dependency 'i18n' s.files = `git ls-files`.split("\n")