From 737e6084df4faa4795352e5a5008d6daf5e1172d Mon Sep 17 00:00:00 2001 From: danielvincent Date: Sun, 5 Dec 2010 01:53:36 -0800 Subject: [PATCH] actually setting the timeout in restclient --- app/models/jobs/http_post.rb | 3 ++- spec/models/jobs/http_post_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/jobs/http_post.rb b/app/models/jobs/http_post.rb index cb9c3c115..cfe887f4a 100644 --- a/app/models/jobs/http_post.rb +++ b/app/models/jobs/http_post.rb @@ -3,7 +3,8 @@ module Jobs @queue = :http def self.perform(url, body, tries_remaining) begin - RestClient.post(url, :xml => body, :timeout => 4){ |response, request, result, &block| + request = RestClient::Request.new(url, :xml => body, :timeout => 4) + request.post { |response, request, result, &block| if [301, 302, 307].include? response.code response.follow_redirection(request, result, &block) else diff --git a/spec/models/jobs/http_post_spec.rb b/spec/models/jobs/http_post_spec.rb index 18461996b..bdb0c44dd 100644 --- a/spec/models/jobs/http_post_spec.rb +++ b/spec/models/jobs/http_post_spec.rb @@ -6,11 +6,11 @@ describe Jobs::HttpPost do @body = 'California' end it 'POSTs to a given URL' do - RestClient.should_receive(:post).with(@url, {:xml=>@body}).and_return(true) + RestClient::Request.should_receive(:new).with(@url, :xml=>@body, :timeout => 4) Jobs::HttpPost.perform(@url, @body, 3) end it 'retries' do - RestClient.should_receive(:post).with(@url, {:xml=>@body}).and_raise(SocketError) + RestClient::Request.should_receive(:new).with(@url, :xml=>@body, :timeout => 4) Resque.should_receive(:enqueue).with(Jobs::HttpPost, @url, @body, 1).once Jobs::HttpPost.perform(@url, @body, 2) end