diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 819be652b..40b2fb954 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -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 \ No newline at end of file +end diff --git a/spec/presenters/post_presenter_spec.rb b/spec/presenters/post_presenter_spec.rb index 2e87f2bb9..0d3d205e8 100644 --- a/spec/presenters/post_presenter_spec.rb +++ b/spec/presenters/post_presenter_spec.rb @@ -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 \ No newline at end of file +end