From 1e780fa6593207438ffa76c21d7d998c99c6278b Mon Sep 17 00:00:00 2001 From: Lawrence Pit Date: Wed, 19 May 2010 15:54:04 +1000 Subject: [PATCH] Test: respond_with(resource) in +create+ which has a template defined always responds with status 200 --- actionpack/test/controller/mime_responds_test.rb | 34 ++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) diff --git a/actionpack/test/controller/mime_responds_test.rb b/actionpack/test/controller/mime_responds_test.rb index c8ba8bc..9b5d736 100644 --- a/actionpack/test/controller/mime_responds_test.rb +++ b/actionpack/test/controller/mime_responds_test.rb @@ -509,6 +509,10 @@ class RespondWithController < ActionController::Base respond_with(resource, :responder => responder) end + def using_resource_with_template + respond_with(resource, :responder => TemplateResponder) + end + protected def resource @@ -521,6 +525,12 @@ protected end end +class TemplateResponder < ActionController::Responder + def default_render + display resource + end +end + class InheritedRespondWithController < RespondWithController clear_respond_to respond_to :xml, :json @@ -633,6 +643,17 @@ class RespondWithControllerTest < ActionController::TestCase end end + def test_using_resource_for_post_with_xml_with_template_yields_created_on_success + with_test_route_set do + @request.accept = "application/xml" + post :using_resource_with_template + assert_equal "application/xml", @response.content_type + assert_equal 201, @response.status + assert_equal "david", @response.body + assert_equal "http://www.example.com/customers/13", @response.location + end + end + def test_using_resource_for_post_with_xml_yields_unprocessable_entity_on_failure with_test_route_set do @request.accept = "application/xml" @@ -646,6 +667,19 @@ class RespondWithControllerTest < ActionController::TestCase end end + def test_using_resource_for_post_with_xml_with_template_yields_unprocessable_entity_on_failure + with_test_route_set do + @request.accept = "application/xml" + errors = { :name => :invalid } + Customer.any_instance.stubs(:errors).returns(errors) + post :using_resource_with_template + assert_equal "application/xml", @response.content_type + assert_equal 422, @response.status + assert_equal errors.to_xml, @response.body + assert_nil @response.location + end + end + def test_using_resource_for_put_with_html_redirects_on_success with_test_route_set do put :using_resource -- 1.7.0