From 7021184f9cd385bc7f7c7bedf6ce871806b1981e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20Kondzior?= <pawel@kondzior.com>
Date: Mon, 16 Jan 2012 23:52:55 -0800
Subject: Fix ActiveModel::Errors#dup

Since ActiveModel::Errors instance keeps all error messages as hash
we should duplicate this object as well.

Previously ActiveModel::Errors was a subclass of ActiveSupport::OrderedHash,
which results in different behavior on dup, this may result in regression for
people relying on it.

Because Rails 3.2 stills supports Ruby 1.8.7 in order to properly fix this
regression we need to backport #initialize_dup.
---
 activemodel/test/cases/errors_test.rb | 8 ++++++++
 1 file changed, 8 insertions(+)

(limited to 'activemodel/test')

diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb
index 8361069819..e2dea12589 100644
--- a/activemodel/test/cases/errors_test.rb
+++ b/activemodel/test/cases/errors_test.rb
@@ -46,6 +46,14 @@ class ErrorsTest < ActiveModel::TestCase
     assert errors.has_key?(:foo), 'errors should have key :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
+
   test "should return true if no errors" do
     person = Person.new
     person.errors[:foo]
-- 
cgit v1.2.3