aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorJeremy Daer <jeremydaer@gmail.com>2015-10-03 19:14:37 -0700
committerJeremy Daer <jeremydaer@gmail.com>2015-10-03 21:59:18 -0700
commit2356403330f2fa60045c858434cad550f6b3ee46 (patch)
treea82b9781bd1c2efb85252e376fa9d27fc94d1f29 /actionpack/test
parent24b1850130c68fe70b912277527e9c139ccc6742 (diff)
downloadrails-2356403330f2fa60045c858434cad550f6b3ee46.tar.gz
rails-2356403330f2fa60045c858434cad550f6b3ee46.tar.bz2
rails-2356403330f2fa60045c858434cad550f6b3ee46.zip
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.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/dispatch/header_test.rb18
-rw-r--r--actionpack/test/dispatch/response_test.rb20
2 files changed, 28 insertions, 10 deletions
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