Skip to content
Browse files

Merge pull request #14796 from kuldeepaggarwal/fix-save-issue

when a destroyed record is duped, it is no longer ´destroyed?`.
  • Loading branch information...
1 parent 87a2f02 commit c1d9c11cbe3d20f2c3daf4e646e5818f1126ffb2 @senny senny committed
View
4 activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+* When a destroyed record is duped, the dup is not `destroyed?`.
+
+ *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 c1d9c11

Please sign in to comment.
Something went wrong with that request. Please try again.