mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Orphaned attachment relationship safe navigation
closes #42514 - Adds Test for Orphaned Attachment Relationship - Adds Changelog entry (with issue number)
This commit is contained in:
parent
acee501edd
commit
f329ae8886
3 changed files with 15 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
* Attachments can be deleted after their association is no longer defined.
|
||||
|
||||
Fixes #42514
|
||||
|
||||
*Don Sisco*
|
||||
|
||||
* Allow to detach an attachment when record is not persisted
|
||||
|
||||
*Jacopo Beschi*
|
||||
|
|
|
@ -74,7 +74,7 @@ class ActiveStorage::Attachment < ActiveStorage::Record
|
|||
end
|
||||
|
||||
def dependent
|
||||
record.attachment_reflections[name]&.options[:dependent]
|
||||
record.attachment_reflections[name]&.options&.fetch(:dependent, nil)
|
||||
end
|
||||
|
||||
def variants
|
||||
|
|
|
@ -134,6 +134,14 @@ class ActiveStorage::AttachmentTest < ActiveSupport::TestCase
|
|||
assert_equal blob, ActiveStorage::Blob.find_signed(signed_id)
|
||||
end
|
||||
|
||||
test "can destroy attachment without existing relation" do
|
||||
blob = create_blob
|
||||
@user.highlights.attach(blob)
|
||||
attachment = @user.highlights.find_by(blob_id: blob.id)
|
||||
attachment.update_attribute(:name, "old_highlights")
|
||||
assert_nothing_raised { attachment.destroy }
|
||||
end
|
||||
|
||||
private
|
||||
def assert_blob_identified_before_owner_validated(owner, blob, content_type)
|
||||
validated_content_type = nil
|
||||
|
|
Loading…
Reference in a new issue