Merge pull request #4957 from MrZYX/4956_deleted_reshare
Use absolute_root more consistently in Reshare
This commit is contained in:
commit
01381ddf25
2 changed files with 40 additions and 28 deletions
|
|
@ -29,28 +29,24 @@ class Reshare < Post
|
|||
self.root.author.diaspora_handle
|
||||
end
|
||||
|
||||
def o_embed_cache
|
||||
self.root ? root.o_embed_cache : super
|
||||
end
|
||||
|
||||
def open_graph_cache
|
||||
self.root ? root.open_graph_cache : super
|
||||
end
|
||||
delegate :o_embed_cache, :open_graph_cache,
|
||||
:message, :nsfw,
|
||||
to: :absolute_root, allow_nil: true
|
||||
|
||||
def raw_message
|
||||
self.root ? root.raw_message : super
|
||||
end
|
||||
|
||||
def message
|
||||
absolute_root.message if root.present?
|
||||
absolute_root.try(:raw_message) || super
|
||||
end
|
||||
|
||||
def mentioned_people
|
||||
self.root ? root.mentioned_people : super
|
||||
absolute_root.try(:mentioned_people) || super
|
||||
end
|
||||
|
||||
def photos
|
||||
self.root ? root.photos : []
|
||||
absolute_root.try(:photos) || super
|
||||
end
|
||||
|
||||
def address
|
||||
absolute_root.try(:location).try(:address)
|
||||
end
|
||||
|
||||
def receive(recipient, sender)
|
||||
|
|
@ -69,21 +65,10 @@ class Reshare < Post
|
|||
Notifications::Reshared if root.author == user.person
|
||||
end
|
||||
|
||||
def nsfw
|
||||
root.try(:nsfw)
|
||||
end
|
||||
|
||||
def absolute_root
|
||||
current = self
|
||||
while( current.is_a?(Reshare) )
|
||||
current = current.root
|
||||
end
|
||||
|
||||
current
|
||||
end
|
||||
|
||||
def address
|
||||
absolute_root.try(:location).try(:address)
|
||||
@absolute_root ||= self
|
||||
@absolute_root = @absolute_root.root while @absolute_root.is_a? Reshare
|
||||
@absolute_root
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -83,11 +83,38 @@ describe Reshare do
|
|||
rs1 = FactoryGirl.build(:reshare, :root=>@sm)
|
||||
rs2 = FactoryGirl.build(:reshare, :root=>rs1)
|
||||
@rs3 = FactoryGirl.build(:reshare, :root=>rs2)
|
||||
|
||||
sm = FactoryGirl.create(:status_message, :author => alice.person, :public => true)
|
||||
rs1 = FactoryGirl.create(:reshare, :root => sm)
|
||||
@of_deleted = FactoryGirl.build(:reshare, :root => rs1)
|
||||
sm.destroy
|
||||
rs1.reload
|
||||
end
|
||||
|
||||
it 'resolves root posts to the top level' do
|
||||
@rs3.absolute_root.should == @sm
|
||||
end
|
||||
|
||||
it 'can handle deleted reshares' do
|
||||
expect(@of_deleted.absolute_root).to be_nil
|
||||
end
|
||||
|
||||
it 'is used everywhere' do
|
||||
expect(@rs3.message).to eq @sm.message
|
||||
expect(@of_deleted.message).to be_nil
|
||||
expect(@rs3.photos).to eq @sm.photos
|
||||
expect(@of_deleted.photos).to be_empty
|
||||
expect(@rs3.o_embed_cache).to eq @sm.o_embed_cache
|
||||
expect(@of_deleted.o_embed_cache).to be_nil
|
||||
expect(@rs3.open_graph_cache).to eq @sm.open_graph_cache
|
||||
expect(@of_deleted.open_graph_cache).to be_nil
|
||||
expect(@rs3.mentioned_people).to eq @sm.mentioned_people
|
||||
expect(@of_deleted.mentioned_people).to be_empty
|
||||
expect(@rs3.nsfw).to eq @sm.nsfw
|
||||
expect(@of_deleted.nsfw).to be_nil
|
||||
expect(@rs3.address).to eq @sm.location.try(:address)
|
||||
expect(@of_deleted.address).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "XML" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue