diff options
-rw-r--r-- | app/models/jobs/http_multi.rb | 6 | ||||
-rw-r--r-- | spec/models/jobs/http_multi_spec.rb | 6 | ||||
-rw-r--r-- | spec/spec_helper.rb | 1 | ||||
-rw-r--r-- | spec/support/fake_typhoeus.rb | 22 | ||||
-rw-r--r-- | spec/support/stub_hydra.rb | 11 |
5 files changed, 33 insertions, 13 deletions
diff --git a/app/models/jobs/http_multi.rb b/app/models/jobs/http_multi.rb index 814645c1e..ada0f4a78 100644 --- a/app/models/jobs/http_multi.rb +++ b/app/models/jobs/http_multi.rb @@ -8,6 +8,8 @@ module Job class HttpMulti < Base @queue = :http + Hydra = Typhoeus::Hydra + Request = Typhoeus::Request MAX_RETRIES = 3 OPTS = {:max_redirects => 3, :timeout => 5000, :method => :post} @@ -19,13 +21,13 @@ module Job failed_request_people = [] - hydra = Typhoeus::Hydra.new + hydra = Hydra.new people.each do |person| url = person.receive_url xml = salmon.xml_for(person) - request = Typhoeus::Request.new(url, OPTS.merge(:params => {:xml => CGI::escape(xml)})) + request = Request.new(url, OPTS.merge(:params => {:xml => CGI::escape(xml)})) request.on_complete do |response| if response.code >= 300 && response.code < 400 diff --git a/spec/models/jobs/http_multi_spec.rb b/spec/models/jobs/http_multi_spec.rb index be04806be..b209aa524 100644 --- a/spec/models/jobs/http_multi_spec.rb +++ b/spec/models/jobs/http_multi_spec.rb @@ -1,6 +1,12 @@ require 'spec_helper' describe Job::HttpMulti do + before :all do + enable_typhoeus + end + after :all do + disable_typhoeus + end before do @people = [Factory(:person), Factory(:person)] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 176e2522d..7d093669d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -42,6 +42,7 @@ RSpec.configure do |config| end end +disable_typhoeus ProcessedImage.enable_processing = false def set_up_friends diff --git a/spec/support/fake_typhoeus.rb b/spec/support/fake_typhoeus.rb new file mode 100644 index 000000000..57b0d376f --- /dev/null +++ b/spec/support/fake_typhoeus.rb @@ -0,0 +1,22 @@ +class FakeHydra + def queue(*args); end + def run; end +end + +class FakeHydraRequest + def initialize(*args); end + def on_complete; end +end + +def disable_typhoeus + silence_warnings do + Job::HttpMulti.const_set('Hydra', FakeHydra) + Job::HttpMulti.const_set('Request', FakeHydraRequest) + end +end +def enable_typhoeus + silence_warnings do + Job::HttpMulti.const_set('Hydra', Typhoeus::Hydra) + Job::HttpMulti.const_set('Request', Typhoeus::Request) + end +end diff --git a/spec/support/stub_hydra.rb b/spec/support/stub_hydra.rb deleted file mode 100644 index e9d70861f..000000000 --- a/spec/support/stub_hydra.rb +++ /dev/null @@ -1,11 +0,0 @@ -#class Typhoeus::Hydra -# def initialize -# end - -# def queue(*args) -# end - -# def run -# end -#end - |