Drop Rails 5.0 and Rails 5.1 support

Since they have reached their End of Life.
This commit is contained in:
David Rodríguez 2019-10-14 15:24:50 +02:00
parent 3bd0078fae
commit 99a67085f0
No known key found for this signature in database
GPG Key ID: 1008A258BB37309C
12 changed files with 11 additions and 176 deletions

View File

@ -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

View File

@ -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)

View File

@ -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.

View File

@ -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,

View File

@ -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

View File

@ -1,2 +0,0 @@
# active_record_5.0_ruby_2/join_association.rb
require 'polyamorous/activerecord_5.1_ruby_2/join_association'

View File

@ -1,2 +0,0 @@
# active_record_5.0_ruby_2/join_dependency.rb
require 'polyamorous/activerecord_5.1_ruby_2/join_dependency'

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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',