Browse files

`@destroyed` should always be set to `false` when an object is duped.

  • Loading branch information...
1 parent 98e8c96 commit 5fe4e62807adc61c42c2d94ec36802f25554224a @kuldeepaggarwal kuldeepaggarwal committed Apr 18, 2014
View
4 activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+* `@destroyed` should always be set to `false` when an object is duped.
+
+ *Kuldeep Aggarwal*
+
* Fixed has_many association to make it support irregular inflections.
Fixes #8928.
View
1 activerecord/lib/active_record/core.rb
@@ -267,6 +267,7 @@ def initialize_dup(other) # :nodoc:
@attributes_cache = {}
@new_record = true
+ @destroyed = false
super
end
View
16 activerecord/test/cases/persistence_test.rb
@@ -233,6 +233,22 @@ def test_save_for_record_with_only_primary_key_that_is_provided
assert_nothing_raised { Minimalistic.create!(:id => 2) }
end
+ def test_save_with_duping_of_destroyed_object
+ developer = Developer.create(name: "Kuldeep")
+ developer.destroy
+ new_developer = developer.dup
+ new_developer.save
+ assert new_developer.persisted?
+ end
+
+ def test_dup_of_destroyed_object_is_not_destroyed
+ developer = Developer.create(name: "Kuldeep")
+ developer.destroy
+ new_developer = developer.dup
+ new_developer.save
+ assert_equal new_developer.destroyed?, false
+ end
+
def test_create_many
topics = Topic.create([ { "title" => "first" }, { "title" => "second" }])
assert_equal 2, topics.size

0 comments on commit 5fe4e62

Please sign in to comment.