From 987d44c41c0851e64fbabdc7cb04828738810520 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Mon, 18 Jul 2011 15:43:36 -0700 Subject: [PATCH] fixed reshare specs; all specs green --- app/models/reshare.rb | 8 +++++++- spec/models/reshare_spec.rb | 25 +++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/app/models/reshare.rb b/app/models/reshare.rb index 716780a7d..3ea3f0439 100644 --- a/app/models/reshare.rb +++ b/app/models/reshare.rb @@ -45,7 +45,13 @@ class Reshare < Post received_post = Diaspora::Parser.from_xml(Faraday.get(root_author.url + "/p/#{@root_guid}.xml").body) unless post = received_post.class.where(:guid => received_post.guid).first post = received_post - post.save + + if root_author.diaspora_handle != post.diaspora_handle + raise "Diaspora ID (#{post.diaspora_handle}) in the root does not match the Diaspora ID (#{root_author.diaspora_handle}) specified in the reshare!" + end + + post.author_id = root_author.id + post.save! end self.root_id = post.id diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index c3b02d9ed..02a74db0a 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -75,7 +75,8 @@ describe Reshare do context 'remote' do before do - @root_object = @reshare.root.delete + @root_object = @reshare.root + @root_object.delete end it 'fetches the root author from root_diaspora_id' do @@ -84,6 +85,8 @@ describe Reshare do @original_author = @reshare.root.author.dup @reshare.root.author.delete + @original_author.profile = @original_profile + wf_prof_mock = mock wf_prof_mock.should_receive(:fetch).and_return(@original_author) Webfinger.should_receive(:new).and_return(wf_prof_mock) @@ -99,7 +102,7 @@ describe Reshare do before do response = mock response.stub(:body).and_return(@root_object.to_diaspora_xml) - Faraday.default_connection.should_receive(:get).with(@reshare.root.author.url + public_post_path(:guid => @root_object.guid, :format => "xml")).and_return(response) + Faraday.default_connection.stub(:get).with(@reshare.root.author.url + public_post_path(:guid => @root_object.guid, :format => "xml")).and_return(response) end it 'fetches the root post from root_guid' do @@ -115,8 +118,26 @@ describe Reshare do end it 'correctly sets the author' do + @original_author = @reshare.root.author Reshare.from_xml(@xml).root.reload.author.reload.should == @original_author end + + it 'verifies that the author of the post received is the same as the author in the reshare xml' do + @original_author = @reshare.root.author.dup + @xml = @reshare.to_xml.to_s + + different_person = Factory.create(:person) + + wf_prof_mock = mock + wf_prof_mock.should_receive(:fetch).and_return(different_person) + Webfinger.should_receive(:new).and_return(wf_prof_mock) + + different_person.stub(:url).and_return(@original_author.url) + + lambda{ + Reshare.from_xml(@xml) + }.should raise_error /^Diaspora ID \(.+\) in the root does not match the Diaspora ID \(.+\) specified in the reshare!$/ + end end end end