Permalink
Browse files

Merge pull request #1462 from arunagw/test_added_for_namedscope

Test added for namedscope target.
  • Loading branch information...
2 parents 9cdd606 + 0695eb6 commit b5b31658bcc963ebb4a8577715d81bb80ddaab3c @josevalim josevalim committed Jun 5, 2011
@@ -456,6 +456,14 @@ def test_scopes_with_arguments_are_cached_on_associations
end
end
+ def test_scopes_to_get_newest
+ post = posts(:welcome)
+ old_last_comment = post.comments.newest
+ new_comment = post.comments.create(:body => "My new comment")
+ assert_equal new_comment, post.comments.newest
+ assert_not_equal old_last_comment, post.comments.newest
+ end
+
def test_scopes_are_reset_on_association_reload
post = posts(:welcome)
@@ -6,7 +6,8 @@ class Comment < ActiveRecord::Base
scope :for_first_author,
:joins => :post,
:conditions => { "posts.author_id" => 1 }
-
+ scope :created
+
belongs_to :post, :counter_cache => true
has_many :ratings
@@ -36,6 +36,10 @@ 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 b5b3165

Please sign in to comment.