diff options
author | Matt Jones <al2o3cr@gmail.com> | 2012-02-04 16:02:52 -0600 |
---|---|---|
committer | Matt Jones <al2o3cr@gmail.com> | 2012-02-04 16:02:52 -0600 |
commit | 02859745cc0db02fcb1af27da345456a3b5e1eb2 (patch) | |
tree | 6f20a39759b9dbd17844915fc787d9b79bbadc37 /activeresource/test | |
parent | 7c307c2da3e0e01131a892b30c040832edbfacb5 (diff) | |
download | rails-02859745cc0db02fcb1af27da345456a3b5e1eb2.tar.gz rails-02859745cc0db02fcb1af27da345456a3b5e1eb2.tar.bz2 rails-02859745cc0db02fcb1af27da345456a3b5e1eb2.zip |
add handling for backwards-compatibility and update documentation
Diffstat (limited to 'activeresource/test')
-rw-r--r-- | activeresource/test/cases/base_errors_test.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/activeresource/test/cases/base_errors_test.rb b/activeresource/test/cases/base_errors_test.rb index 98fef5fa73..88ac2de96e 100644 --- a/activeresource/test/cases/base_errors_test.rb +++ b/activeresource/test/cases/base_errors_test.rb @@ -93,6 +93,36 @@ class BaseErrorsTest < ActiveSupport::TestCase end end + def test_should_parse_json_string_errors_with_an_errors_key + ActiveResource::HttpMock.respond_to do |mock| + 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 + + assert_deprecated(/as an array/) do + invalid_user_using_format(:json) do + assert @person.errors[:name].any? + assert_equal ["can't be blank"], @person.errors[:age] + assert_equal ["can't be blank", "must start with a letter"], @person.errors[:name] + assert_equal ["Person quota full for today."], @person.errors[:base] + end + end + end + + def test_should_parse_3_1_style_json_errors + ActiveResource::HttpMock.respond_to do |mock| + mock.post "/people.json", {}, %q({"age":["can't be blank"],"name":["can't be blank", "must start with a letter"],"person":["quota full for today."]}), 422, {'Content-Type' => 'application/json; charset=utf-8'} + end + + assert_deprecated(/without a root/) do + invalid_user_using_format(:json) do + assert @person.errors[:name].any? + assert_equal ["can't be blank"], @person.errors[:age] + assert_equal ["can't be blank", "must start with a letter"], @person.errors[:name] + assert_equal ["Person quota full for today."], @person.errors[:base] + end + end + end + private def invalid_user_using_format(mime_type_reference) previous_format = Person.format |