From e87748869af238fe6bcb78e8d9a8d2bbc3734039 Mon Sep 17 00:00:00 2001 From: Jatinder Singh Date: Wed, 27 Jan 2010 15:28:32 -0800 Subject: Use format of ARes rather than content-type of remote errors to load errors. [#1956 state:committed] Signed-off-by: Jeremy Kemper --- activeresource/lib/active_resource/validations.rb | 6 +++--- activeresource/test/cases/base_errors_test.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/activeresource/lib/active_resource/validations.rb b/activeresource/lib/active_resource/validations.rb index 7b2382bd8c..4774c6dd22 100644 --- a/activeresource/lib/active_resource/validations.rb +++ b/activeresource/lib/active_resource/validations.rb @@ -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 diff --git a/activeresource/test/cases/base_errors_test.rb b/activeresource/test/cases/base_errors_test.rb index 1eb7765132..b4fd75fba3 100644 --- a/activeresource/test/cases/base_errors_test.rb +++ b/activeresource/test/cases/base_errors_test.rb @@ -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(Age can't be blankName can't be blankName must start with a letterPerson quota full for today.), 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 -- cgit v1.2.3