diff --git a/lib/diaspora/likeable.rb b/lib/diaspora/likeable.rb index 6d0fc532d..1bf91bf3c 100644 --- a/lib/diaspora/likeable.rb +++ b/lib/diaspora/likeable.rb @@ -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 diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 274f1ce08..908453b27 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -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