1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activestorage/test/models
Jonathan Hefner 6aa26c30e2
Identify directly-uploaded blobs before saving the associated record
An Active Storage `Blob` must be identified before it can be reliably
validated.  For direct uploads, a `Blob` is identified when it is
attached, rather than when it is created.

Before this commit, the sequence of events when attaching a `Blob` was:

1. Find the `Blob`.
2. Assign the `Blob` to an `Attachment`.
3. Save the owner record.
4. Save the `Attachment`.
5. Identify the `Blob`'s true `content_type` from its file.
6. Save the `Blob`.

This meant that the owner record's validations might not see the
`Blob`'s true `content_type`.

After this commit, the sequence of events will be:

1. Find the `Blob`.
2. Identify the `Blob`'s true `content_type` from its file.
3. Assign the `Blob` to an `Attachment`.
4. Save the owner record.
5. Save the `Attachment`.
6. Save the `Blob`.

Thus the `Blob`'s true `content_type` will be available when running the
owner record's validations.
2020-08-11 18:08:09 -04:00
..
attached Fix attaching blobs via nested attributes 2020-08-04 00:26:27 -04:00
attachment_test.rb Identify directly-uploaded blobs before saving the associated record 2020-08-11 18:08:09 -04:00
blob_test.rb Identify directly-uploaded blobs before saving the associated record 2020-08-11 18:08:09 -04:00
filename_test.rb Enable Performance/UnfreezeString cop 2018-09-23 08:56:55 +09:00
presence_validation_test.rb Store newly-uploaded files on save rather than assignment 2018-07-07 23:25:33 -04:00
preview_test.rb Store previews in the same service as the original blob 2019-12-20 15:06:03 -05:00
reflection_test.rb Allow configure services for individual attachments 2019-10-01 21:24:05 +03:00
representation_test.rb Extract Analyzable and Representable concerns 2018-01-10 12:12:04 -05:00
variant_test.rb fix misleading variant test 2020-07-29 16:32:14 -05:00
variant_with_record_test.rb Make sure variant is created on the same service 2019-12-06 22:02:07 -05:00