1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/spec/arel/visitors/to_sql_spec.rb

62 lines
1.6 KiB
Ruby
Raw Normal View History

2010-08-13 21:55:15 -04:00
require 'spec_helper'
module Arel
module Visitors
describe 'the to_sql visitor' do
before do
@visitor = ToSql.new Table.engine
@attr = Table.new(:users)[:id]
end
2010-09-08 17:45:38 -04:00
it "should visit_BigDecimal" do
@visitor.accept BigDecimal.new('2.14')
end
2010-08-24 21:42:47 -04:00
it "should visit_Date" do
@visitor.accept Date.today
end
2010-08-23 17:44:10 -04:00
it "should visit_Arel_Nodes_And" do
node = Nodes::And.new @attr.eq(10), @attr.eq(11)
@visitor.accept(node).should be_like %{
"users"."id" = 10 AND "users"."id" = 11
}
end
2010-08-16 20:26:12 -04:00
it "should visit_Arel_Nodes_Or" do
node = Nodes::Or.new @attr.eq(10), @attr.eq(11)
@visitor.accept(node).should be_like %{
"users"."id" = 10 OR "users"."id" = 11
}
end
2010-08-13 21:55:15 -04:00
it "should visit visit_Arel_Attributes_Time" do
attr = Attributes::Time.new(@attr.relation, @attr.name, @attr.column)
@visitor.accept attr
end
2010-08-16 18:46:53 -04:00
it "should visit_TrueClass" do
@visitor.accept(@attr.eq(true)).should be_like %{ "users"."id" = 't' }
end
2010-08-16 17:43:18 -04:00
describe "Nodes::In" do
it "should know how to visit" do
node = @attr.in [1, 2, 3]
@visitor.accept(node).should be_like %{
"users"."id" IN (1, 2, 3)
}
end
end
describe 'Equality' do
it "should escape strings" do
test = @attr.eq 'Aaron Patterson'
@visitor.accept(test).should be_like %{
"users"."id" = 'Aaron Patterson'
}
end
end
2010-08-13 21:55:15 -04:00
end
end
end