diff options
author | Rolf Timmermans <r.timmermans@voormedia.com> | 2010-11-17 22:18:25 +0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-11-18 00:37:15 +0800 |
commit | 35f25f643cca00c192d971234942d5a0d0e07cc0 (patch) | |
tree | 34fadd792ddeb189acbafbc990121d4e368cd9df /test | |
parent | 7c9845e770b2dd2c9875a43e9258c47a74ce1bed (diff) | |
download | rails-35f25f643cca00c192d971234942d5a0d0e07cc0.tar.gz rails-35f25f643cca00c192d971234942d5a0d0e07cc0.tar.bz2 rails-35f25f643cca00c192d971234942d5a0d0e07cc0.zip |
Added tests for Nodes::NotIn.
Diffstat (limited to 'test')
-rw-r--r-- | test/visitors/test_to_sql.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/test/visitors/test_to_sql.rb b/test/visitors/test_to_sql.rb index 8715531bda..b84730eeb4 100644 --- a/test/visitors/test_to_sql.rb +++ b/test/visitors/test_to_sql.rb @@ -132,6 +132,52 @@ module Arel end end + describe "Nodes::NotIn" do + it "should know how to visit" do + node = @attr.not_in [1, 2, 3] + @visitor.accept(node).must_be_like %{ + "users"."id" NOT IN (1, 2, 3) + } + end + + it "should turn empty right to NULL" do + node = @attr.not_in [] + @visitor.accept(node).must_be_like %{ + "users"."id" NOT IN (NULL) + } + end + + it 'can handle two dot ranges' do + node = @attr.not_in 1..3 + @visitor.accept(node).must_be_like %{ + "users"."id" < 1 OR "users"."id" > 3 + } + end + + it 'can handle three dot ranges' do + node = @attr.not_in 1...3 + @visitor.accept(node).must_be_like %{ + "users"."id" < 1 OR "users"."id" >= 3 + } + end + + it 'uses the same column for escaping values' do + @attr = Table.new(:users)[:name] + visitor = Class.new(ToSql) do + attr_accessor :expected + + def quote value, column = nil + raise unless column == expected + super + end + end + in_node = Nodes::NotIn.new @attr, %w{ a b c } + visitor = visitor.new(Table.engine) + visitor.expected = @attr.column + visitor.accept(in_node).must_equal %("users"."name" NOT IN ('a', 'b', 'c')) + end + end + describe 'Equality' do it "should escape strings" do test = Table.new(:users)[:name].eq 'Aaron Patterson' |