mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use format of ARes rather than content-type of remote errors to load errors.
[#1956 state:committed] Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
This commit is contained in:
parent
e98f9579c4
commit
e87748869a
2 changed files with 16 additions and 3 deletions
|
@ -101,10 +101,10 @@ module ActiveResource
|
|||
# Loads the set of remote errors into the object's Errors based on the
|
||||
# content-type of the error-block received
|
||||
def load_remote_errors(remote_errors, save_cache = false ) #:nodoc:
|
||||
case remote_errors.response['Content-Type']
|
||||
when /xml/
|
||||
case self.class.format
|
||||
when ActiveResource::Formats[:xml]
|
||||
errors.from_xml(remote_errors.response.body, save_cache)
|
||||
when /json/
|
||||
when ActiveResource::Formats[:json]
|
||||
errors.from_json(remote_errors.response.body, save_cache)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -69,6 +69,19 @@ class BaseErrorsTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_should_mark_as_invalid_when_content_type_is_unavailable_in_response_header
|
||||
ActiveResource::HttpMock.respond_to do |mock|
|
||||
mock.post "/people.xml", {}, %q(<?xml version="1.0" encoding="UTF-8"?><errors><error>Age can't be blank</error><error>Name can't be blank</error><error>Name must start with a letter</error><error>Person quota full for today.</error></errors>), 422, {}
|
||||
mock.post "/people.json", {}, %q({"errors":["Age can't be blank","Name can't be blank","Name must start with a letter","Person quota full for today."]}), 422, {}
|
||||
end
|
||||
|
||||
[ :json, :xml ].each do |format|
|
||||
invalid_user_using_format(format) do
|
||||
assert !@person.valid?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def invalid_user_using_format(mime_type_reference)
|
||||
previous_format = Person.format
|
||||
|
|
Loading…
Reference in a new issue