Skip to content

Commit 3f3dd66

Browse files
authored
Merge pull request #437 from seanpdoyle/remove-rails-3-1-deprecation
Remove Validations deprecation code
2 parents b86cf0c + dd504b6 commit 3f3dd66

File tree

3 files changed

+2
-58
lines changed

3 files changed

+2
-58
lines changed

lib/active_resource/base.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,15 +325,6 @@ module ActiveResource
325325
# ryan.errors.invalid?(:first) # => true
326326
# ryan.errors.full_messages # => ['First cannot be empty']
327327
#
328-
# For backwards-compatibility with older endpoints, the following formats are also supported in JSON responses:
329-
#
330-
# # {"errors":['First cannot be empty']}
331-
# # This was the required format for previous versions of ActiveResource
332-
# # {"first":["cannot be empty"]}
333-
# # This was the default format produced by respond_with in ActionController <3.2.1
334-
#
335-
# Parsing either of these formats will result in a deprecation warning.
336-
#
337328
# Learn more about Active Resource's validation features in the ActiveResource::Validations documentation.
338329
#
339330
# === Timeouts

lib/active_resource/validations.rb

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,8 @@ def from_hash(messages, save_cache = false)
5555
# Grabs errors from a json response.
5656
def from_json(json, save_cache = false)
5757
decoded = ActiveSupport::JSON.decode(json) || {} rescue {}
58-
if decoded.kind_of?(Hash) && (decoded.has_key?("errors") || decoded.empty?)
59-
errors = decoded["errors"] || {}
60-
if errors.kind_of?(Array)
61-
# 3.2.1-style with array of strings
62-
ActiveResource.deprecator.warn("Returning errors as an array of strings is deprecated.")
63-
from_array errors, save_cache
64-
else
65-
# 3.2.2+ style
66-
from_hash errors, save_cache
67-
end
68-
else
69-
# <3.2-style respond_with - lacks 'errors' key
70-
ActiveResource.deprecator.warn('Returning errors as a hash without a root "errors" key is deprecated.')
71-
from_hash decoded, save_cache
72-
end
58+
errors = decoded["errors"] || {}
59+
from_hash errors, save_cache
7360
end
7461

7562
# Grabs errors from an XML response.

test/cases/base_errors_test.rb

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -111,40 +111,6 @@ def test_should_mark_as_invalid_when_content_type_is_unavailable_in_response_hea
111111
end
112112
end
113113

114-
def test_should_parse_json_string_errors_with_an_errors_key
115-
ActiveResource::HttpMock.respond_to do |mock|
116-
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.", "Phone work can't be blank", "Phone is not valid"]}), 422, "Content-Type" => "application/json; charset=utf-8"
117-
end
118-
119-
assert_deprecated(/as an array/, ActiveResource.deprecator) do
120-
invalid_user_using_format(:json) do
121-
assert @person.errors[:name].any?
122-
assert_equal [ "can't be blank" ], @person.errors[:age]
123-
assert_equal [ "can't be blank", "must start with a letter" ], @person.errors[:name]
124-
assert_equal [ "is not valid" ], @person.errors[:phone]
125-
assert_equal [ "can't be blank" ], @person.errors[:phone_work]
126-
assert_equal [ "Person quota full for today." ], @person.errors[:base]
127-
end
128-
end
129-
end
130-
131-
def test_should_parse_3_1_style_json_errors
132-
ActiveResource::HttpMock.respond_to do |mock|
133-
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."],"phone_work":["can't be blank"],"phone":["is not valid"]}), 422, "Content-Type" => "application/json; charset=utf-8"
134-
end
135-
136-
assert_deprecated(/without a root/, ActiveResource.deprecator) do
137-
invalid_user_using_format(:json) do
138-
assert @person.errors[:name].any?
139-
assert_equal [ "can't be blank" ], @person.errors[:age]
140-
assert_equal [ "can't be blank", "must start with a letter" ], @person.errors[:name]
141-
assert_equal [ "is not valid" ], @person.errors[:phone]
142-
assert_equal [ "can't be blank" ], @person.errors[:phone_work]
143-
assert_equal [ "Person quota full for today." ], @person.errors[:base]
144-
end
145-
end
146-
end
147-
148114
private
149115
def invalid_user_using_format(mime_type_reference)
150116
previous_format = Person.format

0 commit comments

Comments
 (0)