Don't update target.updated_at when updating target.likes_count
This commit is contained in:
parent
134e8a1b20
commit
61eea529cb
2 changed files with 16 additions and 2 deletions
|
|
@ -13,8 +13,8 @@ module Diaspora
|
|||
|
||||
# @return [Integer]
|
||||
def update_likes_counter
|
||||
self.likes_count = self.likes.count
|
||||
self.save
|
||||
self.class.where(:id => self.id).
|
||||
update_all(:likes_count => self.likes.count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -62,4 +62,18 @@ describe Post do
|
|||
post.last_three_comments.map{|c| c.id}.should == comments[1,3].map{|c| c.id}
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Likeable#update_likes_counter' do
|
||||
before do
|
||||
@post = bob.post :status_message, :text => "hello", :to => 'all'
|
||||
bob.like(1, :target => @post)
|
||||
end
|
||||
it 'does not update updated_at' do
|
||||
old_time = Time.zone.now - 10000
|
||||
Post.where(:id => @post.id).update_all(:updated_at => old_time)
|
||||
@post.reload.updated_at.to_i.should == old_time.to_i
|
||||
@post.update_likes_counter
|
||||
@post.reload.updated_at.to_i.should == old_time.to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue