2009-01-28 23:50:46 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
|
|
|
class HeaderTest < ActiveSupport::TestCase
|
|
|
|
def setup
|
|
|
|
@headers = ActionDispatch::Http::Headers.new(
|
|
|
|
"HTTP_CONTENT_TYPE" => "text/plain"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2012-10-18 18:20:30 -04:00
|
|
|
def test_each
|
|
|
|
headers = []
|
|
|
|
@headers.each { |pair| headers << pair }
|
|
|
|
assert_equal [["HTTP_CONTENT_TYPE", "text/plain"]], headers
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_setter
|
|
|
|
@headers['foo'] = "bar"
|
|
|
|
assert_equal "bar", @headers['foo']
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_key?
|
|
|
|
assert @headers.key?('HTTP_CONTENT_TYPE')
|
|
|
|
assert @headers.include?('HTTP_CONTENT_TYPE')
|
|
|
|
end
|
|
|
|
|
2012-10-18 18:22:58 -04:00
|
|
|
def test_fetch_with_block
|
|
|
|
assert_equal 'omg', @headers.fetch('notthere') { 'omg' }
|
|
|
|
end
|
|
|
|
|
2009-01-28 23:50:46 -05:00
|
|
|
test "content type" do
|
|
|
|
assert_equal "text/plain", @headers["Content-Type"]
|
|
|
|
assert_equal "text/plain", @headers["content-type"]
|
|
|
|
assert_equal "text/plain", @headers["CONTENT_TYPE"]
|
|
|
|
assert_equal "text/plain", @headers["HTTP_CONTENT_TYPE"]
|
|
|
|
end
|
2012-05-02 14:14:40 -04:00
|
|
|
|
|
|
|
test "fetch" do
|
|
|
|
assert_equal "text/plain", @headers.fetch("content-type", nil)
|
|
|
|
assert_equal "not found", @headers.fetch('not-found', 'not found')
|
|
|
|
end
|
2009-01-28 23:50:46 -05:00
|
|
|
end
|