aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/dispatch/header_test.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2013-03-13 12:25:32 +0100
committerYves Senn <yves.senn@gmail.com>2013-03-13 16:41:00 +0100
commit9af59b2468e4ad6c3c2ca89f90968fdcaa417aba (patch)
tree5102f6c010fd469fda0f7ed3161c6f4b6155c113 /actionpack/test/dispatch/header_test.rb
parente2a5de2bb200773943e605cdddb9b18bbfa77e13 (diff)
downloadrails-9af59b2468e4ad6c3c2ca89f90968fdcaa417aba.tar.gz
rails-9af59b2468e4ad6c3c2ca89f90968fdcaa417aba.tar.bz2
rails-9af59b2468e4ad6c3c2ca89f90968fdcaa417aba.zip
allow headers and env to be passed in `IntegrationTest`.
Closes #6513.
Diffstat (limited to 'actionpack/test/dispatch/header_test.rb')
-rw-r--r--actionpack/test/dispatch/header_test.rb45
1 files changed, 44 insertions, 1 deletions
diff --git a/actionpack/test/dispatch/header_test.rb b/actionpack/test/dispatch/header_test.rb
index 9f92c3791e..0bfc18b4ed 100644
--- a/actionpack/test/dispatch/header_test.rb
+++ b/actionpack/test/dispatch/header_test.rb
@@ -8,7 +8,23 @@ class HeaderTest < ActiveSupport::TestCase
)
end
- test "each" do
+ test "#new with mixed headers and env" do
+ headers = ActionDispatch::Http::Headers.new(
+ "Content-Type" => "application/json",
+ "HTTP_REFERER" => "/some/page",
+ "Host" => "http://test.com")
+
+ assert_equal({"CONTENT_TYPE" => "application/json",
+ "HTTP_REFERER" => "/some/page",
+ "HTTP_HOST" => "http://test.com"}, headers.env)
+ end
+
+ test "#env returns the headers as env variables" do
+ assert_equal({"CONTENT_TYPE" => "text/plain",
+ "HTTP_REFERER" => "/some/page"}, @headers.env)
+ end
+
+ test "#each iterates through the env variables" do
headers = []
@headers.each { |pair| headers << pair }
assert_equal [["CONTENT_TYPE", "text/plain"],
@@ -54,4 +70,31 @@ class HeaderTest < ActiveSupport::TestCase
assert_equal "text/plain", @headers.fetch("content-type", nil)
assert_equal "not found", @headers.fetch("not-found", "not found")
end
+
+ test "#merge! headers with mutation" do
+ @headers.merge!("Host" => "http://example.test",
+ "Content-Type" => "text/html")
+ assert_equal({"HTTP_HOST" => "http://example.test",
+ "CONTENT_TYPE" => "text/html",
+ "HTTP_REFERER" => "/some/page"}, @headers.env)
+ end
+
+ test "#merge! env with mutation" do
+ @headers.merge!("HTTP_HOST" => "http://first.com",
+ "CONTENT_TYPE" => "text/html")
+ assert_equal({"HTTP_HOST" => "http://first.com",
+ "CONTENT_TYPE" => "text/html",
+ "HTTP_REFERER" => "/some/page"}, @headers.env)
+ end
+
+ test "merge without mutation" do
+ combined = @headers.merge("HTTP_HOST" => "http://example.com",
+ "CONTENT_TYPE" => "text/html")
+ assert_equal({"HTTP_HOST" => "http://example.com",
+ "CONTENT_TYPE" => "text/html",
+ "HTTP_REFERER" => "/some/page"}, combined.env)
+
+ assert_equal({"CONTENT_TYPE" => "text/plain",
+ "HTTP_REFERER" => "/some/page"}, @headers.env)
+ end
end