Permalink
Browse files

Test added for namedscope target. #1419

  • Loading branch information...
1 parent 9f50123 commit 66fb568c0a38187cff77a59d90e10b74e645bc0f @arunagw committed Jun 3, 2011
@@ -443,6 +443,14 @@ def test_named_scopes_are_cached_on_associations
assert_no_queries { post.comments.containing_the_letter_e.all }
end
+ def test_named_scopes_to_get_newest
+ post = posts(:welcome)
+ old_last_comment = post.comments.newest
+ new_comment = post.comments.create(:body => "My new comment")
+ assert_equal post.comments.newest, new_comment
+ #assert_not_equal post.comments.newest, old_last_comment
+ end
+
def test_named_scopes_with_arguments_are_cached_on_associations
post = posts(:welcome)
@@ -5,6 +5,7 @@ class Comment < ActiveRecord::Base
scope :for_first_author,
:joins => :post,
:conditions => { "posts.author_id" => 1 }
+ scope :created
belongs_to :post, :counter_cache => true
@@ -35,6 +35,11 @@ def greeting
def find_most_recent
find(:first, :order => "id DESC")
end
+
+ def newest
+ created.last
+ end
+
end
has_many :author_favorites, :through => :author

0 comments on commit 66fb568

Please sign in to comment.