aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/relation_scoping_test.rb11
-rw-r--r--activerecord/test/models/post.rb6
2 files changed, 17 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb
index 64365c1d75..965bdacc1a 100644
--- a/activerecord/test/cases/relation_scoping_test.rb
+++ b/activerecord/test/cases/relation_scoping_test.rb
@@ -311,6 +311,17 @@ class DefaultScopingTest < ActiveRecord::TestCase
assert_equal expected, received
end
+ def test_default_scope_with_lambda
+ expected = Post.find_all_by_author_id(2)
+ PostForAuthor.selected_author = 2
+ received = PostForAuthor.all
+ assert_equal expected, received
+ expected = Post.find_all_by_author_id(1)
+ PostForAuthor.selected_author = 1
+ received = PostForAuthor.all
+ assert_equal expected, received
+ end
+
def test_default_scope_is_unscoped_on_find
assert_equal 1, DeveloperCalledDavid.count
assert_equal 11, DeveloperCalledDavid.unscoped.count
diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb
index a3cb9c724a..61e782ff14 100644
--- a/activerecord/test/models/post.rb
+++ b/activerecord/test/models/post.rb
@@ -113,3 +113,9 @@ class PostWithComment < ActiveRecord::Base
self.table_name = 'posts'
default_scope where("posts.comments_count > 0").order("posts.comments_count ASC")
end
+
+class PostForAuthor < ActiveRecord::Base
+ self.table_name = 'posts'
+ cattr_accessor :selected_author
+ default_scope lambda { where(:author_id => PostForAuthor.selected_author) }
+end