Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Robinson <mail@jasonrobinson.me>2014-05-16 11:00:31 +0400
committerJason Robinson <mail@jasonrobinson.me>2014-05-16 11:00:31 +0400
commit01381ddf25b8cd7eb7720049b06ad23f6985e5f1 (patch)
treee066b976e953c52ace0ef29dd4423d8291d51690
parent63c44d9f6bc2d7c218cac32104f544c8063e4f75 (diff)
parent8a599e1c1dca39c4dbfe58caa9bef4a69f3d19ae (diff)
Merge pull request #4957 from MrZYX/4956_deleted_reshare
Use absolute_root more consistently in Reshare
-rw-r--r--app/models/reshare.rb41
-rw-r--r--spec/models/reshare_spec.rb27
2 files changed, 40 insertions, 28 deletions
diff --git a/app/models/reshare.rb b/app/models/reshare.rb
index da902dc3d..5bb5326d5 100644
--- a/app/models/reshare.rb
+++ b/app/models/reshare.rb
@@ -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
diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb
index 52a484785..63e4295b8 100644
--- a/spec/models/reshare_spec.rb
+++ b/spec/models/reshare_spec.rb
@@ -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