mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Remove deprecated support to use []=
in ActiveModel::Errors#messages
This commit is contained in:
parent
bab78b5d54
commit
70dc990ad2
4 changed files with 12 additions and 40 deletions
|
@ -1,8 +1,12 @@
|
|||
* Remove deprecated support `delete` errors from `ActiveModel::Errors#messages`.
|
||||
* Remove deprecated support to use `[]=` in `ActiveModel::Errors#messages`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated support `clear` errors from `ActiveModel::Errors#messages`.
|
||||
* Remove deprecated support to `delete` errors from `ActiveModel::Errors#messages`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated support to `clear` errors from `ActiveModel::Errors#messages`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
|
|
|
@ -232,11 +232,9 @@ module ActiveModel
|
|||
undef :to_h
|
||||
|
||||
# Returns a Hash of attributes with an array of their error messages.
|
||||
#
|
||||
# Updating this hash would still update errors state for backward
|
||||
# compatibility, but this behavior is deprecated.
|
||||
def messages
|
||||
DeprecationHandlingMessageHash.new(self)
|
||||
hash = to_hash
|
||||
hash.freeze
|
||||
end
|
||||
|
||||
# Returns a Hash of attributes with an array of their error details.
|
||||
|
@ -494,30 +492,6 @@ module ActiveModel
|
|||
end
|
||||
end
|
||||
|
||||
class DeprecationHandlingMessageHash < SimpleDelegator # :nodoc:
|
||||
def initialize(errors)
|
||||
@errors = errors
|
||||
super(prepare_content)
|
||||
end
|
||||
|
||||
def []=(attribute, value)
|
||||
ActiveSupport::Deprecation.warn("Calling `[]=` to an ActiveModel::Errors is deprecated. Please call `ActiveModel::Errors#add` instead.")
|
||||
|
||||
@errors.delete(attribute)
|
||||
Array(value).each do |message|
|
||||
@errors.add(attribute, message)
|
||||
end
|
||||
|
||||
__setobj__ prepare_content
|
||||
end
|
||||
|
||||
private
|
||||
def prepare_content
|
||||
content = @errors.to_hash
|
||||
content.freeze
|
||||
end
|
||||
end
|
||||
|
||||
# Raised when a validation cannot be corrected by end users and are considered
|
||||
# exceptional.
|
||||
#
|
||||
|
|
|
@ -118,14 +118,6 @@ class ErrorsTest < ActiveModel::TestCase
|
|||
assert_equal ["omg"], errors["name"]
|
||||
end
|
||||
|
||||
test "[]= overrides values" do
|
||||
errors = ActiveModel::Errors.new(self)
|
||||
assert_deprecated { errors.messages[:foo] = "omg" }
|
||||
assert_deprecated { errors.messages[:foo] = "zomg" }
|
||||
|
||||
assert_equal ["zomg"], errors[:foo]
|
||||
end
|
||||
|
||||
test "attribute_names returns the error attributes" do
|
||||
errors = ActiveModel::Errors.new(Person.new)
|
||||
errors.add(:foo, "omg")
|
||||
|
|
|
@ -136,9 +136,11 @@ Please refer to the [Changelog][active-model] for detailed changes.
|
|||
|
||||
* Remove deprecated support concat errors to `ActiveModel::Errors#messages`.
|
||||
|
||||
* Remove deprecated support `clear` errors from `ActiveModel::Errors#messages`.
|
||||
* Remove deprecated support to `clear` errors from `ActiveModel::Errors#messages`.
|
||||
|
||||
* Remove deprecated support `delete` errors from `ActiveModel::Errors#messages`.
|
||||
* Remove deprecated support to `delete` errors from `ActiveModel::Errors#messages`.
|
||||
|
||||
* Remove deprecated support to use `[]=` in `ActiveModel::Errors#messages`.
|
||||
|
||||
### Deprecations
|
||||
|
||||
|
|
Loading…
Reference in a new issue