Skip to content

Commit 15ed41b

Browse files
committed
Merge pull request rails#42515
2 parents 8ee27ff + f329ae8 commit 15ed41b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

activestorage/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Attachments can be deleted after their association is no longer defined.
2+
3+
Fixes #42514
4+
5+
*Don Sisco*
6+
17
* Make `vips` the default variant processor for new apps.
28

39
See the upgrade guide for instructions on converting from `mini_magick` to `vips`. `mini_magick` is

activestorage/app/models/active_storage/attachment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def purge_dependent_blob_later
8080
end
8181

8282
def dependent
83-
record.attachment_reflections[name]&.options[:dependent]
83+
record.attachment_reflections[name]&.options&.fetch(:dependent, nil)
8484
end
8585

8686
def variants

activestorage/test/models/attachment_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ class ActiveStorage::AttachmentTest < ActiveSupport::TestCase
134134
assert_equal blob, ActiveStorage::Blob.find_signed(signed_id)
135135
end
136136

137+
test "can destroy attachment without existing relation" do
138+
blob = create_blob
139+
@user.highlights.attach(blob)
140+
attachment = @user.highlights.find_by(blob_id: blob.id)
141+
attachment.update_attribute(:name, "old_highlights")
142+
assert_nothing_raised { attachment.destroy }
143+
end
144+
137145
private
138146
def assert_blob_identified_before_owner_validated(owner, blob, content_type)
139147
validated_content_type = nil

0 commit comments

Comments
 (0)