aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/test/models/attached/many_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* [ActiveStorage] Ensure that the `_blob` association is properly loaded when ↵Abhishek Chandrasekhar2019-02-261-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | attaching `::One` Consider a model with `One` and `Many` attachments configured: class User < ActiveRecord::Base has_one_attached :avatar has_many_attached :highlights end === One Attachment After attaching `One` attachment (`:avatar`), we can see that the associated `_blob` record (`:avatar_blob`) still returns as `nil`. user.avatar.attach(blob) user.avatar_attachment.present? => true user.avatar_blob.present? => false # Incorrect! This is a false negative. It happens because after the attachment and blob are built: 1. The record already has its `_blob` association loaded, as `nil` 2. the `::Attachment` is associated with the record but the `::Blob` only gets associated with the `::Attachment`, not the record itself In reality, the blob does in fact exist. We can verify this as follows: user.avatar.attach(blob) user.avatar_attachment.blob.present? => true # Blob does exist! The fix in this change is to simply assign the `::Blob` when assigning the `::Attachment`. After this fix is applied, we correctly observe: user.avatar.attach(blob) user.avatar_attachment.present? => true user.avatar_blob.present? => true # Woohoo! === Many Attachments We don't see this issue with `Many` attachments because the `_blob` association is already loaded as part of attaching more/newer blobs. user.highlights.attach(blob) user.highlights_attachments.any? => true user.highlights_blobs.any? => true
* Module#{define_method,alias_method,undef_method,remove_method} become public ↵Ryuta Kamizono2018-12-211-1/+1
| | | | | | since Ruby 2.5 https://bugs.ruby-lang.org/issues/14133
* Ignore ActiveRecord::InvalidForeignKey in ActiveStorage::Blob#purgeJasper Martin2018-07-261-0/+56
| | | Do nothing instead of raising an error when it’s called on an attached blob.
* Add a foreign-key constraint to the attachments table for blobsGeorge Claghorn2018-07-191-1/+1
|
* Remove unnecessary tapGeorge Claghorn2018-07-171-10/+8
|
* Fix replacing many attachments via assign and attachGeorge Claghorn2018-07-171-0/+36
|
* Correct test nameGeorge Claghorn2018-07-161-1/+1
|
* Fix that successive ActiveStorage::Attached::Many#attach calls would ↵George Claghorn2018-07-161-26/+11
| | | | overwrite previous attachments
* Test removing attachments via #attachGeorge Claghorn2018-07-161-8/+32
|
* Clear attachment changes on reloadGeorge Claghorn2018-07-131-0/+8
|
* Implement ActiveStorage::Attached::{One,Many}#attach in terms of changesGeorge Claghorn2018-07-131-9/+88
|
* Fix that detaching could purgeGeorge Claghorn2018-07-131-0/+17
|
* Fix analyzing new blobs from uploaded files on attachGeorge Claghorn2018-07-131-0/+58
|
* Raise an ArgumentError instead of a RuntimeErrorGeorge Claghorn2018-07-081-1/+1
|
* Store newly-uploaded files on save rather than assignmentGeorge Claghorn2018-07-071-0/+335