Skip to content

Commit

Permalink
Merge remote branch 'myronmarston/multiple_response_headers'
Browse files Browse the repository at this point in the history
* myronmarston/multiple_response_headers:
  Ensure multiple values for the same response header gets returned from #get_fields as an array of values, rather than an array-of-an-array of values.
  • Loading branch information
chrisk committed Aug 15, 2010
2 parents 13cc551 + eb61621 commit 058b122
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/fake_web/responder.rb
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions test/test_response_headers.rb
Expand Up @@ -29,6 +29,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)"
Expand Down

0 comments on commit 058b122

Please sign in to comment.