1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

No need to deprecate Errors#first

This deprecation is useless since the result is still an Error object
and there is no way to fix the code to remove the deprecation.

Let's just accept as a breaking change.
This commit is contained in:
Rafael Mendonça França 2020-04-13 19:07:59 -04:00
parent 666947089d
commit a4deb63798
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
3 changed files with 10 additions and 23 deletions

View file

@ -37,15 +37,13 @@
extra parameters, found in the original `details` hash.
The change tries its best at maintaining backward compatibility, however
some edge cases wont be covered, mainly related to manipulating
`errors.messages` and `errors.details` hashes directly. Moving forward,
some edge cases wont be covered, like `errors#first` will return `ActiveModel::Error` and manipulating
`errors.messages` and `errors.details` hashes directly will have no effect. Moving forward,
please convert those direct manipulations to use provided API methods instead.
The list of deprecated methods and their planned future behavioral changes at the next major release are:
* `errors#slice!` will be removed.
* `errors#first` will return Error object instead.
* `errors#last` will return Error object instead.
* `errors#each` with the `key, value` two-arguments block will stop working, while the `error` single-argument block would return `Error` object.
* `errors#values` will be removed.
* `errors#keys` will be removed.

View file

@ -208,16 +208,6 @@ module ActiveModel
DeprecationHandlingMessageArray.new(messages_for(attribute), self, attribute)
end
def first
deprecation_index_access_warning(:first)
super
end
def last
deprecation_index_access_warning(:last)
super
end
# Iterates through each error object.
#
# person.errors.add(:name, :too_short, count: 2)
@ -585,15 +575,6 @@ module ActiveModel
def deprecation_rename_warning(old_method_name, new_method_name)
ActiveSupport::Deprecation.warn("ActiveModel::Errors##{old_method_name} is deprecated. Please call ##{new_method_name} instead.")
end
def deprecation_index_access_warning(method_name, alternative_message)
message = +"ActiveModel::Errors##{method_name} is deprecated. In the next release it would return `Error` object instead."
if alternative_message
message << "\n\nTo achieve the same use:\n\n "
message << alternative_message
end
ActiveSupport::Deprecation.warn(message)
end
end
class DeprecationHandlingMessageHash < SimpleDelegator

View file

@ -63,6 +63,14 @@ class ErrorsTest < ActiveModel::TestCase
}
end
def test_first
errors = ActiveModel::Errors.new(Person.new)
errors.add(:name, :blank)
error = errors.first
assert_kind_of ActiveModel::Error, error
end
def test_dup
errors = ActiveModel::Errors.new(Person.new)
errors.add(:name)