aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/header_test.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-03-13 18:05:01 +0100
committerYves Senn <yves.senn@gmail.com>2013-03-15 10:13:49 +0100
commit41a14dcd1045f61278237f34f065b87212689376 (patch)
tree0f7aafb34684d6ebf78e30b74f310a57b5a6fec1 /actionpack/test/dispatch/header_test.rb
parentc1003d99b00b3afb5417b6853a3e2ba92638cbe8 (diff)
downloadrails-41a14dcd1045f61278237f34f065b87212689376.tar.gz
rails-41a14dcd1045f61278237f34f065b87212689376.tar.bz2
rails-41a14dcd1045f61278237f34f065b87212689376.zip
`Http::Headers` directly modifies the passed environment.
The env hash passed to `Http::Headers#new` must be in env format. Also be aware that the passed hash is modified directly. docs and test-cases for setting headers/env in functional tests. Follow up to #9700.
Diffstat (limited to 'actionpack/test/dispatch/header_test.rb')
-rw-r--r--actionpack/test/dispatch/header_test.rb22
1 files changed, 16 insertions, 6 deletions
diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb
index 3bb3b3db23..9e37b96951 100644
--- a/actionpack/test/dispatch/header_test.rb
+++ b/actionpack/test/dispatch/header_test.rb
@@ -8,15 +8,15 @@ class HeaderTest < ActiveSupport::TestCase
)
end
- test "#new with mixed headers and env" do
+ test "#new does not normalize the data" do
headers = ActionDispatch::Http::Headers.new(
"Content-Type" => "application/json",
"HTTP_REFERER" => "/some/page",
"Host" => "http://test.com")
- assert_equal({"CONTENT_TYPE" => "application/json",
+ assert_equal({"Content-Type" => "application/json",
"HTTP_REFERER" => "/some/page",
- "HTTP_HOST" => "http://test.com"}, headers.env)
+ "Host" => "http://test.com"}, headers.env)
end
test "#env returns the headers as env variables" do
@@ -117,11 +117,21 @@ class HeaderTest < ActiveSupport::TestCase
end
test "symbols are treated as strings" do
- headers = ActionDispatch::Http::Headers.new(:SERVER_NAME => "example.com",
- "HTTP_REFERER" => "/",
- :Host => "test.com")
+ headers = ActionDispatch::Http::Headers.new
+ headers.merge!(:SERVER_NAME => "example.com",
+ "HTTP_REFERER" => "/",
+ :Host => "test.com")
assert_equal "example.com", headers["SERVER_NAME"]
assert_equal "/", headers[:HTTP_REFERER]
assert_equal "test.com", headers["HTTP_HOST"]
end
+
+ test "headers directly modifies the passed environment" do
+ env = {"HTTP_REFERER" => "/"}
+ headers = ActionDispatch::Http::Headers.new(env)
+ headers['Referer'] = "http://example.com/"
+ headers.merge! "CONTENT_TYPE" => "text/plain"
+ assert_equal({"HTTP_REFERER"=>"http://example.com/",
+ "CONTENT_TYPE"=>"text/plain"}, env)
+ end
end