Skip to content

Commit

Permalink
Merge pull request #1318 from activerecord-hackery/drop-rails-60-support
Browse files Browse the repository at this point in the history
Drop rails 6.0 support
  • Loading branch information
deivid-rodriguez authored May 8, 2022
2 parents 7bb9436 + e1ddee7 commit db4ed2c
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 189 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
rails:
- v7.0.2
- v6.1.5
- v6.0.4
ruby:
- 3.1.1
- 3.0.2
Expand All @@ -40,7 +39,6 @@ jobs:
rails:
- v7.0.2
- v6.1.5
- v6.0.4
ruby:
- 3.1.1
- 3.0.2
Expand Down Expand Up @@ -76,7 +74,6 @@ jobs:
rails:
- v7.0.2
- v6.1.5
- v6.0.4
ruby:
- 3.1.1
- 3.0.2
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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='6-0-stable' bundle install`
To install rails other than latest (set in Gemfile): `RAILS='6-1-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:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ gemspec

gem 'rake'

rails = ENV['RAILS'] || '6-0-stable'
rails = ENV['RAILS'] || '6-1-stable'

rails_version = case rails
when /\// # A path
Expand All @@ -15,7 +15,7 @@ rails_version = case rails
end

gem 'faker', '~> 2.0'
gem 'sqlite3', ::Gem::Version.new(rails_version == 'main' ? '6.2.0.alpha' : rails_version) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
gem 'sqlite3', '~> 1.4.1'
gem 'pg', '~> 1.0'
gem 'pry', '~> 0.12.2'
gem 'byebug'
Expand Down
20 changes: 0 additions & 20 deletions lib/polyamorous/activerecord_6.0_ruby_2/join_association.rb

This file was deleted.

79 changes: 0 additions & 79 deletions lib/polyamorous/activerecord_6.0_ruby_2/join_dependency.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/polyamorous/activerecord_6.0_ruby_2/reflection.rb

This file was deleted.

12 changes: 11 additions & 1 deletion lib/polyamorous/activerecord_6.1_ruby_2/reflection.rb
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
require 'polyamorous/activerecord_6.0_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
66 changes: 17 additions & 49 deletions lib/ransack/adapters/active_record/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,7 @@ def klassify(obj)
def join_sources
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_1)
@join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)
elsif ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
@join_dependency.join_constraints(@object.joins_values, alias_tracker)
else
@join_dependency.join_constraints(@object.joins_values, @join_type, alias_tracker)
end
constraints = @join_dependency.join_constraints(@object.joins_values, alias_tracker, @object.references_values)

[
Arel::SelectManager.new(@object.table),
Expand Down Expand Up @@ -284,11 +278,7 @@ def build_joins(relation)
join_list = join_nodes + convert_join_strings_to_ast(relation.table, string_joins)

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 = Polyamorous::JoinDependency.new(relation.klass, relation.table, association_joins, Arel::Nodes::OuterJoin)
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
Expand All @@ -315,22 +305,13 @@ def find_association(name, parent = @base, klass = nil)
end

def build_association(name, parent = @base, klass = nil)
if ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_0)
jd = Polyamorous::JoinDependency.new(
parent.base_klass,
parent.table,
Polyamorous::Join.new(name, @join_type, klass),
@join_type
)
found_association = jd.instance_variable_get(:@join_root).children.last
else
jd = Polyamorous::JoinDependency.new(
parent.base_klass,
parent.table,
Polyamorous::Join.new(name, @join_type, klass)
)
found_association = jd.instance_variable_get(:@join_root).children.last
end
jd = Polyamorous::JoinDependency.new(
parent.base_klass,
parent.table,
Polyamorous::Join.new(name, @join_type, klass),
@join_type
)
found_association = jd.instance_variable_get(:@join_root).children.last

@associations_pot[found_association] = parent

Expand All @@ -339,11 +320,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 ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
@tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)
else
@join_dependency.send(:construct_tables!, jd.instance_variable_get(:@join_root))
end
@tables_pot[found_association] = @join_dependency.construct_tables_for_association!(jd.instance_variable_get(:@join_root), found_association)

# Leverage the stashed association functionality in AR
@object = @object.joins(jd)
Expand All @@ -353,22 +330,13 @@ 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 ::Gem::Version.new(::ActiveRecord::VERSION::STRING) >= ::Gem::Version.new(Constants::RAILS_6_1)
association.join_constraints_with_tables(
parent.table,
parent.base_klass,
Arel::Nodes::OuterJoin,
@join_dependency.instance_variable_get(:@alias_tracker),
@tables_pot[association]
)
else
association.join_constraints(
parent.table,
parent.base_klass,
Arel::Nodes::OuterJoin,
@join_dependency.instance_variable_get(:@alias_tracker)
)
end
join_constraints = association.join_constraints_with_tables(
parent.table,
parent.base_klass,
Arel::Nodes::OuterJoin,
@join_dependency.instance_variable_get(:@alias_tracker),
@tables_pot[association]
)
join_constraints.to_a.flatten
end
end
Expand Down
12 changes: 2 additions & 10 deletions lib/ransack/adapters/active_record/ransack/nodes/condition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,11 @@ def in_predicate?(predicate)
end

def casted_array?(predicate)
value_from(predicate).is_a?(Array) && predicate.is_a?(Arel::Nodes::Casted)
end

def value_from(predicate)
if predicate.respond_to?(:value)
predicate.value # Rails 6.1
elsif predicate.respond_to?(:val)
predicate.val # Rails 6.0
end
predicate.value.is_a?(Array) && predicate.is_a?(Arel::Nodes::Casted)
end

def format_values_for(predicate)
value_from(predicate).map do |val|
predicate.value.map do |val|
val.is_a?(String) ? Arel::Nodes.build_quoted(val) : val
end
end
Expand Down
3 changes: 0 additions & 3 deletions lib/ransack/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ module Constants
NOT_EQ_ALL = 'not_eq_all'.freeze
CONT = 'cont'.freeze

RAILS_6_0 = '6.0.0'.freeze
RAILS_6_1 = '6.1.0'.freeze

RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze
RANSACK_SLASH_SEARCHES_SLASH_SEARCH = 'ransack/searches/search'.freeze
end
Expand Down
4 changes: 2 additions & 2 deletions ransack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Gem::Specification.new do |s|
s.required_ruby_version = '>= 2.7'
s.license = 'MIT'

s.add_dependency 'activerecord', '>= 6.0.4'
s.add_dependency 'activesupport', '>= 6.0.4'
s.add_dependency 'activerecord', '>= 6.1.5'
s.add_dependency 'activesupport', '>= 6.1.5'
s.add_dependency 'i18n'

s.files = `git ls-files`.split("\n")
Expand Down
10 changes: 2 additions & 8 deletions spec/helpers/polyamorous_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,8 @@ def new_join_association(reflection, children, klass)
Polyamorous::JoinAssociation.new reflection, children, klass
end

if ActiveRecord.version >= ::Gem::Version.new("6.0.0.rc1")
def new_join_dependency(klass, associations = {})
Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
end
else
def new_join_dependency(klass, associations = {})
Polyamorous::JoinDependency.new klass, klass.arel_table, associations
end
def new_join_dependency(klass, associations = {})
Polyamorous::JoinDependency.new klass, klass.arel_table, associations, Polyamorous::InnerJoin
end

def new_join(name, type = Polyamorous::InnerJoin, klass = nil)
Expand Down

0 comments on commit db4ed2c

Please sign in to comment.