diff --git a/app/models/reshare.rb b/app/models/reshare.rb index c59ac02c1..713df96fb 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -69,6 +69,15 @@ class Reshare < Post root.try(:nsfw) end + def absolute_root + current = self + while( current.is_a?(Reshare) ) + current = current.root + end + + current + end + private def after_parse diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index 151f51176..f6ef2fd2f 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -63,7 +63,7 @@ class PostPresenter end def root - PostPresenter.new(@post.root, current_user).as_json if @post.respond_to?(:root) && @post.root.present? + PostPresenter.new(@post.absolute_root, current_user).as_json if @post.respond_to?(:root) && @post.root.present? end def user_like @@ -83,6 +83,7 @@ class PostPresenter def user_signed_in? @current_user.present? end + end class PostInteractionPresenter diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index b8311a3ca..3d92bc007 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -81,6 +81,19 @@ describe Reshare do end end + describe '#absolute_root' do + before do + @sm = Factory(:status_message, :author => alice.person, :public => true) + rs1 = Factory(:reshare, :root=>@sm) + rs2 = Factory(:reshare, :root=>rs1) + @rs3 = Factory(:reshare, :root=>rs2) + end + + it 'resolves root posts to the top level' do + @rs3.absolute_root.should == @sm + end + end + describe "XML" do before do @reshare = Factory(:reshare)