diff options
author | Edouard CHIN <edouard.chin@shopify.com> | 2019-07-22 14:02:15 +0200 |
---|---|---|
committer | Edouard CHIN <edouard.chin@shopify.com> | 2019-07-23 14:11:36 +0200 |
commit | 35ac22d6ef60bcfb699ed6e92d9cbe4d891762c3 (patch) | |
tree | d61ad81651d0149e54b71e030b096602d32a1ab4 /activemodel/test | |
parent | 9ad806887096be1f60019a6b301a4c84aa1d8e65 (diff) | |
download | rails-35ac22d6ef60bcfb699ed6e92d9cbe4d891762c3.tar.gz rails-35ac22d6ef60bcfb699ed6e92d9cbe4d891762c3.tar.bz2 rails-35ac22d6ef60bcfb699ed6e92d9cbe4d891762c3.zip |
Deprecated `AM::Errors#to_h`:
- In ef4d3215b1198c456780b8d18aa62be7795b9b8c I made a change to
pass `AM::Error` object in case the arity of the block passed to
`each` accepted less than 2 arguments.
This is causing one issue for `to_h` as it expects the argument
passed to the block to be an Array (and were are passing it an
instance of `AM::Error`).
There is no real reason to use `to_h` anymore since `to_hash` exists
Deprecating `to_h` inf favor of `to_hash`
Co-Authored-By: Rafael França <rafael@franca.dev>
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index 60b20ab59f..79ccfe0c13 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -474,6 +474,16 @@ class ErrorsTest < ActiveModel::TestCase assert_equal ["name cannot be blank", "name cannot be nil"], person.errors.to_a end + test "to_h is deprecated" do + person = Person.new + person.errors.add(:name, "cannot be blank") + + expected_deprecation = "ActiveModel::Errors#to_h is deprecated. Please call #to_hash instead." + assert_deprecated(expected_deprecation) do + assert_equal({ name: ["cannot be blank"] }, person.errors.to_h) + end + end + test "to_hash returns the error messages hash" do person = Person.new person.errors.add(:name, "cannot be blank") |