From 2356403330f2fa60045c858434cad550f6b3ee46 Mon Sep 17 00:00:00 2001 From: Jeremy Daer Date: Sat, 3 Oct 2015 19:14:37 -0700 Subject: Introduce `Headers#add`. Move `Response#add_header` upstream. * Introduce `ActionDispatch::Http::Headers#add` to add a value to a multivalued header. * Move `Response#add_header` upstream: https://github.com/rack/rack/pull/957 * Match upstream `Response#have_header?` -> `#has_header?` name change. --- actionpack/test/dispatch/header_test.rb | 18 ++++++++++++++++++ actionpack/test/dispatch/response_test.rb | 20 ++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) (limited to 'actionpack/test/dispatch') diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb index 79600b654b..7f1ef121b7 100644 --- a/actionpack/test/dispatch/header_test.rb +++ b/actionpack/test/dispatch/header_test.rb @@ -42,6 +42,24 @@ class HeaderTest < ActiveSupport::TestCase assert_equal "127.0.0.1", @headers["HTTP_HOST"] end + test "add to multivalued headers" do + # Sets header when not present + @headers.add 'Foo', '1' + assert_equal '1', @headers['Foo'] + + # Ignores nil values + @headers.add 'Foo', nil + assert_equal '1', @headers['Foo'] + + # Converts value to string + @headers.add 'Foo', 1 + assert_equal '1,1', @headers['Foo'] + + # Case-insensitive + @headers.add 'fOo', 2 + assert_equal '1,1,2', @headers['foO'] + end + test "headers can contain numbers" do @headers["Content-MD5"] = "Q2hlY2sgSW50ZWdyaXR5IQ==" diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 82cc21b17a..2b2fea7504 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -299,10 +299,10 @@ class ResponseHeadersTest < ActiveSupport::TestCase @response.set_header 'Foo', '1' end - test 'have_header?' do - assert @response.have_header? 'Foo' - assert_not @response.have_header? 'foo' - assert_not @response.have_header? nil + test 'has_header?' do + assert @response.has_header? 'Foo' + assert_not @response.has_header? 'foo' + assert_not @response.has_header? nil end test 'get_header' do @@ -313,11 +313,11 @@ class ResponseHeadersTest < ActiveSupport::TestCase test 'set_header' do assert_equal '2', @response.set_header('Foo', '2') - assert @response.have_header?('Foo') + assert @response.has_header?('Foo') assert_equal '2', @response.get_header('Foo') assert_nil @response.set_header('Foo', nil) - assert @response.have_header?('Foo') + assert @response.has_header?('Foo') assert_nil @response.get_header('Foo') end @@ -325,10 +325,10 @@ class ResponseHeadersTest < ActiveSupport::TestCase assert_nil @response.delete_header(nil) assert_nil @response.delete_header('foo') - assert @response.have_header?('Foo') + assert @response.has_header?('Foo') assert_equal '1', @response.delete_header('Foo') - assert_not @response.have_header?('Foo') + assert_not @response.has_header?('Foo') end test 'add_header' do @@ -342,12 +342,12 @@ class ResponseHeadersTest < ActiveSupport::TestCase # Add nil to a nonexistent header assert_nil @response.add_header('Bar', nil) - assert_not @response.have_header?('Bar') + assert_not @response.has_header?('Bar') assert_nil @response.get_header('Bar') # Add a value to a nonexistent header assert_equal '1', @response.add_header('Bar', '1') - assert @response.have_header?('Bar') + assert @response.has_header?('Bar') assert_equal '1', @response.get_header('Bar') end end -- cgit v1.2.3