提交 9766997f 编写于 作者: J Josh Kalderimis 提交者: José Valim

when using respond_with with an invalid resource and custom options, the...

when using respond_with with an invalid resource and custom options, the default response status and error messages should be returned
Signed-off-by: NJosé Valim <jose.valim@gmail.com>
上级 28670933
......@@ -156,7 +156,8 @@ def api_behavior(error)
if get?
display resource
elsif has_errors?
display resource.errors, :status => :unprocessable_entity
# bypass the options merging of display
controller.render format => resource.errors, :status => :unprocessable_entity
elsif post?
display resource, :status => :created, :location => api_location
elsif has_empty_resource_definition?
......
......@@ -953,6 +953,23 @@ def test_using_resource_with_status_and_location
assert_equal 201, @response.status
end
def test_using_resource_with_status_and_location_with_invalid_resource
errors = { :name => :invalid }
Customer.any_instance.stubs(:errors).returns(errors)
@request.accept = "text/xml"
post :using_resource_with_status_and_location
assert_equal errors.to_xml, @response.body
assert_equal 422, @response.status
assert_equal nil, @response.location
put :using_resource_with_status_and_location
assert_equal errors.to_xml, @response.body
assert_equal 422, @response.status
assert_equal nil, @response.location
end
def test_using_resource_with_responder
get :using_resource_with_responder
assert_equal "Resource name is david", @response.body
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册