Merge pull request #3275 from diaspora/reshare-root

resolve reshare authors to the first one
This commit is contained in:
Maxwell Salzberg 2012-05-17 16:51:52 -07:00
commit 973d6d9e8b
3 changed files with 24 additions and 1 deletions

View file

@ -69,6 +69,15 @@ class Reshare < Post
root.try(:nsfw) root.try(:nsfw)
end end
def absolute_root
current = self
while( current.is_a?(Reshare) )
current = current.root
end
current
end
private private
def after_parse def after_parse

View file

@ -63,7 +63,7 @@ class PostPresenter
end end
def root 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 end
def user_like def user_like
@ -83,6 +83,7 @@ class PostPresenter
def user_signed_in? def user_signed_in?
@current_user.present? @current_user.present?
end end
end end
class PostInteractionPresenter class PostInteractionPresenter

View file

@ -81,6 +81,19 @@ describe Reshare do
end end
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 describe "XML" do
before do before do
@reshare = Factory(:reshare) @reshare = Factory(:reshare)