From b2ede64a89a5837a047e75f21a1522324a614514 Mon Sep 17 00:00:00 2001 From: Jamis Buck Date: Thu, 28 Sep 2006 19:13:55 +0000 Subject: Add ActionController::Base#head for rendering empty responses. Add support for symbolic status codes, as well as for having raw integer statuses expand with their default messages. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5199 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/new_render_test.rb | 59 +++++++++++++++++++++++++++ actionpack/test/controller/send_file_test.rb | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb index 936e75d04f..5463df3c60 100644 --- a/actionpack/test/controller/new_render_test.rb +++ b/actionpack/test/controller/new_render_test.rb @@ -202,6 +202,26 @@ class NewRenderTestController < ActionController::Base render :template => "test/hello_world.rxml" end + def head_with_location_header + head :location => "/foo" + end + + def head_with_symbolic_status + head :status => params[:status].intern + end + + def head_with_integer_status + head :status => params[:status].to_i + end + + def head_with_string_status + head :status => params[:status] + end + + def head_with_custom_header + head :x_custom_header => "something" + end + helper NewRenderTestHelper helper do def rjs_helper_method(value) @@ -602,4 +622,43 @@ EOS get :hello_world_from_rxml_using_action assert_equal "\n

Hello

\n\n", @response.body end + + + def test_head_with_location_header + get :head_with_location_header + assert @response.body.blank? + assert_equal "/foo", @response.headers["Location"] + end + + def test_head_with_custom_header + get :head_with_custom_header + assert @response.body.blank? + assert_equal "something", @response.headers["X-Custom-Header"] + end + + def test_head_with_symbolic_status + get :head_with_symbolic_status, :status => "ok" + assert_equal "200 OK", @response.headers["Status"] + + get :head_with_symbolic_status, :status => "not_found" + assert_equal "404 Not Found", @response.headers["Status"] + + ActionController::StatusCodes::SYMBOL_TO_STATUS_CODE.each do |status, code| + get :head_with_symbolic_status, :status => status.to_s + assert_equal code, @response.response_code + end + end + + def test_head_with_integer_status + ActionController::StatusCodes::STATUS_CODES.each do |code, message| + get :head_with_integer_status, :status => code.to_s + assert_equal message, @response.message + end + end + + def head_with_string_status + get :head_with_string_status, :status => "404 Eat Dirt" + assert_equal 404, @response.response_code + assert_equal "Eat Dirt", @response.message + end end diff --git a/actionpack/test/controller/send_file_test.rb b/actionpack/test/controller/send_file_test.rb index 4c97e2d5d2..a4617cbf5a 100644 --- a/actionpack/test/controller/send_file_test.rb +++ b/actionpack/test/controller/send_file_test.rb @@ -97,7 +97,7 @@ class SendFileTest < Test::Unit::TestCase define_method "test_send_#{method}_status" do @controller.options = { :stream => false, :status => 500 } assert_nothing_raised { assert_not_nil process(method) } - assert_equal '500', @controller.headers['Status'] + assert_equal '500 Internal Server Error', @controller.headers['Status'] end define_method "test_default_send_#{method}_status" do -- cgit v1.2.3