From 9af59b2468e4ad6c3c2ca89f90968fdcaa417aba Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Wed, 13 Mar 2013 12:25:32 +0100 Subject: allow headers and env to be passed in `IntegrationTest`. Closes #6513. --- actionpack/test/dispatch/header_test.rb | 45 ++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'actionpack/test/dispatch/header_test.rb') 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 -- cgit v1.2.3