aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activestorage/lib/active_storage/attached/model.rb4
-rw-r--r--activestorage/test/models/attached/many_test.rb8
-rw-r--r--activestorage/test/models/attached/one_test.rb8
3 files changed, 20 insertions, 0 deletions
diff --git a/activestorage/lib/active_storage/attached/model.rb b/activestorage/lib/active_storage/attached/model.rb
index 1cdaac2e32..aa5c769cb8 100644
--- a/activestorage/lib/active_storage/attached/model.rb
+++ b/activestorage/lib/active_storage/attached/model.rb
@@ -132,5 +132,9 @@ module ActiveStorage
def attachment_changes #:nodoc:
@attachment_changes ||= {}
end
+
+ def reload(*) #:nodoc:
+ super.tap { @attachment_changes = nil }
+ end
end
end
diff --git a/activestorage/test/models/attached/many_test.rb b/activestorage/test/models/attached/many_test.rb
index 719032786b..fc89dae658 100644
--- a/activestorage/test/models/attached/many_test.rb
+++ b/activestorage/test/models/attached/many_test.rb
@@ -467,6 +467,14 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
end
end
+ test "clearing change on reload" do
+ @user.highlights = [ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ]
+ assert @user.highlights.attached?
+
+ @user.reload
+ assert_not @user.highlights.attached?
+ end
+
test "overriding attached reader" do
@user.highlights.attach create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg")
diff --git a/activestorage/test/models/attached/one_test.rb b/activestorage/test/models/attached/one_test.rb
index 6d2b8eaaf6..33f9122644 100644
--- a/activestorage/test/models/attached/one_test.rb
+++ b/activestorage/test/models/attached/one_test.rb
@@ -427,6 +427,14 @@ class ActiveStorage::OneAttachedTest < ActiveSupport::TestCase
end
end
+ test "clearing change on reload" do
+ @user.avatar = create_blob(filename: "funky.jpg")
+ assert @user.avatar.attached?
+
+ @user.reload
+ assert_not @user.avatar.attached?
+ end
+
test "overriding attached reader" do
@user.avatar.attach create_blob(filename: "funky.jpg")