Navigation Menu

Skip to content

Commit

Permalink
Merge pull request rails#6682 from acapilleri/dup_validation_fix_back…
Browse files Browse the repository at this point in the history
…port_for_1_9_3

Dup validation fix backport for 1 9 3
  • Loading branch information
rafaelfranca committed Jun 12, 2012
2 parents 0ccdeeb + b97e0a1 commit 6522a12
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion activemodel/lib/active_model/validations.rb
Expand Up @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions activemodel/test/cases/validations_test.rb
Expand Up @@ -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'
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions activemodel/test/models/book.rb
@@ -0,0 +1,3 @@
class Book < Hash
include ActiveModel::Validations
end

0 comments on commit 6522a12

Please sign in to comment.