diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index be5d7b570..7f1162989 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -56,7 +56,7 @@ class PublicsController < ApplicationController end @user = person.owner - Resque.enqueue(Jobs::ReceiveSalmon, @user.id, params[:xml]) + Resque.enqueue(Jobs::ReceiveSalmon, @user.id, CGI::unescape(params[:xml])) render :nothing => true, :status => 200 end diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index ac78c148e..c5eeed0fb 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -23,6 +23,20 @@ describe PublicsController do post :receive, "id" => user.person.id.to_s, "xml" => xml end + it 'unescapes the xml before sending it to receive_salmon' do + aspect = user.aspects.create(:name => 'foo') + post1 = user.post(:status_message, :message => 'moms', :to => [aspect.id]) + xml2 = post1.to_diaspora_xml + user2 = make_user + + salmon_factory = Salmon::SalmonSlap.create(user, xml2) + enc_xml = salmon_factory.xml_for(user2.person) + + Resque.should_receive(:enqueue).with(Jobs::ReceiveSalmon, user.id, enc_xml).once + + post :receive, "id" => user.person.id.to_s, "xml" => CGI::escape(enc_xml) + end + it 'returns a 422 if no xml is passed' do post :receive, "id" => person.id.to_s response.code.should == '422' diff --git a/spec/lib/pubsubhubbub_spec.rb b/spec/lib/pubsubhubbub_spec.rb index 1a90c29c4..fd17dee86 100644 --- a/spec/lib/pubsubhubbub_spec.rb +++ b/spec/lib/pubsubhubbub_spec.rb @@ -5,11 +5,11 @@ require 'spec_helper' describe PubSubHubbub do - before :all do + before do RestClient.unstub!(:post) end - after :all do + after do RestClient.stub!(:post).and_return(FakeHttpRequest.new(:success)) end diff --git a/spec/models/jobs/post_to_service_spec.rb b/spec/models/jobs/post_to_service_spec.rb index 59cb062c6..74fa74708 100644 --- a/spec/models/jobs/post_to_service_spec.rb +++ b/spec/models/jobs/post_to_service_spec.rb @@ -13,4 +13,3 @@ describe Jobs::PostToService do Jobs::PostToService.perform("123", post.id.to_s, url) end end - diff --git a/spec/models/jobs/receive_salmon_spec.rb b/spec/models/jobs/receive_salmon_spec.rb index 7a5df6a4b..8e64acceb 100644 --- a/spec/models/jobs/receive_salmon_spec.rb +++ b/spec/models/jobs/receive_salmon_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe Jobs::ReceiveSalmon do before do @user = make_user + @user2 = make_user @xml = '' User.stub(:find){ |id| if id == @user.id @@ -16,4 +17,7 @@ describe Jobs::ReceiveSalmon do @user.should_receive(:receive_salmon).with(@xml).once Jobs::ReceiveSalmon.perform(@user.id, @xml) end + + + end diff --git a/spec/models/user/receive_spec.rb b/spec/models/user/receive_spec.rb index 33f74a123..d250184cd 100644 --- a/spec/models/user/receive_spec.rb +++ b/spec/models/user/receive_spec.rb @@ -49,14 +49,16 @@ describe User do end describe '#receive_salmon' do - it 'should handle the case where the webfinger fails' do - pending "Write this to test #receive_salmon" - Webfinger.stub!(:fetch).and_return(nil) + it 'should handle the case where the webfinger fails' do + pending "Write this to test #receive_salmon" + Webfinger.stub!(:fetch).and_return(nil) + + proc{ + user2.post :status_message, :message => "store this!", :to => aspect2.id + }.should_not raise_error + end + - proc{ - user2.post :status_message, :message => "store this!", :to => aspect2.id - }.should_not raise_error - end end context 'update posts' do @@ -182,7 +184,7 @@ describe User do let(:salmon){user.salmon( post )} it 'should receive a salmon for a post' do - user2.receive_salmon( salmon.xml_for user2.person ) + user2.receive_salmon( salmon.xml_for(user2.person) ) user2.visible_post_ids.include?(post.id).should be true end end