Permalink
Browse files

Add tests for default scope behaviour change

See #13875
  • Loading branch information...
1 parent 2fdbddd commit 25a05723792bdd65a617b67a01108ae396309b8e @jonleighton jonleighton committed Feb 23, 2014
Showing with 20 additions and 0 deletions.
  1. +18 −0 activerecord/test/cases/scoping/default_scoping_test.rb
  2. +2 −0 activerecord/test/models/developer.rb
@@ -395,4 +395,22 @@ def test_default_scope_is_threadsafe
threads.each(&:join)
end
end
+
+ test "additional conditions are ANDed with the default scope" do
+ scope = DeveloperCalledJamis.where(name: "David")
+ assert_equal 2, scope.where_values.length
+ assert_equal [], scope.to_a
+ end
+
+ test "additional conditions in a scope are ANDed with the default scope" do
+ scope = DeveloperCalledJamis.david
+ assert_equal 2, scope.where_values.length
+ assert_equal [], scope.to_a
+ end
+
+ test "a scope can remove the condition from the default scope" do
+ scope = DeveloperCalledJamis.david2
+ assert_equal 1, scope.where_values.length
+ assert_equal Developer.where(name: "David").map(&:id), scope.map(&:id)
+ end
end
@@ -165,6 +165,8 @@ class DeveloperCalledJamis < ActiveRecord::Base
default_scope { where(:name => 'Jamis') }
scope :poor, -> { where('salary < 150000') }
+ scope :david, -> { where name: "David" }
+ scope :david2, -> { unscoped.where name: "David" }
end
class PoorDeveloperCalledJamis < ActiveRecord::Base

0 comments on commit 25a0572

Please sign in to comment.