diff options
-rw-r--r-- | activerecord/lib/active_record/relation/where_clause.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/relation/or_test.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/relation/where_clause_test.rb | 6 |
3 files changed, 7 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/relation/where_clause.rb b/activerecord/lib/active_record/relation/where_clause.rb index ce307e4f0c..f9b9e640ec 100644 --- a/activerecord/lib/active_record/relation/where_clause.rb +++ b/activerecord/lib/active_record/relation/where_clause.rb @@ -33,9 +33,9 @@ module ActiveRecord def or(other) if empty? - other - elsif other.empty? self + elsif other.empty? + other else WhereClause.new( [ast.or(other.ast)], diff --git a/activerecord/test/cases/relation/or_test.rb b/activerecord/test/cases/relation/or_test.rb index 1515b9c454..2006fc9611 100644 --- a/activerecord/test/cases/relation/or_test.rb +++ b/activerecord/test/cases/relation/or_test.rb @@ -35,12 +35,12 @@ module ActiveRecord end def test_or_without_left_where - expected = Post.where('id = 1') + expected = Post.all assert_equal expected, Post.or(Post.where('id = 1')).to_a end def test_or_without_right_where - expected = Post.where('id = 1') + expected = Post.all assert_equal expected, Post.where('id = 1').or(Post.all).to_a end diff --git a/activerecord/test/cases/relation/where_clause_test.rb b/activerecord/test/cases/relation/where_clause_test.rb index 7325aec0a9..c20ed94d90 100644 --- a/activerecord/test/cases/relation/where_clause_test.rb +++ b/activerecord/test/cases/relation/where_clause_test.rb @@ -158,11 +158,11 @@ class ActiveRecord::Relation assert_equal expected_binds, where_clause.or(other_clause).binds end - test "or does nothing with an empty where clause" do + test "or returns an empty where clause when either side is empty" 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) + assert_equal WhereClause.empty, where_clause.or(WhereClause.empty) + assert_equal WhereClause.empty, WhereClause.empty.or(where_clause) end private |