From fa0cf663fe6a6393a3ba117505703e587da4ddc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 29 Jul 2009 14:32:56 +0200 Subject: Add a couple more tests to respond_with. Signed-off-by: Yehuda Katz --- actionpack/test/controller/mime_responds_test.rb | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'actionpack/test/controller') diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index 369d683d23..558fc47695 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -508,6 +508,12 @@ class RespondWithController < ActionController::Base end end + def default_overwritten + respond_to do |format| + format.html { render :text => "HTML" } + end + end + protected def _render_js(js, options) @@ -516,6 +522,17 @@ protected end end +class InheritedRespondWithController < RespondWithController + clear_respond_to + respond_to :xml, :json + + def index + respond_with(RespondResource.new) do |format| + format.json { render :text => "JSON" } + end + end +end + class RespondWithControllerTest < ActionController::TestCase tests RespondWithController @@ -590,6 +607,27 @@ class RespondWithControllerTest < ActionController::TestCase assert_equal "JS", @response.body end + def test_default_overwritten + get :default_overwritten + assert_equal "text/html", @response.content_type + assert_equal "HTML", @response.body + end + + def test_clear_respond_to + @controller = InheritedRespondWithController.new + @request.accept = "text/html" + get :index + assert_equal 406, @response.status + end + + def test_first_in_respond_to_has_higher_priority + @controller = InheritedRespondWithController.new + @request.accept = "*/*" + get :index + assert_equal "application/xml", @response.content_type + assert_equal "XML", @response.body + end + def test_not_acceptable @request.accept = "application/xml" get :using_defaults -- cgit v1.2.3