Skip to content

Commit

Permalink
Fix brittle content-type check. [#1956 state:committed]
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy committed Sep 17, 2009
1 parent c9d3c48 commit b5dd1b6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions activeresource/lib/active_resource/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def save_with_validation(perform_validation = true)
# 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
Expand Down
4 changes: 2 additions & 2 deletions activeresource/test/cases/base_errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
end

Expand Down

0 comments on commit b5dd1b6

Please sign in to comment.