diff options
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/named_scope_test.rb | 9 | ||||
-rw-r--r-- | activerecord/test/models/post.rb | 6 |
2 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/named_scope_test.rb b/activerecord/test/cases/named_scope_test.rb index e1e27fa130..f28285faaf 100644 --- a/activerecord/test/cases/named_scope_test.rb +++ b/activerecord/test/cases/named_scope_test.rb @@ -142,6 +142,15 @@ class NamedScopeTest < ActiveRecord::TestCase assert_equal authors(:david).comments & Comment.containing_the_letter_e, authors(:david).comments.containing_the_letter_e end + def test_named_scopes_honor_current_scopes_from_when_defined + assert !Post.ranked_by_comments.limit(5).empty? + assert !authors(:david).posts.ranked_by_comments.limit(5).empty? + assert_not_equal Post.ranked_by_comments.limit(5), authors(:david).posts.ranked_by_comments.limit(5) + assert_not_equal Post.top(5), authors(:david).posts.top(5) + assert_equal authors(:david).posts.ranked_by_comments.limit(5), authors(:david).posts.top(5) + assert_equal Post.ranked_by_comments.limit(5), Post.top(5) + end + def test_active_records_have_scope_named__all__ assert !Topic.find(:all).empty? diff --git a/activerecord/test/models/post.rb b/activerecord/test/models/post.rb index 388fff8fba..374e536a5b 100644 --- a/activerecord/test/models/post.rb +++ b/activerecord/test/models/post.rb @@ -1,5 +1,7 @@ class Post < ActiveRecord::Base named_scope :containing_the_letter_a, :conditions => "body LIKE '%a%'" + named_scope :ranked_by_comments, :order => "comments_count DESC" + named_scope :limit, lambda {|limit| {:limit => limit} } named_scope :with_authors_at_address, lambda { |address| { :conditions => [ 'authors.author_address_id = ?', address.id ], :joins => 'JOIN authors ON authors.id = posts.author_id' @@ -68,6 +70,10 @@ class Post < ActiveRecord::Base :before_remove => lambda {|owner, reader| log(:removed, :before, reader.first_name) }, :after_remove => lambda {|owner, reader| log(:removed, :after, reader.first_name) } + def self.top(limit) + ranked_by_comments.limit(limit) + end + def self.reset_log @log = [] end |