mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #4491 from pkondzior/master
Wrong behavior of ActiveModel::Errors#dup is causing regressions on Rails master
This commit is contained in:
commit
a200446c53
2 changed files with 14 additions and 1 deletions
|
@ -78,6 +78,11 @@ module ActiveModel
|
|||
@messages = ActiveSupport::OrderedHash.new
|
||||
end
|
||||
|
||||
def initialize_dup(other)
|
||||
@messages = other.messages.dup
|
||||
super
|
||||
end
|
||||
|
||||
# Clear the messages
|
||||
def clear
|
||||
messages.clear
|
||||
|
@ -118,7 +123,7 @@ module ActiveModel
|
|||
# p.errors[:name] = "must be set"
|
||||
# p.errors[:name] # => ['must be set']
|
||||
def []=(attribute, error)
|
||||
self[attribute.to_sym] << error
|
||||
self[attribute] << error
|
||||
end
|
||||
|
||||
# Iterates through each error key, value pair in the error messages hash.
|
||||
|
|
|
@ -40,6 +40,14 @@ class ErrorsTest < ActiveModel::TestCase
|
|||
assert errors.include?(:foo), 'errors should include :foo'
|
||||
end
|
||||
|
||||
def test_dup
|
||||
errors = ActiveModel::Errors.new(self)
|
||||
errors[:foo] = 'bar'
|
||||
errors_dup = errors.dup
|
||||
errors_dup[:bar] = 'omg'
|
||||
assert_not_same errors_dup.messages, errors.messages
|
||||
end
|
||||
|
||||
def test_has_key?
|
||||
errors = ActiveModel::Errors.new(self)
|
||||
errors[:foo] = 'omg'
|
||||
|
|
Loading…
Reference in a new issue