From c19fbaeb3d76701384eba954a1edd1aaa4370ce4 Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Wed, 15 Oct 2008 18:31:38 -0500 Subject: [PATCH] Added test for ARes::Connection#build_request_headers --- activeresource/test/connection_test.rb | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb index 84bcf69..64f97f0 100644 --- a/activeresource/test/connection_test.rb +++ b/activeresource/test/connection_test.rb @@ -184,6 +184,11 @@ class ConnectionTest < Test::Unit::TestCase assert_nothing_raised(Mocha::ExpectationError) { @conn.get(path, {'Accept' => 'application/xhtml+xml'}) } end end + + def test_build_request_headers + headers = @conn.send(:build_request_headers, {}) + assert(!headers.include?(nil)) + end protected def assert_response_raises(klass, code) -- 1.5.5 From 57972e2e328b7dc9669f6025d7e18b325f8be5f0 Mon Sep 17 00:00:00 2001 From: Elliot Winkler Date: Thu, 16 Oct 2008 08:45:44 -0500 Subject: [PATCH] Patched ActiveResource::Connection#http_format_header so that if given http_method is nil (which happens when sending a HEAD request), it returns an empty hash instead of one with a nil key. --- activeresource/lib/active_resource/connection.rb | 2 +- activeresource/test/connection_test.rb | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb index 273fee3..4a29a71 100644 --- a/activeresource/lib/active_resource/connection.rb +++ b/activeresource/lib/active_resource/connection.rb @@ -208,7 +208,7 @@ module ActiveResource end def http_format_header(http_method) - {HTTP_FORMAT_HEADER_NAMES[http_method] => format.mime_type} + HTTP_FORMAT_HEADER_NAMES.include?(http_method) ? { HTTP_FORMAT_HEADER_NAMES[http_method] => format.mime_type } : {} end def logger #:nodoc: diff --git a/activeresource/test/connection_test.rb b/activeresource/test/connection_test.rb index 64f97f0..9067167 100644 --- a/activeresource/test/connection_test.rb +++ b/activeresource/test/connection_test.rb @@ -185,10 +185,14 @@ class ConnectionTest < Test::Unit::TestCase end end - def test_build_request_headers - headers = @conn.send(:build_request_headers, {}) + def test_http_format_header_when_http_method_not_nil + headers = @conn.send(:http_format_header, :get) assert(!headers.include?(nil)) end + def test_http_format_header_when_http_method_nil + headers = @conn.send(:http_format_header, nil) + assert headers.empty? + end protected def assert_response_raises(klass, code) -- 1.5.5