From b62494b933d3535c88ffcf9d2337dffab867a555 Mon Sep 17 00:00:00 2001 From: Jared Beck Date: Fri, 16 Aug 2019 16:49:49 -0400 Subject: [PATCH 1/3] Compare `Gem::Version` rather than version strings --- lib/ransack/adapters/active_record/context.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ransack/adapters/active_record/context.rb b/lib/ransack/adapters/active_record/context.rb index ed562f972..791459ceb 100644 --- a/lib/ransack/adapters/active_record/context.rb +++ b/lib/ransack/adapters/active_record/context.rb @@ -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) @@ -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) @@ -313,7 +313,7 @@ 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, @@ -321,7 +321,7 @@ def build_association(name, parent = @base, klass = nil) @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), From 3ed594f20b024c874ce9aec66f5ac9a23a768d63 Mon Sep 17 00:00:00 2001 From: Greg Molnar Date: Sun, 18 Aug 2019 14:18:54 +0200 Subject: [PATCH 2/3] update travis matrix --- .travis.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8f0b241ed..d1474b0e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 From e3f182d92c35fab16d003d0ba78492a8dbabe511 Mon Sep 17 00:00:00 2001 From: Greg Molnar Date: Sun, 18 Aug 2019 19:12:25 +0200 Subject: [PATCH 3/3] change version comparison from string to Gem::Version --- lib/ransack/constants.rb | 2 +- polyamorous/lib/polyamorous.rb | 5 ++--- ransack.gemspec | 2 +- spec/helpers/polyamorous_helper.rb | 6 +++--- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/ransack/constants.rb b/lib/ransack/constants.rb index 5ad2b13bf..6fbafabd4 100644 --- a/lib/ransack/constants.rb +++ b/lib/ransack/constants.rb @@ -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 diff --git a/polyamorous/lib/polyamorous.rb b/polyamorous/lib/polyamorous.rb index 3137df523..05bca1037 100644 --- a/polyamorous/lib/polyamorous.rb +++ b/polyamorous/lib/polyamorous.rb @@ -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 diff --git a/ransack.gemspec b/ransack.gemspec index ad25d0dfc..85a6ec0ba 100644 --- a/ransack.gemspec +++ b/ransack.gemspec @@ -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' diff --git a/spec/helpers/polyamorous_helper.rb b/spec/helpers/polyamorous_helper.rb index d485aa7eb..74a144117 100644 --- a/spec/helpers/polyamorous_helper.rb +++ b/spec/helpers/polyamorous_helper.rb @@ -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