Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Rails untyped bound values change for MySQL #1234

Merged
merged 1 commit into from
Jun 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions spec/ransack/adapters/active_record/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

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

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

Expand Down Expand Up @@ -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
Expand Down