From 99a67085f06154049bd840580d0b86ecfdff5d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 14 Oct 2019 15:24:50 +0200 Subject: [PATCH] Drop Rails 5.0 and Rails 5.1 support Since they have reached their End of Life. --- .travis.yml | 4 - CHANGELOG.md | 3 + README.md | 3 +- lib/ransack/adapters/active_record/context.rb | 12 +- lib/ransack/constants.rb | 1 - .../join_association.rb | 2 - .../join_dependency.rb | 2 - .../join_association.rb | 31 ----- .../join_dependency.rb | 112 ------------------ polyamorous/polyamorous.gemspec | 2 +- ransack.gemspec | 6 +- spec/ransack/search_spec.rb | 9 +- 12 files changed, 11 insertions(+), 176 deletions(-) delete mode 100644 polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb delete mode 100644 polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb delete mode 100644 polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb delete mode 100644 polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb diff --git a/.travis.yml b/.travis.yml index d37adcd..60749cb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,10 +27,6 @@ env: - RAILS=v5.2.0 DB=mysql - RAILS=v5.2.0 DB=postgres - - RAILS=5-1-stable DB=sqlite3 - - RAILS=5-1-stable DB=mysql - - RAILS=5-1-stable DB=postgres - matrix: allow_failures: - env: RAILS=5-2-stable DB=sqlite3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 95c0af8..5132883 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Drop support for Active Record < 5.2. + PR [#1073](https://github.com/activerecord-hackery/ransack/pull/1073) + ## 2.3.0 - 2019-08-18 * Arabic translations PR [979](https://github.com/activerecord-hackery/ransack/pull/979) diff --git a/README.md b/README.md index 61b91c0..a850a5d 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,8 @@ you're reading the documentation for the master branch with the latest features. ## Getting started -Ransack is compatible with Rails 6.0, 5.0, 5.1 and 5.2 on Ruby 2.2 and later. +Ransack is compatible with Rails 6.0, and 5.2 on Ruby 2.2 and later. +If you are using Rails 5.0 or Rails 5.1 use the 2.3 line of Ransack. If you are using Rails <5.0 use the 1.8 line of Ransack. If you are using Ruby 1.8 or an earlier JRuby and run into compatibility issues, you can use an earlier version of Ransack, say, up to 1.3.0. diff --git a/lib/ransack/adapters/active_record/context.rb b/lib/ransack/adapters/active_record/context.rb index 791459c..410c7ef 100644 --- a/lib/ransack/adapters/active_record/context.rb +++ b/lib/ransack/adapters/active_record/context.rb @@ -367,17 +367,7 @@ module Ransack def extract_joins(association) parent = @join_dependency.instance_variable_get(:@join_root) reflection = association.reflection - join_constraints = if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_1 - association.join_constraints( - parent.table, - parent.base_klass, - association, - Arel::Nodes::OuterJoin, - association.tables, - reflection.scope_chain, - reflection.chain - ) - elsif ::ActiveRecord::VERSION::STRING <= Constants::RAILS_5_2_0 + join_constraints = if ::ActiveRecord::VERSION::STRING <= Constants::RAILS_5_2_0 association.join_constraints( parent.table, parent.base_klass, diff --git a/lib/ransack/constants.rb b/lib/ransack/constants.rb index 6fbafab..9d15e93 100644 --- a/lib/ransack/constants.rb +++ b/lib/ransack/constants.rb @@ -45,7 +45,6 @@ module Ransack NOT_EQ_ALL = 'not_eq_all'.freeze CONT = 'cont'.freeze - RAILS_5_1 = '5.1'.freeze RAILS_5_2 = '5.2'.freeze RAILS_5_2_0 = '5.2.0'.freeze RAILS_6_0 = '6.0.0'.freeze diff --git a/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb b/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb deleted file mode 100644 index 794f2da..0000000 --- a/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_association.rb +++ /dev/null @@ -1,2 +0,0 @@ -# active_record_5.0_ruby_2/join_association.rb -require 'polyamorous/activerecord_5.1_ruby_2/join_association' diff --git a/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb b/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb deleted file mode 100644 index 03423b2..0000000 --- a/polyamorous/lib/polyamorous/activerecord_5.0_ruby_2/join_dependency.rb +++ /dev/null @@ -1,2 +0,0 @@ -# active_record_5.0_ruby_2/join_dependency.rb -require 'polyamorous/activerecord_5.1_ruby_2/join_dependency' diff --git a/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb b/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb deleted file mode 100644 index 7e9c24e..0000000 --- a/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_association.rb +++ /dev/null @@ -1,31 +0,0 @@ -# active_record_5.1_ruby_2/join_association.rb - -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 - - def build_constraint(klass, table, key, foreign_table, foreign_key) - if reflection.polymorphic? - super(klass, table, key, foreign_table, foreign_key) - .and(foreign_table[reflection.foreign_type].eq(reflection.klass.name)) - else - super(klass, table, key, foreign_table, foreign_key) - end - end - end -end diff --git a/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb b/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb deleted file mode 100644 index b1b63af..0000000 --- a/polyamorous/lib/polyamorous/activerecord_5.1_ruby_2/join_dependency.rb +++ /dev/null @@ -1,112 +0,0 @@ -# active_record_5.1_ruby_2/join_dependency.rb - -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 - - # Replaces ActiveRecord::Associations::JoinDependency#join_constraints - # - # This internal method was changed in Rails 5.0 by commit - # https://github.com/rails/rails/commit/e038975 which added - # left_outer_joins (see #make_polyamorous_left_outer_joins below) and added - # passing an additional argument, `join_type`, to #join_constraints. - # - def join_constraints(outer_joins, join_type) - joins = join_root.children.flat_map { |child| - if join_type == Arel::Nodes::OuterJoin - make_polyamorous_left_outer_joins join_root, child - else - make_polyamorous_inner_joins join_root, child - end - } - - joins.concat outer_joins.flat_map { |oj| - if join_root.match? oj.join_root - walk(join_root, oj.join_root) - else - oj.join_root.children.flat_map { |child| - make_outer_joins(oj.join_root, child) - } - end - } - end - - # Replaces ActiveRecord::Associations::JoinDependency#make_left_outer_joins, - # a new method that was added in Rails 5.0 with the following commit: - # https://github.com/rails/rails/commit/e038975 - # - def make_polyamorous_left_outer_joins(parent, child) - tables = child.tables - join_type = Arel::Nodes::OuterJoin - info = make_constraints parent, child, tables, join_type - - [info] + child.children.flat_map { |c| - make_polyamorous_left_outer_joins(child, c) - } - end - - # Replaces ActiveRecord::Associations::JoinDependency#make_inner_joins - # - def make_polyamorous_inner_joins(parent, child) - tables = child.tables - join_type = child.join_type || Arel::Nodes::InnerJoin - info = make_constraints parent, child, tables, join_type - - [info] + child.children.flat_map { |c| - make_polyamorous_inner_joins(child, c) - } - end - - private :make_polyamorous_inner_joins, :make_polyamorous_left_outer_joins - - 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/polyamorous/polyamorous.gemspec b/polyamorous/polyamorous.gemspec index 8a76124..1e4e707 100644 --- a/polyamorous/polyamorous.gemspec +++ b/polyamorous/polyamorous.gemspec @@ -18,7 +18,7 @@ Gem::Specification.new do |s| associations. } - s.add_dependency 'activerecord', '>= 5.0' + s.add_dependency 'activerecord', '>= 5.2' s.add_development_dependency 'rspec', '~> 3' s.add_development_dependency 'machinist', '~> 1.0.6' s.add_development_dependency 'faker', '~> 1.6.5' diff --git a/ransack.gemspec b/ransack.gemspec index 269cf3f..3bc1b24 100644 --- a/ransack.gemspec +++ b/ransack.gemspec @@ -14,9 +14,9 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 1.9' s.license = 'MIT' - s.add_dependency 'actionpack', '>= 5.0' - s.add_dependency 'activerecord', '>= 5.0' - s.add_dependency 'activesupport', '>= 5.0' + s.add_dependency 'actionpack', '>= 5.2' + s.add_dependency 'activerecord', '>= 5.2' + s.add_dependency 'activesupport', '>= 5.2' s.add_dependency 'i18n' s.add_dependency 'polyamorous', Ransack::VERSION.to_s diff --git a/spec/ransack/search_spec.rb b/spec/ransack/search_spec.rb index c19a6f1..e294a8f 100644 --- a/spec/ransack/search_spec.rb +++ b/spec/ransack/search_spec.rb @@ -228,7 +228,6 @@ module Ransack end it 'use appropriate table alias' do - skip "Make this spec pass for Rails <5.2" if ::ActiveRecord::VERSION::STRING < '5.2.0' s = Search.new(Person, { name_eq: "person_name_query", articles_title_eq: "person_article_title_query", @@ -251,13 +250,7 @@ module Ransack .to include "articles_people.title = 'parents_article_title_query'" end - # FIXME: Make this spec pass for Rails 4.1 / 4.2 / 5.0 and not just 4.0 by - # commenting out lines 221 and 242 to run the test. Addresses issue #374. - # https://github.com/activerecord-hackery/ransack/issues/374 - # - it 'evaluates conditions for multiple `belongs_to` associations to the - same table contextually' do - skip "Make this spec pass for Rails <5.2" if ::ActiveRecord::VERSION::STRING < '5.2.0' + it 'evaluates conditions for multiple `belongs_to` associations to the same table contextually' do s = Search.new( Recommendation, person_name_eq: 'Ernie',