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

Remove deprecated ActiveModel::Errors#slice!

This commit is contained in:
Rafael Mendonça França 2021-11-16 00:04:37 +00:00
parent a743656ae4
commit 362e17e899
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
4 changed files with 6 additions and 43 deletions

View file

@ -1,3 +1,7 @@
* Remove deprecated `ActiveModel::Errors#slice!`.
*Rafael Mendonça França*
* Remove deprecated `ActiveModel::Errors#to_h`.
*Rafael Mendonça França*

View file

@ -138,25 +138,6 @@ module ActiveModel
}
end
# Removes all errors except the given keys. Returns a hash containing the removed errors.
#
# person.errors.keys # => [:name, :age, :gender, :city]
# person.errors.slice!(:age, :gender) # => { :name=>["cannot be nil"], :city=>["cannot be nil"] }
# person.errors.keys # => [:age, :gender]
def slice!(*keys)
deprecation_removal_warning(:slice!)
keys = keys.map(&:to_sym)
results = messages.dup.slice!(*keys)
@errors.keep_if do |error|
keys.include?(error.attribute)
end
results
end
# Search for errors matching +attribute+, +type+ or +options+.
#
# Only supplied params will be matched.

View file

@ -754,30 +754,6 @@ class ErrorsTest < ActiveModel::TestCase
assert(person.errors.added?(:name, :blank))
end
test "slice! removes all errors except the given keys" do
person = Person.new
person.errors.add(:name, "cannot be nil")
person.errors.add(:age, "cannot be nil")
person.errors.add(:gender, "cannot be nil")
person.errors.add(:city, "cannot be nil")
assert_deprecated { person.errors.slice!(:age, "gender") }
assert_equal [:age, :gender], assert_deprecated { person.errors.keys }
end
test "slice! returns the deleted errors" do
person = Person.new
person.errors.add(:name, "cannot be nil")
person.errors.add(:age, "cannot be nil")
person.errors.add(:gender, "cannot be nil")
person.errors.add(:city, "cannot be nil")
removed_errors = assert_deprecated { person.errors.slice!(:age, "gender") }
assert_equal({ name: ["cannot be nil"], city: ["cannot be nil"] }, removed_errors)
end
test "errors are marshalable" do
errors = ActiveModel::Errors.new(Person.new)
errors.add(:name, :invalid)

View file

@ -126,6 +126,8 @@ Please refer to the [Changelog][active-model] for detailed changes.
* Remove deprecated `ActiveModel::Errors#to_h`.
* Remove deprecated `ActiveModel::Errors#slice!`.
### Deprecations
### Notable changes