mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Test added for namedscope target.
This commit is contained in:
parent
f064664de7
commit
0695eb6dac
3 changed files with 14 additions and 1 deletions
|
@ -456,6 +456,14 @@ class NamedScopeTest < ActiveRecord::TestCase
|
|||
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,6 +6,7 @@ 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 @@ class Post < ActiveRecord::Base
|
|||
def find_most_recent
|
||||
find(:first, :order => "id DESC")
|
||||
end
|
||||
|
||||
def newest
|
||||
created.last
|
||||
end
|
||||
end
|
||||
|
||||
has_many :author_favorites, :through => :author
|
||||
|
|
Loading…
Reference in a new issue