@@ -293,6 +293,65 @@ def test_only_set_charset_still_defaults_to_text_html
293293 end
294294end
295295
296+ class ResponseHeadersTest < ActiveSupport ::TestCase
297+ def setup
298+ @response = ActionDispatch ::Response . create
299+ @response . set_header 'Foo' , '1'
300+ end
301+
302+ test 'have_header?' do
303+ assert @response . have_header? 'Foo'
304+ assert_not @response . have_header? 'foo'
305+ assert_not @response . have_header? nil
306+ end
307+
308+ test 'get_header' do
309+ assert_equal '1' , @response . get_header ( 'Foo' )
310+ assert_nil @response . get_header ( 'foo' )
311+ assert_nil @response . get_header ( nil )
312+ end
313+
314+ test 'set_header' do
315+ assert_equal '2' , @response . set_header ( 'Foo' , '2' )
316+ assert @response . have_header? ( 'Foo' )
317+ assert_equal '2' , @response . get_header ( 'Foo' )
318+
319+ assert_nil @response . set_header ( 'Foo' , nil )
320+ assert @response . have_header? ( 'Foo' )
321+ assert_nil @response . get_header ( 'Foo' )
322+ end
323+
324+ test 'delete_header' do
325+ assert_nil @response . delete_header ( nil )
326+
327+ assert_nil @response . delete_header ( 'foo' )
328+ assert @response . have_header? ( 'Foo' )
329+
330+ assert_equal '1' , @response . delete_header ( 'Foo' )
331+ assert_not @response . have_header? ( 'Foo' )
332+ end
333+
334+ test 'add_header' do
335+ # Add a value to an existing header
336+ assert_equal '1,2' , @response . add_header ( 'Foo' , '2' )
337+ assert_equal '1,2' , @response . get_header ( 'Foo' )
338+
339+ # Add nil to an existing header
340+ assert_equal '1,2' , @response . add_header ( 'Foo' , nil )
341+ assert_equal '1,2' , @response . get_header ( 'Foo' )
342+
343+ # Add nil to a nonexistent header
344+ assert_nil @response . add_header ( 'Bar' , nil )
345+ assert_not @response . have_header? ( 'Bar' )
346+ assert_nil @response . get_header ( 'Bar' )
347+
348+ # Add a value to a nonexistent header
349+ assert_equal '1' , @response . add_header ( 'Bar' , '1' )
350+ assert @response . have_header? ( 'Bar' )
351+ assert_equal '1' , @response . get_header ( 'Bar' )
352+ end
353+ end
354+
296355class ResponseIntegrationTest < ActionDispatch ::IntegrationTest
297356 test "response cache control from railsish app" do
298357 @app = lambda { |env |
0 commit comments