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
|
||||||
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
|
def test_scopes_are_reset_on_association_reload
|
||||||
post = posts(:welcome)
|
post = posts(:welcome)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ class Comment < ActiveRecord::Base
|
||||||
scope :for_first_author,
|
scope :for_first_author,
|
||||||
:joins => :post,
|
:joins => :post,
|
||||||
:conditions => { "posts.author_id" => 1 }
|
:conditions => { "posts.author_id" => 1 }
|
||||||
|
scope :created
|
||||||
|
|
||||||
belongs_to :post, :counter_cache => true
|
belongs_to :post, :counter_cache => true
|
||||||
has_many :ratings
|
has_many :ratings
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,10 @@ class Post < ActiveRecord::Base
|
||||||
def find_most_recent
|
def find_most_recent
|
||||||
find(:first, :order => "id DESC")
|
find(:first, :order => "id DESC")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def newest
|
||||||
|
created.last
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
has_many :author_favorites, :through => :author
|
has_many :author_favorites, :through => :author
|
||||||
|
|
Loading…
Reference in a new issue