Skip to content

Commit

Permalink
Merge pull request #1056 from gregmolnar/fix_argument_error
Browse files Browse the repository at this point in the history
Fix argument error
  • Loading branch information
gregmolnar authored Aug 18, 2019
2 parents aada895 + e3f182d commit 8bca7d0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ language: ruby
sudo: false

rvm:
- 2.5
- 2.6.0

services:
- mysql

env:
- RAILS=6-0-stable DB=sqlite3
- RAILS=6-0-stable DB=mysql
- RAILS=6-0-stable DB=postgres

- RAILS=v6.0.0 DB=sqlite3
- RAILS=v6.0.0 DB=mysql
- RAILS=v6.0.0 DB=postgres

- RAILS=5-2-stable DB=sqlite3
- RAILS=5-2-stable DB=mysql
- RAILS=5-2-stable DB=postgres
Expand Down
8 changes: 4 additions & 4 deletions lib/ransack/adapters/active_record/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def join_sources
base, joins =
if ::ActiveRecord::VERSION::STRING > Constants::RAILS_5_2_0
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, @object.table.name, [])
constraints = if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_6_0
constraints = if ::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)
Expand Down Expand Up @@ -281,7 +281,7 @@ def build_joins(relation)
end
else
alias_tracker = ::ActiveRecord::Associations::AliasTracker.create(self.klass.connection, relation.table.name, join_list)
join_dependency = if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_6_0
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)
Expand Down Expand Up @@ -313,15 +313,15 @@ def find_association(name, parent = @base, klass = nil)
end

def build_association(name, parent = @base, klass = nil)
if ::ActiveRecord::VERSION::STRING >= Constants::RAILS_6_0
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
elsif ::ActiveRecord::VERSION::STRING < Constants::RAILS_5_2_0
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),
Expand Down
2 changes: 1 addition & 1 deletion lib/ransack/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Constants
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.rc1'.freeze
RAILS_6_0 = '6.0.0'.freeze

RANSACK_SLASH_SEARCHES = 'ransack/searches'.freeze
RANSACK_SLASH_SEARCHES_SLASH_SEARCH = 'ransack/searches/search'.freeze
Expand Down
5 changes: 2 additions & 3 deletions polyamorous/lib/polyamorous.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ 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::STRING < "6.0"
ar_version = "5.2.1" if ::ActiveRecord::VERSION::STRING >= "5.2.1" && ::ActiveRecord::VERSION::STRING < "6.0"

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|
require "polyamorous/activerecord_#{ar_version}_ruby_2/#{file}"
end
Expand Down
2 changes: 1 addition & 1 deletion ransack.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec', '~> 3'
s.add_development_dependency 'machinist', '~> 1.0.6'
s.add_development_dependency 'faker', '~> 0.9.5'
s.add_development_dependency 'sqlite3', ENV['RAILS'] == '6-0-stable' ? '~> 1.4.1' : '~> 1.3.3'
s.add_development_dependency 'sqlite3', ::Gem::Version.new(ENV['RAILS'].gsub(/^v/, '')) >= ::Gem::Version.new('6-0-stable') ? '~> 1.4.1' : '~> 1.3.3'
s.add_development_dependency 'pg', '~> 0.21'
s.add_development_dependency 'mysql2', '0.3.20'
s.add_development_dependency 'pry', '0.10'
Expand Down
6 changes: 3 additions & 3 deletions spec/helpers/polyamorous_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ def new_join_association(reflection, children, klass)
Polyamorous::JoinAssociation.new reflection, children, klass
end

if ActiveRecord::VERSION::STRING >= "6.0.0.rc1"
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
elsif ActiveRecord::VERSION::STRING > "5.2.0"
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::STRING == "5.2.0"
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
Expand Down

0 comments on commit 8bca7d0

Please sign in to comment.