Ticket #10974: head_should_return_empty_body.diff
| File head_should_return_empty_body.diff, 5.1 kB (added by wzph, 10 months ago) |
|---|
-
test/controller/render_test.rb
old new 72 72 def render_nothing_with_appendix 73 73 render :text => "appended" 74 74 end 75 76 def render_nothing 77 render :nothing => true 78 end 75 79 76 80 def render_invalid_args 77 81 render("test/hello") … … 95 99 render :text => line 96 100 end 97 101 102 def render_empty_body 103 render :empty_body => true 104 end 105 98 106 def heading 99 107 head :ok 100 108 end 101 109 110 def heading_with_301 111 head 301 112 end 113 102 114 def greeting 103 115 # let's just rely on the template 104 116 end … … 312 324 assert_response 200 313 325 assert_equal 'appended', @response.body 314 326 end 315 327 328 def test_render_empty_body 329 get :render_empty_body 330 assert_response 200 331 assert_equal '', @response.body 332 end 333 334 def test_head_responses_should_have_empty_bodies 335 head :heading 336 assert_equal '', @response.body 337 end 338 339 def test_head_responses_should_return_200s_by_default 340 head :heading 341 assert_response 200 342 end 343 344 def test_head_responses_can_have_other_status_codes 345 head :heading_with_301 346 assert_response 301 347 end 348 316 349 def test_attempt_to_render_with_invalid_arguments 317 350 assert_raises(ActionController::RenderError) { get :render_invalid_args } 318 351 end -
test/controller/rescue_test.rb
old new 198 198 end 199 199 200 200 assert_response :internal_server_error 201 assert_equal ' ', @response.body201 assert_equal '', @response.body 202 202 end 203 203 204 204 def test_rescue_unknown_action_in_public_with_error_file … … 221 221 end 222 222 223 223 assert_response :not_found 224 assert_equal ' ', @response.body224 assert_equal '', @response.body 225 225 end 226 226 227 227 def test_rescue_missing_template_in_public -
test/controller/filters_test.rb
old new 823 823 def test_first_filter_in_multiple_before_filter_chain_halts 824 824 controller = ::FilterTest::TestMultipleFiltersController.new 825 825 response = test_process(controller, 'fail_1') 826 assert_equal ' ', response.body826 assert_equal '', response.body 827 827 assert_equal 1, controller.instance_variable_get(:@try) 828 828 assert controller.instance_variable_get(:@before_filter_chain_aborted) 829 829 end … … 831 831 def test_second_filter_in_multiple_before_filter_chain_halts 832 832 controller = ::FilterTest::TestMultipleFiltersController.new 833 833 response = test_process(controller, 'fail_2') 834 assert_equal ' ', response.body834 assert_equal '', response.body 835 835 assert_equal 2, controller.instance_variable_get(:@try) 836 836 assert controller.instance_variable_get(:@before_filter_chain_aborted) 837 837 end … … 839 839 def test_last_filter_in_multiple_before_filter_chain_halts 840 840 controller = ::FilterTest::TestMultipleFiltersController.new 841 841 response = test_process(controller, 'fail_3') 842 assert_equal ' ', response.body842 assert_equal '', response.body 843 843 assert_equal 3, controller.instance_variable_get(:@try) 844 844 assert controller.instance_variable_get(:@before_filter_chain_aborted) 845 845 end -
lib/action_controller/base.rb
old new 913 913 elsif options[:nothing] 914 914 # Safari doesn't pass the headers of the return if the response is zero length 915 915 render_for_text(" ", options[:status]) 916 916 elsif options[:empty_body] 917 # Absolutely nothing in the body--sorry, Safari! 918 # To be safe, this should probably only be used for 919 # HEAD requests. 920 render_for_text(nil, options[:status]) 917 921 else 918 922 render_for_file(default_template_name, options[:status], true) 919 923 end … … 954 958 options.each do |key, value| 955 959 headers[key.to_s.dasherize.split(/-/).map { |v| v.capitalize }.join("-")] = value.to_s 956 960 end 957 958 render : nothing=> true, :status => status961 962 render :empty_body => true, :status => status 959 963 end 960 964 961 965 -
lib/action_controller/layout.rb
old new 273 273 274 274 def candidate_for_layout?(options) 275 275 (options.has_key?(:layout) && options[:layout] != false) || 276 options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing ).compact.empty? &&276 options.values_at(:text, :xml, :json, :file, :inline, :partial, :nothing, :empty_body).compact.empty? && 277 277 !template_exempt_from_layout?(options[:template] || default_template_name(options[:action])) 278 278 end 279 279