diff --git a/.travis.yml b/.travis.yml index d37adcd15..39c4fc668 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,26 +19,16 @@ env: - RAILS=5-2-stable DB=mysql - RAILS=5-2-stable DB=postgres - - RAILS=v5.2.1 DB=sqlite3 - - RAILS=v5.2.1 DB=mysql - - RAILS=v5.2.1 DB=postgres - - - RAILS=v5.2.0 DB=sqlite3 - - 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 + - RAILS=v5.2.3 DB=sqlite3 + - RAILS=v5.2.3 DB=mysql + - RAILS=v5.2.3 DB=postgres matrix: allow_failures: - - env: RAILS=5-2-stable DB=sqlite3 - - env: RAILS=5-2-stable DB=mysql - - env: RAILS=5-2-stable DB=postgres - env: RAILS=6-0-stable DB=sqlite3 - env: RAILS=6-0-stable DB=mysql - env: RAILS=6-0-stable DB=postgres + before_script: - if [ "$DB" = "mysql" ]; then diff --git a/CHANGELOG.md b/CHANGELOG.md index b10500d3d..489f75023 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## Unreleased +* Drop support for Active Record 5.0, 5.1, and 5.2.0. + PR [#1073](https://github.com/activerecord-hackery/ransack/pull/1073) + * Drop support for rubies under 2.3. PR [#1070](https://github.com/activerecord-hackery/ransack/pull/1070) diff --git a/lib/ransack/adapters/active_record/context.rb b/lib/ransack/adapters/active_record/context.rb index 791459ceb..9ea20ab90 100644 --- a/lib/ransack/adapters/active_record/context.rb +++ b/lib/ransack/adapters/active_record/context.rb @@ -6,13 +6,6 @@ module Adapters module ActiveRecord class Context < ::Ransack::Context - def initialize(object, options = {}) - super - if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2 - @arel_visitor = @engine.connection.visitor - end - end - def relation_for(object) object.all end @@ -104,8 +97,7 @@ def klassify(obj) # JoinDependency to track table aliases. # def join_sources - base, joins = - if ::ActiveRecord::VERSION::STRING > Constants::RAILS_5_2_0 + base, joins = begin alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, []) constraints = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0) @join_dependency.join_constraints(@object.joins_values, alias_tracker) @@ -117,13 +109,7 @@ def join_sources Arel::SelectManager.new(@object.table), constraints ] - else - [ - Arel::SelectManager.new(@object.table), - @join_dependency.join_constraints(@object.joins_values, @join_type) - ] end - joins = joins.collect(&:joins).flatten if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2 joins.each do |aliased_join| base.from(aliased_join) end @@ -268,28 +254,15 @@ def build_joins(relation) join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins) - if ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2_0 - join_dependency = Polyamorous::JoinDependency.new(relation.klass, association_joins, join_list) - join_nodes.each do |join| - join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1 - end - elsif ::ActiveRecord::VERSION::STRING == Constants::RAILS_5_2_0 - alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list) - join_dependency = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, alias_tracker) - join_nodes.each do |join| - join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1 - end + alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list) + join_dependency = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0) + Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin) else - alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list) - join_dependency = if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0) - Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin) - else - Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins) - end - join_dependency.instance_variable_set(:@alias_tracker, alias_tracker) - join_nodes.each do |join| - join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1 - end + Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins) + end + join_dependency.instance_variable_set(:@alias_tracker, alias_tracker) + join_nodes.each do |join| + join_dependency.send(:alias_tracker).aliases[join.left.name.downcase] = 1 end join_dependency end @@ -321,22 +294,6 @@ def build_association(name, parent = @base, klass = nil) @join_type ) found_association = jd.instance_variable_get(:@join_root).children.last - elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) < ::Gem::Version.new(Constants::RAILS_5_2_0) - jd = Polyamorous::JoinDependency.new( - parent.base_klass, - Polyamorous::Join.new(name, @join_type, klass), - [] - ) - found_association = jd.join_root.children.last - elsif ::ActiveRecord::VERSION::STRING == Constants::RAILS_5_2_0 - alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, parent.table.name, []) - jd = Polyamorous::JoinDependency.new( - parent.base_klass, - parent.table, - Polyamorous::Join.new(name, @join_type, klass), - alias_tracker - ) - found_association = jd.instance_variable_get(:@join_root).children.last else jd = Polyamorous::JoinDependency.new( parent.base_klass, @@ -353,11 +310,7 @@ def build_association(name, parent = @base, klass = nil) @join_dependency.instance_variable_get(:@join_root).children.push found_association # Builds the arel nodes properly for this association - if ::ActiveRecord::VERSION::STRING > Constants::RAILS_5_2_0 - @join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root)) - else - @join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root), found_association) - end + @join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root)) # Leverage the stashed association functionality in AR @object = @object.joins(jd) @@ -367,32 +320,12 @@ def build_association(name, parent = @base, klass = nil) 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 - association.join_constraints( - parent.table, - parent.base_klass, - Arel::Nodes::OuterJoin, - association.tables, - reflection.chain - ) - else - association.join_constraints( + join_constraints = association.join_constraints( parent.table, parent.base_klass, Arel::Nodes::OuterJoin, @join_dependency.instance_variable_get(:@alias_tracker) ) - end join_constraints.to_a.flatten end end diff --git a/lib/ransack/adapters/active_record/ransack/context.rb b/lib/ransack/adapters/active_record/ransack/context.rb index 353da953b..73ad0f16e 100644 --- a/lib/ransack/adapters/active_record/ransack/context.rb +++ b/lib/ransack/adapters/active_record/ransack/context.rb @@ -30,12 +30,7 @@ def initialize(object, options = {}) @associations_pot = {} @lock_associations = [] - if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_5_2 - @base = @join_dependency.instance_variable_get(:@join_root) - else - @base = @join_dependency.join_root - @engine = @base.base_klass.arel_engine - end + @base = @join_dependency.instance_variable_get(:@join_root) end def bind_pair_for(key) diff --git a/lib/ransack/constants.rb b/lib/ransack/constants.rb index 6fbafabd4..48897d9df 100644 --- a/lib/ransack/constants.rb +++ b/lib/ransack/constants.rb @@ -45,9 +45,6 @@ module Constants 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 RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze diff --git a/lib/ransack/helpers/form_builder.rb b/lib/ransack/helpers/form_builder.rb index 1726bbbdc..2ee3c25f7 100644 --- a/lib/ransack/helpers/form_builder.rb +++ b/lib/ransack/helpers/form_builder.rb @@ -7,17 +7,11 @@ module ActionView::Helpers::Tags class Base private if defined? ::ActiveRecord - if ::ActiveRecord::VERSION::STRING < '5.2' - def value(object) - object.send @method_name if object # use send instead of public_send - end - else # rails/rails#29791 - def value - if @allow_method_names_outside_object - object.send @method_name if object && object.respond_to?(@method_name, true) - else - object.send @method_name if object - end + def value + if @allow_method_names_outside_object + object.send @method_name if object && object.respond_to?(@method_name, true) + else + object.send @method_name if object end end end diff --git a/polyamorous/lib/polyamorous.rb b/polyamorous/lib/polyamorous.rb index 05bca1037..26f3322c2 100644 --- a/polyamorous/lib/polyamorous.rb +++ b/polyamorous/lib/polyamorous.rb @@ -12,16 +12,11 @@ module Polyamorous require 'polyamorous/swapping_reflection_class' ar_version = ::ActiveRecord::VERSION::STRING[0,3] - ar_version = ::ActiveRecord::VERSION::STRING[0,5] if ar_version >= "5.2" && ::ActiveRecord.version < ::Gem::Version.new("6.0") - ar_version = "5.2.1" if ::ActiveRecord::VERSION::STRING >= "5.2.1" && ::ActiveRecord.version < ::Gem::Version.new("6.0") - %w(join_association join_dependency).each do |file| + %w(join_association join_dependency reflection).each do |file| require "polyamorous/activerecord_#{ar_version}_ruby_2/#{file}" end - if ar_version >= "5.2.0" - require "polyamorous/activerecord_#{ar_version}_ruby_2/reflection.rb" - ::ActiveRecord::Reflection::AbstractReflection.send(:prepend, Polyamorous::ReflectionExtensions) - end + ActiveRecord::Reflection::AbstractReflection.send(:prepend, Polyamorous::ReflectionExtensions) Polyamorous::JoinDependency.send(:prepend, Polyamorous::JoinDependencyExtensions) Polyamorous::JoinDependency.singleton_class.send(:prepend, Polyamorous::JoinDependencyExtensions::ClassMethods) 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 794f2da92..000000000 --- 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 03423b268..000000000 --- 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 7e9c24e94..000000000 --- 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 b1b63af3a..000000000 --- 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/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb b/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb deleted file mode 100644 index 20cf2a4d9..000000000 --- a/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_association.rb +++ /dev/null @@ -1,31 +0,0 @@ -# active_record_5.2_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, alias_tracker, 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, alias_tracker) - self.reflection.options[:polymorphic] = true - end - else - super(reflection, children, alias_tracker) - 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.2.0_ruby_2/join_dependency.rb b/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb deleted file mode 100644 index 1e76107c2..000000000 --- a/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/join_dependency.rb +++ /dev/null @@ -1,112 +0,0 @@ -# active_record_5.2_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), alias_tracker, 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), alias_tracker) - 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) && join_root.table.name == oj.join_root.table.name - 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/lib/polyamorous/activerecord_5.2.1_ruby_2/reflection.rb b/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/reflection.rb deleted file mode 100644 index e66bf9090..000000000 --- a/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/reflection.rb +++ /dev/null @@ -1,2 +0,0 @@ -# active_record_5.2.1_ruby_2/reflection.rb -require 'polyamorous/activerecord_5.2.0_ruby_2/reflection' diff --git a/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb b/polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb similarity index 92% rename from polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb rename to polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb index 8b3976033..fd836fa14 100644 --- a/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_association.rb +++ b/polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/join_association.rb @@ -1,5 +1,3 @@ -# active_record_5.2.1_ruby_2/join_association.rb - module Polyamorous module JoinAssociationExtensions include SwappingReflectionClass diff --git a/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb b/polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb similarity index 98% rename from polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb rename to polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb index ca7de5650..58b9f6744 100644 --- a/polyamorous/lib/polyamorous/activerecord_5.2.1_ruby_2/join_dependency.rb +++ b/polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/join_dependency.rb @@ -1,5 +1,3 @@ -# active_record_5.2.1_ruby_2/join_dependency.rb - module Polyamorous module JoinDependencyExtensions # Replaces ActiveRecord::Associations::JoinDependency#build diff --git a/polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/reflection.rb b/polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb similarity index 100% rename from polyamorous/lib/polyamorous/activerecord_5.2.0_ruby_2/reflection.rb rename to polyamorous/lib/polyamorous/activerecord_5.2_ruby_2/reflection.rb diff --git a/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb b/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb index ea2b61e47..25c1bccf4 100644 --- a/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb +++ b/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb @@ -1,2 +1,2 @@ # active_record_6.0_ruby_2/join_association -require 'polyamorous/activerecord_5.2.1_ruby_2/join_association' +require 'polyamorous/activerecord_5.2_ruby_2/join_association' diff --git a/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb b/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb index 0417c1089..bb92287e9 100644 --- a/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb +++ b/polyamorous/lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb @@ -1,2 +1,2 @@ # active_record_6.0_ruby_2/reflection.rb -require 'polyamorous/activerecord_5.2.0_ruby_2/reflection' +require 'polyamorous/activerecord_5.2_ruby_2/reflection' diff --git a/polyamorous/polyamorous.gemspec b/polyamorous/polyamorous.gemspec index 8a76124c1..57e07e0ba 100644 --- a/polyamorous/polyamorous.gemspec +++ b/polyamorous/polyamorous.gemspec @@ -18,18 +18,10 @@ Gem::Specification.new do |s| associations. } - s.add_dependency 'activerecord', '>= 5.0' - s.add_development_dependency 'rspec', '~> 3' - s.add_development_dependency 'machinist', '~> 1.0.6' - s.add_development_dependency 'faker', '~> 1.6.5' - s.add_development_dependency 'sqlite3', '~> 1.3.3' + s.add_dependency 'activerecord', '>= 5.2.1' s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } s.require_paths = ["lib"] - - # specify any dependencies here; for example: - # s.add_development_dependency "rspec" - # s.add_runtime_dependency "rest-client" end diff --git a/ransack.gemspec b/ransack.gemspec index 4a579229c..1f1344872 100644 --- a/ransack.gemspec +++ b/ransack.gemspec @@ -14,9 +14,9 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.3' 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.1' + s.add_dependency 'activerecord', '>= 5.2.1' + s.add_dependency 'activesupport', '>= 5.2.1' s.add_dependency 'i18n' s.add_dependency 'polyamorous', Ransack::VERSION.to_s diff --git a/spec/helpers/polyamorous_helper.rb b/spec/helpers/polyamorous_helper.rb index 74a144117..b35da729d 100644 --- a/spec/helpers/polyamorous_helper.rb +++ b/spec/helpers/polyamorous_helper.rb @@ -7,18 +7,9 @@ def new_join_association(reflection, children, klass) def new_join_dependency(klass, associations = {}) Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin end - elsif ActiveRecord.version > ::Gem::Version.new("5.2.0") - def new_join_dependency(klass, associations = {}) - Polyamorous::JoinDependency.new klass, klass.arel_table, associations - end - elsif ActiveRecord.version == ::Gem::Version.new("5.2.0") - def new_join_dependency(klass, associations = {}) - alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(klass.connection, klass.table_name, []) - Polyamorous::JoinDependency.new klass, klass.arel_table, associations, alias_tracker - end else def new_join_dependency(klass, associations = {}) - Polyamorous::JoinDependency.new klass, associations, [] + Polyamorous::JoinDependency.new klass, klass.arel_table, associations end end diff --git a/spec/ransack/search_spec.rb b/spec/ransack/search_spec.rb index c19a6f158..e294a8f8f 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',