From 995996add101fb2f172cc92890f552618b8c44c3 Mon Sep 17 00:00:00 2001 From: danielgrippi Date: Wed, 2 Nov 2011 15:00:30 -0700 Subject: [PATCH] add spec & change syntax in http_multi --- app/models/jobs/http_multi.rb | 6 ++---- spec/models/jobs/http_multi_spec.rb | 13 ++++++++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/models/jobs/http_multi.rb b/app/models/jobs/http_multi.rb index a17d5cce0..d573f19b6 100644 --- a/app/models/jobs/http_multi.rb +++ b/app/models/jobs/http_multi.rb @@ -25,7 +25,6 @@ module Jobs [user_id, encoded_object_xml, @failed_people, dispatcher_class_as_string] end - def self.perform(user_id, encoded_object_xml, person_ids, dispatcher_class_as_string) user = User.find(user_id) people = Person.where(:id => person_ids) @@ -36,9 +35,9 @@ module Jobs hydra.enqueue_batch hydra.run - @failed_people = hydra.failed_people + @failed_people = hydra.failed_people - if not @failed_people.empty? + unless @failed_people.empty? if self.retry_limit_reached? msg = "event=http_multi_abandon sender_id=#{user_id} failed_recipient_ids='[#{@failed_people.join(', ')}]'" Rails.logger.info(msg) @@ -47,6 +46,5 @@ module Jobs end end end - end end diff --git a/spec/models/jobs/http_multi_spec.rb b/spec/models/jobs/http_multi_spec.rb index 07915b4ab..a9c0acb0d 100644 --- a/spec/models/jobs/http_multi_spec.rb +++ b/spec/models/jobs/http_multi_spec.rb @@ -28,7 +28,18 @@ describe Jobs::HttpMulti do Typhoeus::Hydra.stub!(:new).and_return(@hydra) people_ids = @people.map{ |p| p.id } - Jobs::HttpMulti.perform(bob.id, @post_xml, people_ids, "Postzord::Dispatcher::Private") + lambda { + Jobs::HttpMulti.perform(bob.id, @post_xml, people_ids, "Postzord::Dispatcher::Private") + }.should_not raise_error + end + + it 'retries' do + person = @people[0] + @hydra.stub(:post, person.receive_url).and_return(@failed_response) + Typhoeus::Hydra.stub!(:new).and_return(@hydra) + lambda { + Jobs::HttpMulti.perform(bob.id, @post_xml, [person.id], "Postzord::Dispatcher::Private") + }.should raise_error /retry/ end it 'generates encrypted xml for people' do