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/lib/tasks/fixtures.rake b/lib/tasks/fixtures.rake index 4d41da041..8fa3ad9c7 100644 --- a/lib/tasks/fixtures.rake +++ b/lib/tasks/fixtures.rake @@ -76,6 +76,15 @@ namespace :fixtures do user3.reload user4.receive(remote_photo.to_diaspora_xml, remote_person) user3.reload + + + facebook = Services::Facebook.new(:access_token => "yeah") + user3.services << facebook + facebook.save! + + twitter = Services::Twitter.new(:access_token => "yeah", :access_secret => "foobar") + user2.services << twitter + twitter.save! end puts "Done generating fixtures, you can now export" 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/helper_methods.rb b/spec/helper_methods.rb index d97a84d59..d8b5991bd 100644 --- a/spec/helper_methods.rb +++ b/spec/helper_methods.rb @@ -8,14 +8,6 @@ module HelperMethods Mocha::Mockery.instance.stubba.unstub_all end - def fantasy_resque - former_value = $process_queue - $process_queue = true - result = yield - $process_queue = former_value - result - end - def connect_users(user1, aspect1, user2, aspect2) Contact.create!(:user => user1, :person => user2.person, 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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cf8572166..7c8672584 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -14,11 +14,11 @@ require 'webmock/rspec' include Devise::TestHelpers include WebMock::API -include HelperMethods # # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories. Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} +include HelperMethods RSpec.configure do |config| config.mock_with :mocha diff --git a/spec/support/fake_resque.rb b/spec/support/fake_resque.rb index 165d9ea10..e08eb0a03 100644 --- a/spec/support/fake_resque.rb +++ b/spec/support/fake_resque.rb @@ -7,3 +7,13 @@ module Resque end end end + +module HelperMethods + def fantasy_resque + former_value = $process_queue + $process_queue = true + result = yield + $process_queue = former_value + result + end +end