mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #162 from dylanahsmith/quote-integers
Test quoting integers when comparing a string column with integers.
This commit is contained in:
commit
bb05bf01ce
2 changed files with 25 additions and 5 deletions
|
@ -60,9 +60,13 @@ module FakeRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def quote thing, column = nil
|
def quote thing, column = nil
|
||||||
if column && column.type == :integer
|
if column && !thing.nil?
|
||||||
return 'NULL' if thing.nil?
|
case column.type
|
||||||
return thing.to_i
|
when :integer
|
||||||
|
thing = thing.to_i
|
||||||
|
when :string
|
||||||
|
thing = thing.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
case thing
|
case thing
|
||||||
|
@ -111,6 +115,10 @@ module FakeRecord
|
||||||
def schema_cache
|
def schema_cache
|
||||||
connection
|
connection
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def quote thing, column = nil
|
||||||
|
connection.quote thing, column
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Base
|
class Base
|
||||||
|
|
|
@ -119,6 +119,12 @@ module Arel
|
||||||
sql.must_be_like %{ "users"."id" = 1 }
|
sql.must_be_like %{ "users"."id" = 1 }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'should use the column to quote integers' do
|
||||||
|
table = Table.new(:users)
|
||||||
|
sql = compile table[:name].eq(0)
|
||||||
|
sql.must_be_like %{ "users"."name" = '0' }
|
||||||
|
end
|
||||||
|
|
||||||
it 'should handle nil' do
|
it 'should handle nil' do
|
||||||
sql = compile Nodes::Equality.new(@table[:name], nil)
|
sql = compile Nodes::Equality.new(@table[:name], nil)
|
||||||
sql.must_be_like %{ "users"."name" IS NULL }
|
sql.must_be_like %{ "users"."name" IS NULL }
|
||||||
|
@ -160,6 +166,12 @@ module Arel
|
||||||
assert_match(/LIMIT 'omg'/, compile(sc))
|
assert_match(/LIMIT 'omg'/, compile(sc))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should quote LIMIT without column type coercion" do
|
||||||
|
table = Table.new(:users)
|
||||||
|
sc = table.where(table[:name].eq(0)).take(1).ast
|
||||||
|
assert_match(/WHERE "users"."name" = '0' LIMIT 1/, compile(sc))
|
||||||
|
end
|
||||||
|
|
||||||
it "should visit_DateTime" do
|
it "should visit_DateTime" do
|
||||||
called_with = nil
|
called_with = nil
|
||||||
@conn.connection.extend(Module.new {
|
@conn.connection.extend(Module.new {
|
||||||
|
@ -179,9 +191,9 @@ module Arel
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should visit_Float" do
|
it "should visit_Float" do
|
||||||
test = Table.new(:users)[:name].eq 2.14
|
test = Table.new(:products)[:price].eq 2.14
|
||||||
sql = compile test
|
sql = compile test
|
||||||
sql.must_be_like %{"users"."name" = 2.14}
|
sql.must_be_like %{"products"."price" = 2.14}
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should visit_Not" do
|
it "should visit_Not" do
|
||||||
|
|
Loading…
Reference in a new issue