aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relation/where_clause_test.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@thoughtbot.com>2015-01-27 09:41:25 -0700
committerSean Griffin <sean@thoughtbot.com>2015-01-27 09:41:25 -0700
commita5fcdae0a04d97dbd8fd05af6f352d3e09b2815f (patch)
treed4ecbd88d02dfe3215ebd06cfec24775652b5c63 /activerecord/test/cases/relation/where_clause_test.rb
parent16ce2eecd3eb23034555bb37b29c12985243d908 (diff)
downloadrails-a5fcdae0a04d97dbd8fd05af6f352d3e09b2815f.tar.gz
rails-a5fcdae0a04d97dbd8fd05af6f352d3e09b2815f.tar.bz2
rails-a5fcdae0a04d97dbd8fd05af6f352d3e09b2815f.zip
Move where grouping into `WhereClause`
Diffstat (limited to 'activerecord/test/cases/relation/where_clause_test.rb')
-rw-r--r--activerecord/test/cases/relation/where_clause_test.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation/where_clause_test.rb b/activerecord/test/cases/relation/where_clause_test.rb
index 6864be2608..511d595f71 100644
--- a/activerecord/test/cases/relation/where_clause_test.rb
+++ b/activerecord/test/cases/relation/where_clause_test.rb
@@ -111,6 +111,39 @@ class ActiveRecord::Relation
assert_equal expected, where_clause.except("id", "name")
end
+ test "ast groups its predicates with AND" do
+ where_clause = WhereClause.new([
+ table["id"].in([1, 2, 3]),
+ table["name"].eq(bind_param),
+ ], [])
+ expected = Arel::Nodes::And.new(where_clause.predicates)
+
+ assert_equal expected, where_clause.ast
+ end
+
+ test "ast wraps any SQL literals in parenthesis" do
+ random_object = Object.new
+ where_clause = WhereClause.new([
+ table["id"].in([1, 2, 3]),
+ "foo = bar",
+ random_object,
+ ], [])
+ expected = Arel::Nodes::And.new([
+ table["id"].in([1, 2, 3]),
+ Arel::Nodes::Grouping.new(Arel.sql("foo = bar")),
+ Arel::Nodes::Grouping.new(random_object),
+ ])
+
+ assert_equal expected, where_clause.ast
+ end
+
+ test "ast removes any empty strings" do
+ where_clause = WhereClause.new([table["id"].in([1, 2, 3])], [])
+ where_clause_with_empty = WhereClause.new([table["id"].in([1, 2, 3]), ''], [])
+
+ assert_equal where_clause.ast, where_clause_with_empty.ast
+ end
+
private
def table