aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorEdward Paget <edward@cassetteta.pe>2015-01-14 12:23:37 -0600
committerSean Griffin <sean@seantheprogrammer.com>2015-12-17 12:49:50 -0700
commitf726dbe0802395aabf9cc99fe34bc69b375bf344 (patch)
tree984b5c89c8dc9164c373c13326597ffeeb6f67e1 /test
parentdad0e081c4dc9dbbcdb195ff4e7f9ad4d2bc6de3 (diff)
downloadrails-f726dbe0802395aabf9cc99fe34bc69b375bf344.tar.gz
rails-f726dbe0802395aabf9cc99fe34bc69b375bf344.tar.bz2
rails-f726dbe0802395aabf9cc99fe34bc69b375bf344.zip
Delegate to Connection Visitor in WhereSQL Visitor
The WhereSQL visitor always uses the generic ToSQL visitor to create the where clause sql statement. This means that it'll miss database specific statements, such as 'ILIKE' in PostgreSQL. Since the `#where_sql` method is mainly used for ActiveRecord error reporting, this discrepancy could be confusing to users. This patch changes the WhereSQL visitor to use the its connection visitor to generate SQL for each statement in the SelectManager's wheres array. Then lets them be joined together with ' AND '.
Diffstat (limited to 'test')
-rw-r--r--test/test_select_manager.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/test_select_manager.rb b/test/test_select_manager.rb
index 8425cee031..e6b13e748d 100644
--- a/test/test_select_manager.rb
+++ b/test/test_select_manager.rb
@@ -968,6 +968,27 @@ module Arel
manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 }
end
+ it 'joins wheres with AND' do
+ table = Table.new :users
+ manager = Arel::SelectManager.new
+ manager.from table
+ manager.where table[:id].eq 10
+ manager.where table[:id].eq 11
+ manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 AND "users"."id" = 11}
+ end
+
+ it 'handles database specific statements' do
+ old_visitor = Table.engine.connection.visitor
+ Table.engine.connection.visitor = Visitors::PostgreSQL.new Table.engine.connection
+ table = Table.new :users
+ manager = Arel::SelectManager.new
+ manager.from table
+ manager.where table[:id].eq 10
+ manager.where table[:name].matches 'foo%'
+ manager.where_sql.must_be_like %{ WHERE "users"."id" = 10 AND "users"."name" ILIKE 'foo%' }
+ Table.engine.connection.visitor = old_visitor
+ end
+
it 'returns nil when there are no wheres' do
table = Table.new :users
manager = Arel::SelectManager.new