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
|
@messages = ActiveSupport::OrderedHash.new
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def initialize_dup(other)
|
||||||
|
@messages = other.messages.dup
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
# Clear the messages
|
# Clear the messages
|
||||||
def clear
|
def clear
|
||||||
messages.clear
|
messages.clear
|
||||||
|
@ -118,7 +123,7 @@ module ActiveModel
|
||||||
# p.errors[:name] = "must be set"
|
# p.errors[:name] = "must be set"
|
||||||
# p.errors[:name] # => ['must be set']
|
# p.errors[:name] # => ['must be set']
|
||||||
def []=(attribute, error)
|
def []=(attribute, error)
|
||||||
self[attribute.to_sym] << error
|
self[attribute] << error
|
||||||
end
|
end
|
||||||
|
|
||||||
# Iterates through each error key, value pair in the error messages hash.
|
# 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'
|
assert errors.include?(:foo), 'errors should include :foo'
|
||||||
end
|
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?
|
def test_has_key?
|
||||||
errors = ActiveModel::Errors.new(self)
|
errors = ActiveModel::Errors.new(self)
|
||||||
errors[:foo] = 'omg'
|
errors[:foo] = 'omg'
|
||||||
|
|
Loading…
Reference in a new issue