Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add tests for default scope behaviour change

See #13875
  • Loading branch information...
commit 40a9d8987711f7973c5e95087bcc0c59e167294b 1 parent f8dcc48
@jonleighton jonleighton authored
View
18 activerecord/test/cases/scoping/default_scoping_test.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
View
2  activerecord/test/models/developer.rb
@@ -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

2 comments on commit 40a9d89

@carlosantoniodasilva

@jonleighton maybe we should backport that to 4-1-stable too to avoid regressions?

@jonleighton
Collaborator

Good point, done

Please sign in to comment.
Something went wrong with that request. Please try again.