Skip to content

Commit 0586c88

Browse files
authored
Merge pull request rails#53330 from Shopify/active-model-dirty-skip-reset
ActiveModel::Dirty: only reset original values for persisted records
2 parents 92410a1 + 788330e commit 0586c88

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

activemodel/lib/active_model/dirty.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ module Dirty
247247

248248
def initialize_dup(other) # :nodoc:
249249
super
250-
if self.class.respond_to?(:_default_attributes)
250+
if other.persisted? && self.class.respond_to?(:_default_attributes)
251251
@attributes = self.class._default_attributes.map do |attr|
252252
attr.with_value_from_user(@attributes.fetch_value(attr.name))
253253
end

activemodel/test/cases/dirty_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
class DirtyTest < ActiveModel::TestCase
77
class DirtyModel
8+
include ActiveModel::API
89
include ActiveModel::Dirty
910
define_attribute_methods :name, :color, :size, :status
1011

0 commit comments

Comments
 (0)