From 4b1d5b772d4d812c231dbd713c5dcf9197b28002 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Fri, 22 Jul 2011 14:19:58 -0700 Subject: [PATCH] Failing spec for the second retraction for a reshared post, reshares need to refer to guids --- app/models/reshare.rb | 12 ++++++++++-- spec/models/signed_retraction_spec.rb | 24 ++++++++++++++++++++++++ spec/multi_server/repost_spec.rb | 1 - 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 72e3ccbca..9ba63bcd9 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -43,8 +43,7 @@ class Reshare < Post local_post = Post.where(:guid => @root_guid).select('id').first unless local_post && self.root_id = local_post.id - response = Faraday.get(root_author.url + "/p/#{@root_guid}.xml") - received_post = Diaspora::Parser.from_xml(response.body) + received_post = self.class.fetch_post(root_author, @root_guid) unless post = received_post.class.where(:guid => received_post.guid).first post = received_post @@ -61,6 +60,15 @@ class Reshare < Post end end + # Fetch a remote public post, used for receiving reshares of unknown posts + # @param [Person] author the remote post's author + # @param [String] guid the remote post's guid + # @return [Post] an unsaved remote post + def self.fetch_post author, guid + response = Faraday.get(root_author.url + "/p/#{@root_guid}.xml") + Diaspora::Parser.from_xml(response.body) + end + def root_must_be_public if self.root && !self.root.public errors[:base] << "you must reshare public posts" diff --git a/spec/models/signed_retraction_spec.rb b/spec/models/signed_retraction_spec.rb index de5b38da3..7c86a2ac6 100644 --- a/spec/models/signed_retraction_spec.rb +++ b/spec/models/signed_retraction_spec.rb @@ -19,5 +19,29 @@ describe SignedRetraction do retraction.perform(@resharer) end + it 'relays the retraction onward even if the post does not exist' do + remote_post = Factory(:status_message, :public => true) + bob.post(:reshare, :root_id => remote_post.id) + alice.post(:reshare, :root_id => remote_post.id) + + remote_retraction = SignedRetraction.new.tap{|r| + r.target_type = remote_post.type + r.target_guid = remote_post.guid + r.sender = remote_post.author + r.stub!(:target_author_signature_valid?).and_return(true) + } + + remote_retraction.dup.perform(bob) + Post.exists?(:id => remote_post.id).should be_false + + dis = mock + Postzord::Dispatch.should_receive(:new){ |sender, retraction| + sender.should == alice + retraction.sender.should == alice.person + dis + } + dis.should_receive(:post) + remote_retraction.perform(alice) + end end end diff --git a/spec/multi_server/repost_spec.rb b/spec/multi_server/repost_spec.rb index 39bacb164..1f3e70921 100644 --- a/spec/multi_server/repost_spec.rb +++ b/spec/multi_server/repost_spec.rb @@ -72,6 +72,5 @@ unless Server.all.empty? Post.exists?(:guid => @original_post.guid).should be_false end end - end end