Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #4491 from pkondzior/master

Wrong behavior of ActiveModel::Errors#dup is causing regressions on Rails master
  • Loading branch information...
commit a200446c5311477a17f6ff96c32215c72690f8b7 2 parents 21afd9b + 6174d3b
@drogus drogus authored
View
7 activemodel/lib/active_model/errors.rb
@@ -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.
View
8 activemodel/test/cases/errors_test.rb
@@ -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'
Please sign in to comment.
Something went wrong with that request. Please try again.