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)
|
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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue