1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

set default_headers to nil after use it to avoid order dependent tests

This commit is contained in:
Francesco Rodriguez 2012-09-08 14:51:22 -05:00
parent 7b31a43085
commit 8cbd563edf

View file

@ -178,33 +178,40 @@ class ResponseTest < ActiveSupport::TestCase
end
test "read x_frame_options, x_content_type_options and x_xss_protection" do
ActionDispatch::Response.default_headers = {
'X-Frame-Options' => 'DENY',
'X-Content-Type-Options' => 'nosniff',
'X-XSS-Protection' => '1;'
}
resp = ActionDispatch::Response.new.tap { |response|
response.body = 'Hello'
}
resp.to_a
begin
ActionDispatch::Response.default_headers = {
'X-Frame-Options' => 'DENY',
'X-Content-Type-Options' => 'nosniff',
'X-XSS-Protection' => '1;'
}
resp = ActionDispatch::Response.new.tap { |response|
response.body = 'Hello'
}
resp.to_a
assert_equal('DENY', resp.headers['X-Frame-Options'])
assert_equal('nosniff', resp.headers['X-Content-Type-Options'])
assert_equal('1;', resp.headers['X-XSS-Protection'])
end
assert_equal('DENY', resp.headers['X-Frame-Options'])
assert_equal('nosniff', resp.headers['X-Content-Type-Options'])
assert_equal('1;', resp.headers['X-XSS-Protection'])
ensure
ActionDispatch::Response.default_headers = nil
end
end
test "read custom default_header" do
ActionDispatch::Response.default_headers = {
'X-XX-XXXX' => 'Here is my phone number'
}
resp = ActionDispatch::Response.new.tap { |response|
response.body = 'Hello'
}
resp.to_a
assert_equal('Here is my phone number', resp.headers['X-XX-XXXX'])
end
begin
ActionDispatch::Response.default_headers = {
'X-XX-XXXX' => 'Here is my phone number'
}
resp = ActionDispatch::Response.new.tap { |response|
response.body = 'Hello'
}
resp.to_a
assert_equal('Here is my phone number', resp.headers['X-XX-XXXX'])
ensure
ActionDispatch::Response.default_headers = nil
end
end
end
class ResponseIntegrationTest < ActionDispatch::IntegrationTest