Browse files

Ensure multiple values for the same response header gets returned fro…

…m #get_fields as an array of values, rather than an array-of-an-array of values.
  • Loading branch information...
1 parent fcf7e1f commit eb61621c0c58f56603f2e37f571f82db3ec336d0 @myronmarston myronmarston committed Aug 3, 2010
Showing with 14 additions and 1 deletion.
  1. +7 −1 lib/fake_web/responder.rb
  2. +7 −0 test/test_response_headers.rb
View
8 lib/fake_web/responder.rb
@@ -23,7 +23,13 @@ def response(&block)
code, msg = meta_information
response = Net::HTTPResponse.send(:response_class, code.to_s).new("1.0", code.to_s, msg)
response.instance_variable_set(:@body, body)
- headers_extracted_from_options.each { |name, value| response[name] = value }
+ headers_extracted_from_options.each do |name, value|
+ if value.respond_to?(:each)
+ value.each { |v| response.add_field(name, v) }
+ else
+ response[name] = value
+ end
+ end
end
response.instance_variable_set(:@read, true)
View
7 test/test_response_headers.rb
@@ -30,6 +30,13 @@ def test_cookies_when_registering_with_file_and_set_cookie_header
assert_equal "user_id=1; example=yes", response['Set-Cookie']
end
+ def test_multiple_set_cookie_headers
+ FakeWeb.register_uri(:get, "http://example.com/with_two_cookies", :body => 'body',
+ :set_cookie => ["user_id=2", "example=yes"])
+ response = Net::HTTP.start("example.com") { |query| query.get("/with_two_cookies") }
+ assert_equal ["user_id=2", "example=yes"], response.get_fields('Set-Cookie')
+ end
+
def test_registering_with_baked_response_ignores_header_options
fake_response = Net::HTTPOK.new('1.1', '200', 'OK')
fake_response["Server"] = "Apache/1.3.27 (Unix)"

0 comments on commit eb61621

Please sign in to comment.