Remove deprecated `ActiveModel::Errors#keys`

This commit is contained in:
Rafael Mendonça França 2021-11-16 00:08:36 +00:00
parent 6fed53b694
commit edc4e7dfb5
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
6 changed files with 12 additions and 37 deletions

View File

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

View File

@ -200,17 +200,6 @@ module ActiveModel
@errors.each(&block)
end
# Returns all message keys.
#
# person.errors.messages # => {:name=>["cannot be nil", "must be specified"]}
# person.errors.keys # => [:name]
def keys
deprecation_removal_warning(:keys, "errors.attribute_names")
keys = @errors.map(&:attribute)
keys.uniq!
keys.freeze
end
# Returns all error attribute names
#
# person.errors.messages # => {:name=>["cannot be nil", "must be specified"]}

View File

@ -135,26 +135,6 @@ class ErrorsTest < ActiveModel::TestCase
assert_equal ["zomg"], errors[:foo]
end
test "keys returns the error keys" do
errors = ActiveModel::Errors.new(Person.new)
assert_deprecated { errors.messages[:foo] << "omg" }
assert_deprecated { errors.messages[:baz] << "zomg" }
assert_deprecated do
assert_equal [:foo, :baz], errors.keys
end
end
test "keys returns an empty array after try to get a message only" do
errors = ActiveModel::Errors.new(Person.new)
errors.messages[:foo]
errors.messages[:baz]
assert_deprecated do
assert_equal [], errors.keys
end
end
test "attribute_names returns the error attributes" do
errors = ActiveModel::Errors.new(Person.new)
errors.add(:foo, "omg")

View File

@ -237,14 +237,14 @@ class ValidationsTest < ActiveModel::TestCase
t = Topic.new title: ""
assert_predicate t, :invalid?
assert_equal :title, key = assert_deprecated { t.errors.keys[0] }
assert_equal :title, key = t.errors.attribute_names[0]
assert_equal "can't be blank", t.errors[key][0]
assert_equal "is too short (minimum is 2 characters)", t.errors[key][1]
assert_equal :author_name, key = assert_deprecated { t.errors.keys[1] }
assert_equal :author_name, key = t.errors.attribute_names[1]
assert_equal "can't be blank", t.errors[key][0]
assert_equal :author_email_address, key = assert_deprecated { t.errors.keys[2] }
assert_equal :author_email_address, key = t.errors.attribute_names[2]
assert_equal "will never be valid", t.errors[key][0]
assert_equal :content, key = assert_deprecated { t.errors.keys[3] }
assert_equal :content, key = t.errors.attribute_names[3]
assert_equal "is too short (minimum is 2 characters)", t.errors[key][0]
end

View File

@ -305,7 +305,7 @@ class PersistenceTest < ActiveRecord::TestCase
assert_not_predicate company, :valid?
original_errors = company.errors
client = company.becomes(Client)
assert_equal assert_deprecated { original_errors.keys }, assert_deprecated { client.errors.keys }
assert_equal original_errors.attribute_names, client.errors.attribute_names
end
def test_becomes_errors_base
@ -319,7 +319,7 @@ class PersistenceTest < ActiveRecord::TestCase
admin.errors.add :token, :invalid
child = admin.becomes(child_class)
assert_equal [:token], assert_deprecated { child.errors.keys }
assert_equal [:token], child.errors.attribute_names
assert_nothing_raised do
child.errors.add :foo, :invalid
end

View File

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