提交 a200446c 编写于 作者: P Piotr Sarnacki

Merge pull request #4491 from pkondzior/master

Wrong behavior of ActiveModel::Errors#dup is causing regressions on Rails master
......@@ -78,6 +78,11 @@ def initialize(base)
@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 @@ def [](attribute)
# 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 @@ def test_include?
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'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册