diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-01-28 14:04:26 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-01-28 14:35:03 -0700 |
commit | ff45b9e9f7c4ff0fb4fdab8beb539913b876d63b (patch) | |
tree | 1513baae2abecb8e0ce14fe21ae8563c876d25ab /activerecord/test/cases/relation/where_clause_test.rb | |
parent | b0b37942d729b6bdcd2e3178eda7fa1de203b3d0 (diff) | |
download | rails-ff45b9e9f7c4ff0fb4fdab8beb539913b876d63b.tar.gz rails-ff45b9e9f7c4ff0fb4fdab8beb539913b876d63b.tar.bz2 rails-ff45b9e9f7c4ff0fb4fdab8beb539913b876d63b.zip |
Bring the implementation of Relation#or up to speed
Diffstat (limited to 'activerecord/test/cases/relation/where_clause_test.rb')
-rw-r--r-- | activerecord/test/cases/relation/where_clause_test.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation/where_clause_test.rb b/activerecord/test/cases/relation/where_clause_test.rb index db18980e0b..7325aec0a9 100644 --- a/activerecord/test/cases/relation/where_clause_test.rb +++ b/activerecord/test/cases/relation/where_clause_test.rb @@ -145,6 +145,26 @@ class ActiveRecord::Relation assert_equal where_clause.ast, where_clause_with_empty.ast end + test "or joins the two clauses using OR" do + where_clause = WhereClause.new([table["id"].eq(bind_param)], [attribute("id", 1)]) + other_clause = WhereClause.new([table["name"].eq(bind_param)], [attribute("name", "Sean")]) + expected_ast = + Arel::Nodes::Grouping.new( + Arel::Nodes::Or.new(table["id"].eq(bind_param), table["name"].eq(bind_param)) + ) + expected_binds = where_clause.binds + other_clause.binds + + assert_equal expected_ast.to_sql, where_clause.or(other_clause).ast.to_sql + assert_equal expected_binds, where_clause.or(other_clause).binds + end + + test "or does nothing with an empty where clause" do + where_clause = WhereClause.new([table["id"].eq(bind_param)], [attribute("id", 1)]) + + assert_equal where_clause, where_clause.or(WhereClause.empty) + assert_equal where_clause, WhereClause.empty.or(where_clause) + end + private def table |