diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-06-12 10:21:52 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-06-12 10:21:52 -0700 |
commit | 6522a127e549040d834196eea6eb2818e5051dba (patch) | |
tree | 1024b3785669a23fa8c2185d77dd5aae03e49a88 | |
parent | 0ccdeeb6b589b486f9ffdfb56cbbf901ec955d88 (diff) | |
parent | b97e0a1127d45e25e4281d6c1b5fb9a57f0efea6 (diff) | |
download | rails-6522a127e549040d834196eea6eb2818e5051dba.tar.gz rails-6522a127e549040d834196eea6eb2818e5051dba.tar.bz2 rails-6522a127e549040d834196eea6eb2818e5051dba.zip |
Merge pull request #6682 from acapilleri/dup_validation_fix_backport_for_1_9_3
Dup validation fix backport for 1 9 3
-rw-r--r-- | activemodel/lib/active_model/validations.rb | 3 | ||||
-rw-r--r-- | activemodel/test/cases/validations_test.rb | 11 | ||||
-rw-r--r-- | activemodel/test/models/book.rb | 3 |
3 files changed, 16 insertions, 1 deletions
diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index 18cd53e130..f38121c175 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -168,8 +168,9 @@ module ActiveModel # 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: diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index 56c9a5592c..d000a88ce1 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -5,6 +5,7 @@ require 'models/topic' 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 @@ class ValidationsTest < ActiveModel::TestCase 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 diff --git a/activemodel/test/models/book.rb b/activemodel/test/models/book.rb new file mode 100644 index 0000000000..c5c19046c8 --- /dev/null +++ b/activemodel/test/models/book.rb @@ -0,0 +1,3 @@ +class Book < Hash + include ActiveModel::Validations +end |