From 930ea6c425aea277b26fe195e38eb1854c844c7a Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 14 Sep 2011 21:41:46 -0700 Subject: [PATCH] Fix failure, decode in receiver --- lib/hydra_wrapper.rb | 3 ++- lib/salmon/slap.rb | 3 +++ spec/lib/hydra_wrapper_spec.rb | 8 ++++++-- spec/models/job/receive_salmon_spec.rb | 7 ++++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/hydra_wrapper.rb b/lib/hydra_wrapper.rb index 46e9b1a0d..3ef31602a 100644 --- a/lib/hydra_wrapper.rb +++ b/lib/hydra_wrapper.rb @@ -3,6 +3,7 @@ # the COPYRIGHT file. require 'typhoeus' +require 'active_support/base64' class HydraWrapper @@ -27,7 +28,7 @@ class HydraWrapper # @return [Salmon] def salmon - @salmon ||= @dispatcher_class.salmon(@user, @encoded_object_xml) + @salmon ||= @dispatcher_class.salmon(@user, Base64.decode64(@encoded_object_xml)) end # Group people on their receiving_urls diff --git a/lib/salmon/slap.rb b/lib/salmon/slap.rb index 75bf7ec55..3007188b5 100644 --- a/lib/salmon/slap.rb +++ b/lib/salmon/slap.rb @@ -9,6 +9,9 @@ module Salmon delegate :sig, :data_type, :to => :magic_sig + # @param user [User] + # @param activity [String] A decoded string + # @return [Slap] def self.create_by_user_and_activity(user, activity) salmon = self.new salmon.author = user.person diff --git a/spec/lib/hydra_wrapper_spec.rb b/spec/lib/hydra_wrapper_spec.rb index 00e160f22..45184e827 100644 --- a/spec/lib/hydra_wrapper_spec.rb +++ b/spec/lib/hydra_wrapper_spec.rb @@ -6,7 +6,7 @@ require 'hydra_wrapper' describe HydraWrapper do before do - @wrapper = HydraWrapper.new(stub, [stub, stub, stub], stub, stub) + @wrapper = HydraWrapper.new(stub, [stub, stub, stub], "", stub) end describe 'initialize' do @@ -33,7 +33,9 @@ describe HydraWrapper do describe '#salmon' do it 'calls the salmon method on the dispatcher class (and memoizes)' do - @wrapper.dispatcher_class.should_receive(:salmon).once.and_return(true) + Base64.stub(:decode64).and_return(@wrapper.encoded_object_xml + 'decoded') + decoded = Base64.decode64(@wrapper.encoded_object_xml) + @wrapper.dispatcher_class.should_receive(:salmon).with(@wrapper.user, decoded).once.and_return(true) @wrapper.salmon @wrapper.salmon end @@ -55,6 +57,7 @@ describe HydraWrapper do end it 'inserts a job for every group of people' do + Base64.stub(:decode64) @wrapper.dispatcher_class = stub(:salmon => stub(:xml_for => "")) @wrapper.stub(:grouped_people).and_return({'https://foo.com' => @wrapper.people}) @wrapper.people.should_receive(:first).once @@ -63,6 +66,7 @@ describe HydraWrapper do end it 'does not insert a job for a person whos xml returns false' do + Base64.stub(:decode64) @wrapper.stub(:grouped_people).and_return({'https://foo.com' => [stub]}) @wrapper.dispatcher_class = stub(:salmon => stub(:xml_for => false)) @wrapper.should_not_receive(:insert_job) diff --git a/spec/models/job/receive_salmon_spec.rb b/spec/models/job/receive_salmon_spec.rb index d3e1d6c94..523fefbe2 100644 --- a/spec/models/job/receive_salmon_spec.rb +++ b/spec/models/job/receive_salmon_spec.rb @@ -13,10 +13,11 @@ describe Job::ReceiveSalmon do } end it 'calls receive_salmon' do - salmon_mock = mock() + zord = mock + + zord.should_receive(:perform) + Postzord::Receiver::Private.should_receive(:new).with(@user, hash_including(:salmon_xml => @xml)).and_return(zord) - salmon_mock.should_receive(:perform) - Postzord::Receiver.should_receive(:new).and_return(salmon_mock) Job::ReceiveSalmon.perform(@user.id, @xml) end end