diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-05-25 00:07:38 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-05-25 00:08:14 +0100 |
commit | c69111ba5fde8445237f682c88b927bcde1588d4 (patch) | |
tree | 4f29767a8b0c45352b2383f5bce497d582d8e98a /activerecord/test | |
parent | d21fef324b5270e9e3c255d278974a15a34b118a (diff) | |
download | rails-c69111ba5fde8445237f682c88b927bcde1588d4.tar.gz rails-c69111ba5fde8445237f682c88b927bcde1588d4.tar.bz2 rails-c69111ba5fde8445237f682c88b927bcde1588d4.zip |
Fix infinite recursion where a lazy default scope references a scope. Fixes #1264.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/relation_scoping_test.rb | 8 | ||||
-rw-r--r-- | activerecord/test/models/developer.rb | 15 |
2 files changed, 23 insertions, 0 deletions
diff --git a/activerecord/test/cases/relation_scoping_test.rb b/activerecord/test/cases/relation_scoping_test.rb index c215602567..8f8e72f052 100644 --- a/activerecord/test/cases/relation_scoping_test.rb +++ b/activerecord/test/cases/relation_scoping_test.rb @@ -312,6 +312,14 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal [developers(:david).becomes(ClassMethodDeveloperCalledDavid)], ClassMethodDeveloperCalledDavid.all end + def test_default_scope_as_class_method_referencing_scope + assert_equal [developers(:david).becomes(ClassMethodReferencingScopeDeveloperCalledDavid)], ClassMethodReferencingScopeDeveloperCalledDavid.all + end + + def test_default_scope_as_block_referencing_scope + assert_equal [developers(:david).becomes(LazyBlockReferencingScopeDeveloperCalledDavid)], LazyBlockReferencingScopeDeveloperCalledDavid.all + end + def test_default_scope_with_lambda assert_equal [developers(:david).becomes(LazyLambdaDeveloperCalledDavid)], LazyLambdaDeveloperCalledDavid.all end diff --git a/activerecord/test/models/developer.rb b/activerecord/test/models/developer.rb index a2aa8ae664..41c52f7df0 100644 --- a/activerecord/test/models/developer.rb +++ b/activerecord/test/models/developer.rb @@ -127,6 +127,21 @@ class ClassMethodDeveloperCalledDavid < ActiveRecord::Base end end +class ClassMethodReferencingScopeDeveloperCalledDavid < ActiveRecord::Base + self.table_name = 'developers' + scope :david, where(:name => 'David') + + def self.default_scope + david + end +end + +class LazyBlockReferencingScopeDeveloperCalledDavid < ActiveRecord::Base + self.table_name = 'developers' + scope :david, where(:name => 'David') + default_scope { david } +end + class DeveloperCalledJamis < ActiveRecord::Base self.table_name = 'developers' |