Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix brittle content-type check. [#1956 state:committed]

  • Loading branch information...
commit 1488c6cc9e6237ce794e3c4a6201627b9fd4ca09 1 parent 4f5cac5
@jeremy jeremy authored
View
4 activeresource/lib/active_resource/validations.rb
@@ -260,9 +260,9 @@ def save_with_validation
true
rescue ResourceInvalid => error
case error.response['Content-Type']
- when 'application/xml'
+ when /xml/
errors.from_xml(error.response.body)
- when 'application/json'
+ when /json/
errors.from_json(error.response.body)
end
false
View
4 activeresource/test/base_errors_test.rb
@@ -4,8 +4,8 @@
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
@person = Person.new(:name => '', :age => '')
assert_equal @person.save, false
Please sign in to comment.
Something went wrong with that request. Please try again.