aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib
diff options
context:
space:
mode:
authorJosh Bassett <josh.bassett@gmail.com>2011-01-18 19:21:16 +1100
committerSantiago Pastorino <santiago@wyeworks.com>2011-02-09 19:25:53 -0200
commit056be15212a8645d17534f993c1e89bd2dcf7df9 (patch)
treefedf74cb130c48e99f09942bd9bfa838f156bde0 /activeresource/lib
parentad31549ab3044afc336c05243481c0f663689584 (diff)
downloadrails-056be15212a8645d17534f993c1e89bd2dcf7df9.tar.gz
rails-056be15212a8645d17534f993c1e89bd2dcf7df9.tar.bz2
rails-056be15212a8645d17534f993c1e89bd2dcf7df9.zip
Fixed a bug where ActiveResource::HttpMock would not replace an existing response when passing a block to the respond_to method.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
Diffstat (limited to 'activeresource/lib')
-rw-r--r--activeresource/lib/active_resource/http_mock.rb17
1 files changed, 14 insertions, 3 deletions
diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb
index 9aefde7c30..75649053d0 100644
--- a/activeresource/lib/active_resource/http_mock.rb
+++ b/activeresource/lib/active_resource/http_mock.rb
@@ -60,10 +60,21 @@ module ActiveResource
# end
module_eval <<-EOE, __FILE__, __LINE__ + 1
def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {})
- @responses << [Request.new(:#{method}, path, nil, request_headers), Response.new(body || "", status, response_headers)]
+ request = Request.new(:#{method}, path, nil, request_headers)
+ response = Response.new(body || "", status, response_headers)
+
+ delete_duplicate_responses(request)
+
+ @responses << [request, response]
end
EOE
end
+
+ private
+
+ def delete_duplicate_responses(request)
+ @responses.delete_if {|r| r[0] == request }
+ end
end
class << self
@@ -181,11 +192,11 @@ module ActiveResource
pairs = args.first || {}
reset! if args.last.class != FalseClass
- delete_responses_to_replace pairs.to_a
- responses.concat pairs.to_a
if block_given?
yield Responder.new(responses)
else
+ delete_responses_to_replace pairs.to_a
+ responses.concat pairs.to_a
Responder.new(responses)
end
end