resolve reshare root posts to the first one
This commit is contained in:
parent
c66bd9d6d8
commit
788f328a77
3 changed files with 24 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue