aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib/active_resource/http_mock.rb
diff options
context:
space:
mode:
authorElomar França <elomar@maisweb.org>2010-06-22 19:50:15 -0300
committerJosé Valim <jose.valim@gmail.com>2010-06-24 13:25:10 +0200
commit176c386409fd57bc03b9ebf1570a8955e21e0800 (patch)
tree91294edbc0a2c9059f447885994a101c10c26e91 /activeresource/lib/active_resource/http_mock.rb
parent6788db824ab732b13493a9d702dd8fb89fa153c8 (diff)
downloadrails-176c386409fd57bc03b9ebf1570a8955e21e0800.tar.gz
rails-176c386409fd57bc03b9ebf1570a8955e21e0800.tar.bz2
rails-176c386409fd57bc03b9ebf1570a8955e21e0800.zip
Fix bug where ActiveResource::HttpMock would overwrite Accept/Content-Type header to application/xml [#4939 state:resolved]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activeresource/lib/active_resource/http_mock.rb')
-rw-r--r--activeresource/lib/active_resource/http_mock.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/activeresource/lib/active_resource/http_mock.rb b/activeresource/lib/active_resource/http_mock.rb
index 1ed3804017..f192c53b4f 100644
--- a/activeresource/lib/active_resource/http_mock.rb
+++ b/activeresource/lib/active_resource/http_mock.rb
@@ -148,16 +148,28 @@ module ActiveResource
attr_accessor :path, :method, :body, :headers
def initialize(method, path, body = nil, headers = {})
- @method, @path, @body, @headers = method, path, body, headers.merge(ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[method] => 'application/xml')
+ @method, @path, @body, @headers = method, path, body, headers
end
def ==(req)
- path == req.path && method == req.method && headers == req.headers
+ path == req.path && method == req.method && headers_match?(req)
end
def to_s
"<#{method.to_s.upcase}: #{path} [#{headers}] (#{body})>"
end
+
+ private
+
+ def headers_match?(req)
+ # Ignore format header on equality if it's not defined
+ format_header = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[method]
+ if headers[format_header].present? || req.headers[format_header].blank?
+ headers == req.headers
+ else
+ headers.dup.merge(format_header => req.headers[format_header]) == req.headers
+ end
+ end
end
class Response