diff --git a/app/models/post.rb b/app/models/post.rb index e161f8fca..00a253447 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -54,7 +54,7 @@ class Post < ActiveRecord::Base end def reshare_count - @reshare_count ||= Post.where(:root_guid => self.guid).count + @reshare_count ||= Post.find_all_by_root_guid(self.guid).count end # @return Returns true if this Post will accept updates (i.e. updates to the caption of a photo). diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index fa546987e..dd872466b 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -24,7 +24,7 @@ describe Post do StatusMessage.owned_or_visible_by_user(@you).should include(@post_from_contact) end - it 'returns your posts' do + it 'returns your posts' do StatusMessage.owned_or_visible_by_user(@you).should include(@your_post) end @@ -378,4 +378,45 @@ describe Post do end end end + + describe '#reshare_count' do + before :each do + @post = @user.post :status_message, :text => "hello", :to => @aspect.id, :public => true + @post.reshares.size.should == 0 + end + + describe 'when post has not been reshared' do + it 'returns zero' do + @post.reshare_count.should == 0 + end + end + + describe 'when post has been reshared exactly 1 time' do + before :each do + @post.reshares.size.should == 0 + @reshare = Factory.create(:reshare, :root => @post) + @post.reload + @post.reshares.size.should == 1 + end + + it 'returns 1' do + @post.reshare_count.should == 1 + end + end + + describe 'when post has been reshared more than once' do + before :each do + @post.reshares.size.should == 0 + Factory.create(:reshare, :root => @post) + Factory.create(:reshare, :root => @post) + Factory.create(:reshare, :root => @post) + @post.reload + @post.reshares.size.should == 3 + end + + it 'returns the number of reshares' do + @post.reshare_count.should == 3 + end + end + end end