looks like there are sometimes objects passed into post presenter that respond to root while root is nil

This commit is contained in:
Jonne Haß 2012-05-11 14:23:05 +02:00
parent b16f309aca
commit 7a6d325f64
2 changed files with 14 additions and 4 deletions

View file

@ -60,7 +60,7 @@ class PostPresenter
end
def root
PostPresenter.new(@post.root, current_user).as_json if @post.respond_to?(:root)
PostPresenter.new(@post.root, current_user).as_json if @post.respond_to?(:root) && @post.root.present?
end
def user_like
@ -102,4 +102,4 @@ class PostInteractionPresenter
element.as_api_response(:backbone)
end
end
end
end

View file

@ -42,7 +42,17 @@ describe PostPresenter do
@unauthenticated_presenter.user_reshare.should be_nil
end
end
describe '#root' do
it 'does not raise if the root does not exists' do
reshare = Factory :reshare
reshare.root = nil
expect {
PostPresenter.new(reshare).root
}.to_not raise_error
end
end
describe '#next_post_path' do
it 'returns a string of the users next post' do
@presenter.next_post_path.should == "#{Rails.application.routes.url_helpers.post_path(@sm)}/next"
@ -71,4 +81,4 @@ describe PostPresenter do
end
end
end
end
end