1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Responders now return 204 No Content for API requests without a response body (as in the new scaffold)

This commit is contained in:
José Valim 2011-10-26 09:31:56 +02:00
parent aef62c4b4e
commit 80768b739e
3 changed files with 13 additions and 31 deletions

View file

@ -1,5 +1,7 @@
*Rails 3.2.0 (unreleased)*
* Responders now return 204 No Content for API requests without a response body (as in the new scaffold) [José Valim]
* Added ActionDispatch::RequestId middleware that'll make a unique X-Request-Id header available to the response and enables the ActionDispatch::Request#uuid method. This makes it easy to trace requests from end-to-end in the stack and to identify individual requests in mixed logs like Syslog [DHH]
* Limit the number of options for select_year to 1000.

View file

@ -202,10 +202,8 @@ module ActionController #:nodoc:
display resource
elsif post?
display resource, :status => :created, :location => api_location
elsif has_empty_resource_definition?
display empty_resource, :status => :ok
else
head :ok
head :no_content
end
end
@ -269,24 +267,6 @@ module ActionController #:nodoc:
@action ||= ACTIONS_FOR_VERBS[request.request_method_symbol]
end
# Check whether resource needs a specific definition of empty resource to be valid
#
def has_empty_resource_definition?
respond_to?("empty_#{format}_resource")
end
# Delegate to proper empty resource method
#
def empty_resource
send("empty_#{format}_resource")
end
# Return a valid empty JSON resource
#
def empty_json_resource
"{}"
end
def resource_errors
respond_to?("#{format}_resource_errors") ? send("#{format}_resource_errors") : resource.errors
end

View file

@ -796,21 +796,21 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
def test_using_resource_for_put_with_xml_yields_ok_on_success
def test_using_resource_for_put_with_xml_yields_no_content_on_success
@request.accept = "application/xml"
put :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 200, @response.status
assert_equal 204, @response.status
assert_equal " ", @response.body
end
def test_using_resource_for_put_with_json_yields_ok_on_success
def test_using_resource_for_put_with_json_yields_no_content_on_success
Customer.any_instance.stubs(:to_json).returns('{"name": "David"}')
@request.accept = "application/json"
put :using_resource
assert_equal "application/json", @response.content_type
assert_equal 200, @response.status
assert_equal "{}", @response.body
assert_equal 204, @response.status
assert_equal " ", @response.body
end
def test_using_resource_for_put_with_xml_yields_unprocessable_entity_on_failure
@ -846,23 +846,23 @@ class RespondWithControllerTest < ActionController::TestCase
end
end
def test_using_resource_for_delete_with_xml_yields_ok_on_success
def test_using_resource_for_delete_with_xml_yields_no_content_on_success
Customer.any_instance.stubs(:destroyed?).returns(true)
@request.accept = "application/xml"
delete :using_resource
assert_equal "application/xml", @response.content_type
assert_equal 200, @response.status
assert_equal 204, @response.status
assert_equal " ", @response.body
end
def test_using_resource_for_delete_with_json_yields_ok_on_success
def test_using_resource_for_delete_with_json_yields_no_content_on_success
Customer.any_instance.stubs(:to_json).returns('{"name": "David"}')
Customer.any_instance.stubs(:destroyed?).returns(true)
@request.accept = "application/json"
delete :using_resource
assert_equal "application/json", @response.content_type
assert_equal 200, @response.status
assert_equal "{}", @response.body
assert_equal 204, @response.status
assert_equal " ", @response.body
end
def test_using_resource_for_delete_with_html_redirects_on_failure