Refactor implementation of #reshare_count.
The old implementation which uses Post.where causes undefined method `abstract_class?' for Object:Class in spec/controllers/posts_controller_spec.rb. Not sure whether that's a problem with Rails, or rspec, or what.
This commit is contained in:
parent
51566ebe0b
commit
a604dd2aa6
2 changed files with 43 additions and 2 deletions
|
|
@ -54,7 +54,7 @@ class Post < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def reshare_count
|
def reshare_count
|
||||||
@reshare_count ||= Post.where(:root_guid => self.guid).count
|
@reshare_count ||= Post.find_all_by_root_guid(self.guid).count
|
||||||
end
|
end
|
||||||
|
|
||||||
# @return Returns true if this Post will accept updates (i.e. updates to the caption of a photo).
|
# @return Returns true if this Post will accept updates (i.e. updates to the caption of a photo).
|
||||||
|
|
|
||||||
|
|
@ -378,4 +378,45 @@ describe Post do
|
||||||
end
|
end
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue