diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/insert_manager_spec.rb | 5 | ||||
-rw-r--r-- | spec/support/fake_record.rb | 5 | ||||
-rw-r--r-- | spec/visitors/to_sql_spec.rb | 11 |
3 files changed, 19 insertions, 2 deletions
diff --git a/spec/insert_manager_spec.rb b/spec/insert_manager_spec.rb index 1cd61ae630..9d6045a913 100644 --- a/spec/insert_manager_spec.rb +++ b/spec/insert_manager_spec.rb @@ -37,7 +37,10 @@ module Arel manager = Arel::InsertManager.new Table.engine time = Time.now - manager.insert [[table[:id], time]] + attribute = table[:id] + attribute.column.type = :date + + manager.insert [[attribute, time]] manager.to_sql.should be_like %{ INSERT INTO "users" ("id") VALUES (#{Table.engine.connection.quote time}) } diff --git a/spec/support/fake_record.rb b/spec/support/fake_record.rb index eb6aa2c472..2aba0c10f2 100644 --- a/spec/support/fake_record.rb +++ b/spec/support/fake_record.rb @@ -39,6 +39,11 @@ module FakeRecord end def quote thing, column = nil + if column && column.type == :integer + return 'NULL' if thing.nil? + return thing.to_i + end + case thing when true "'t'" diff --git a/spec/visitors/to_sql_spec.rb b/spec/visitors/to_sql_spec.rb index 25642ee947..c234a2d58e 100644 --- a/spec/visitors/to_sql_spec.rb +++ b/spec/visitors/to_sql_spec.rb @@ -13,6 +13,12 @@ module Arel sql = @visitor.accept Nodes::Equality.new(false, false) sql.should be_like %{ 'f' = 'f' } end + + it 'should use the column to quote' do + table = Table.new(:users) + sql = @visitor.accept Nodes::Equality.new(table[:id], '1-fooo') + sql.should be_like %{ "users"."id" = 1 } + end end it "should visit_DateTime" do @@ -55,7 +61,9 @@ module Arel end it "should visit_TrueClass" do - @visitor.accept(@attr.eq(true)).should be_like %{ "users"."id" = 't' } + test = @attr.eq(true) + test.left.column.type = :boolean + @visitor.accept(test).should be_like %{ "users"."id" = 't' } end describe "Nodes::In" do @@ -91,6 +99,7 @@ module Arel describe 'Equality' do it "should escape strings" do test = @attr.eq 'Aaron Patterson' + test.left.column.type = :string @visitor.accept(test).should be_like %{ "users"."id" = 'Aaron Patterson' } |