From 7af12d04cebe3a1ffcf55cae967d22fc7b0606c8 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 12 Mar 2006 06:02:44 +0000 Subject: Added synonym and custom type handling to respond_to [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3844 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/test/controller/mime_responds_test.rb | 28 ++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'actionpack/test') diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 184110aad1..1470fa9899 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -56,6 +56,14 @@ class RespondToController < ActionController::Base end end + def custom_type_handling + respond_to do |type| + type.html { render :text => "HTML" } + type.custom("application/crazy-xml") { render :text => "Crazy XML" } + type.all { render :text => "Nothing" } + end + end + def rescue_action(e) raise unless ActionController::MissingTemplate === e end @@ -155,4 +163,24 @@ class MimeControllerTest < Test::Unit::TestCase get :made_for_content_type assert_equal "RSS", @response.body end + + def test_synonyms + @request.env["HTTP_ACCEPT"] = "application/javascript" + get :js_or_html + assert_equal 'JS', @response.body + + @request.env["HTTP_ACCEPT"] = "application/x-xml" + get :using_argument_defaults + assert_equal "\n\n David\n\n", @response.body + end + + def test_custom_types + @request.env["HTTP_ACCEPT"] = "application/crazy-xml" + get :custom_type_handling + assert_equal 'Crazy XML', @response.body + + @request.env["HTTP_ACCEPT"] = "text/html" + get :custom_type_handling + assert_equal 'HTML', @response.body + end end \ No newline at end of file -- cgit v1.2.3