aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-10-19 15:07:44 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-10-19 15:07:44 -0700
commite68f339aae4d3bc1bcf46b65cb8dcddc0ad2a435 (patch)
treee6e2beee0e388075041519eb12cb80a9bd761b84 /activerecord/test
parentb1b26af9a2f1c2037f7c2167d747ed33cc639763 (diff)
downloadrails-e68f339aae4d3bc1bcf46b65cb8dcddc0ad2a435.tar.gz
rails-e68f339aae4d3bc1bcf46b65cb8dcddc0ad2a435.tar.bz2
rails-e68f339aae4d3bc1bcf46b65cb8dcddc0ad2a435.zip
default scope can accept any object that responds to #call
Diffstat (limited to 'activerecord/test')
-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