From 73f8d385971cf8244aec73d526bf9e7d17955a47 Mon Sep 17 00:00:00 2001 From: Roel van der Hoorn Date: Fri, 7 Feb 2014 19:41:11 +0100 Subject: Add tests for Nodes::Equality and Nodes::NotEqual to the ToSql class. --- test/visitors/test_to_sql.rb | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'test') 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 -- cgit v1.2.3