Permalink
Browse files

Merge pull request #6682 from acapilleri/dup_validation_fix_backport_…

…for_1_9_3

Dup validation fix backport for 1 9 3
  • Loading branch information...
2 parents 0ccdeeb + b97e0a1 commit 6522a127e549040d834196eea6eb2818e5051dba @rafaelfranca rafaelfranca committed Jun 12, 2012
@@ -168,8 +168,9 @@ def inherited(base)
# Clean the +Errors+ object if instance is duped
def initialize_dup(other) # :nodoc:
@errors = nil
+ super if defined?(super)
end
-
+
# Backport dup from 1.9 so that #initialize_dup gets called
unless Object.respond_to?(:initialize_dup)
def dup # :nodoc:
@@ -5,6 +5,7 @@
require 'models/reply'
require 'models/custom_reader'
require 'models/automobile'
+require 'models/book'
require 'active_support/json'
require 'active_support/xml_mini'
@@ -354,4 +355,14 @@ def test_dup_validity_is_independent
assert topic.invalid?
assert duped.valid?
end
+
+ def test_dup_call_parent_dup_when_include_validations
+ book = Book.new
+ book['title'] = "Litterature"
+ book['author'] = "Foo"
+ duped = book.dup
+
+ assert_equal book.keys, duped.keys
+ assert_equal book.values, duped.values
+ end
end
@@ -0,0 +1,3 @@
+class Book < Hash
+ include ActiveModel::Validations
+end

0 comments on commit 6522a12

Please sign in to comment.