Fix brittle content-type check. [#1956 state:committed]
This commit is contained in:
parent
c9d3c48dc6
commit
b5dd1b6599
|
@ -93,9 +93,9 @@ module ActiveResource
|
|||
# content-type of the error-block received
|
||||
def load_remote_errors(remote_errors, save_cache = false ) #:nodoc:
|
||||
case remote_errors.response['Content-Type']
|
||||
when 'application/xml'
|
||||
when /xml/
|
||||
errors.from_xml(remote_errors.response.body, save_cache)
|
||||
when 'application/json'
|
||||
when /json/
|
||||
errors.from_json(remote_errors.response.body, save_cache)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,8 +4,8 @@ require "fixtures/person"
|
|||
class BaseErrorsTest < Test::Unit::TestCase
|
||||
def setup
|
||||
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, {'Content-Type' => 'application/xml'}
|
||||
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, {'Content-Type' => 'application/json'}
|
||||
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, {'Content-Type' => 'application/xml; charset=utf-8'}
|
||||
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, {'Content-Type' => 'application/json; charset=utf-8'}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue