aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/relation_scoping_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/relation_scoping_test.rb')
-rw-r--r--activerecord/test/cases/relation_scoping_test.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb
index 965bdacc1a..689cce8746 100644
--- a/activerecord/test/cases/relation_scoping_test.rb
+++ b/activerecord/test/cases/relation_scoping_test.rb
@@ -322,6 +322,24 @@ class DefaultScopingTest < ActiveRecord::TestCase
assert_equal expected, received
end
+ def test_default_scope_with_thing_that_responds_to_call
+ klass = Class.new(ActiveRecord::Base) do
+ self.table_name = 'posts'
+ end
+
+ klass.class_eval do
+ default_scope Class.new(Struct.new(:klass)) {
+ def call
+ klass.where(:author_id => 2)
+ end
+ }.new(self)
+ end
+
+ records = klass.all
+ assert_equal 1, records.length
+ assert_equal 2, records.first.author_id
+ end
+
def test_default_scope_is_unscoped_on_find
assert_equal 1, DeveloperCalledDavid.count
assert_equal 11, DeveloperCalledDavid.unscoped.count