From f996bdd7fc22b5a8780b498cd0437001978fc065 Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Sun, 20 Jun 2021 12:03:01 +0900 Subject: [PATCH] Support Rails untyped bound values change for MySQL Follow up rails/rails#42440 Fix #1231 --- .../adapters/active_record/base_spec.rb | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/spec/ransack/adapters/active_record/base_spec.rb b/spec/ransack/adapters/active_record/base_spec.rb index afba4e4d..9879d9d2 100644 --- a/spec/ransack/adapters/active_record/base_spec.rb +++ b/spec/ransack/adapters/active_record/base_spec.rb @@ -44,12 +44,12 @@ module ActiveRecord it 'applies stringy boolean scopes with true value in an array' do s = Person.ransack('of_age' => ['true']) - expect(s.result.to_sql).to (include 'age >= 18') + expect(s.result.to_sql).to (include rails7_and_mysql ? %q{(age >= '18')} : 'age >= 18') end it 'applies stringy boolean scopes with false value in an array' do s = Person.ransack('of_age' => ['false']) - expect(s.result.to_sql).to (include 'age < 18') + expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age < '18'} : 'age < 18') end it 'ignores unlisted scopes' do @@ -69,12 +69,12 @@ module ActiveRecord it 'passes values to scopes' do s = Person.ransack('over_age' => 18) - expect(s.result.to_sql).to (include 'age > 18') + expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '18'} : 'age > 18') end it 'chains scopes' do s = Person.ransack('over_age' => 18, 'active' => true) - expect(s.result.to_sql).to (include 'age > 18') + expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '18'} : 'age > 18') expect(s.result.to_sql).to (include 'active = 1') end @@ -89,12 +89,12 @@ module ActiveRecord it 'passes true values to scopes' do s = Person.ransack('over_age' => 1) - expect(s.result.to_sql).to (include 'age > 1') + expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '1'} : 'age > 1') end it 'passes false values to scopes' do s = Person.ransack('over_age' => 0) - expect(s.result.to_sql).to (include 'age > 0') + expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '0'} : 'age > 0') end end @@ -107,12 +107,12 @@ module ActiveRecord it 'passes true values to scopes' do s = Person.ransack('over_age' => 1) - expect(s.result.to_sql).to (include 'age > 1') + expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '1'} : 'age > 1') end it 'passes false values to scopes' do s = Person.ransack('over_age' => 0) - expect(s.result.to_sql).to (include 'age > 0') + expect(s.result.to_sql).to (include rails7_and_mysql ? %q{age > '0'} : 'age > 0') end end @@ -690,6 +690,10 @@ def self.simple_escaping? it { should eq [] } end + private + def rails7_and_mysql + ::ActiveRecord::VERSION::MAJOR >= 7 && ENV['DB'] == 'mysql' + end end end end