diff options
author | Roel van der Hoorn <vanderhoorn@gmail.com> | 2014-02-07 19:41:11 +0100 |
---|---|---|
committer | Roel van der Hoorn <vanderhoorn@gmail.com> | 2014-02-07 19:41:11 +0100 |
commit | 73f8d385971cf8244aec73d526bf9e7d17955a47 (patch) | |
tree | 5971820b785d3125f97e806ad493ecb794fe2cf0 /test | |
parent | c6297d711ad2a9fd04653a5f29597c2d6bd10aeb (diff) | |
download | rails-73f8d385971cf8244aec73d526bf9e7d17955a47.tar.gz rails-73f8d385971cf8244aec73d526bf9e7d17955a47.tar.bz2 rails-73f8d385971cf8244aec73d526bf9e7d17955a47.zip |
Add tests for Nodes::Equality and Nodes::NotEqual to the ToSql class.
Diffstat (limited to 'test')
-rw-r--r-- | test/visitors/test_to_sql.rb | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index 34d3459a27..35effd4105 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -92,7 +92,14 @@ module Arel assert_equal 'omg(*, *)', @visitor.accept(function) end - describe 'equality' do + describe 'Nodes::Equality' do + it "should escape strings" do + test = Table.new(:users)[:name].eq 'Aaron Patterson' + @visitor.accept(test).must_be_like %{ + "users"."name" = 'Aaron Patterson' + } + end + it 'should handle false' do sql = @visitor.accept Nodes::Equality.new(false, false) sql.must_be_like %{ 'f' = 'f' } @@ -103,6 +110,23 @@ module Arel sql = @visitor.accept Nodes::Equality.new(table[:id], '1-fooo') sql.must_be_like %{ "users"."id" = 1 } end + + it 'should handle nil' do + sql = @visitor.accept Nodes::Equality.new(@table[:name], nil) + sql.must_be_like %{ "users"."name" IS NULL } + end + end + + describe 'Nodes::NotEqual' do + it 'should handle false' do + sql = @visitor.accept Nodes::NotEqual.new(@table[:active], false) + sql.must_be_like %{ "users"."active" != 'f' } + end + + it 'should handle nil' do + sql = @visitor.accept Nodes::NotEqual.new(@table[:name], nil) + sql.must_be_like %{ "users"."name" IS NOT NULL } + end end it "should visit string subclass" do @@ -412,15 +436,6 @@ module Arel end end - describe 'Equality' do - it "should escape strings" do - test = Table.new(:users)[:name].eq 'Aaron Patterson' - @visitor.accept(test).must_be_like %{ - "users"."name" = 'Aaron Patterson' - } - end - end - describe 'Constants' do it "should handle true" do test = Table.new(:users).create_true |