mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #32317 from dwightwatson/32247
Flip the order of the after_create callbacks
This commit is contained in:
commit
1518457a67
3 changed files with 24 additions and 4 deletions
|
@ -14,7 +14,7 @@ class ActiveStorage::Attachment < ActiveRecord::Base
|
|||
|
||||
delegate_missing_to :blob
|
||||
|
||||
after_create_commit :identify_blob, :analyze_blob_later
|
||||
after_create_commit :analyze_blob_later, :identify_blob
|
||||
|
||||
# Synchronously purges the blob (deletes it from the configured service) and destroys the attachment.
|
||||
def purge
|
||||
|
|
|
@ -136,9 +136,7 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test "identify newly-attached, directly-uploaded blob" do
|
||||
# Simulate a direct upload.
|
||||
blob = create_blob_before_direct_upload(filename: "racecar.jpg", content_type: "application/octet-stream", byte_size: 1124062, checksum: "7GjDDNEQb4mzMzsW+MS0JQ==")
|
||||
ActiveStorage::Blob.service.upload(blob.key, file_fixture("racecar.jpg").open)
|
||||
blob = directly_upload_file_blob(content_type: "application/octet-stream")
|
||||
|
||||
@user.avatar.attach(blob)
|
||||
|
||||
|
@ -146,6 +144,18 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase
|
|||
assert_predicate @user.avatar, :identified?
|
||||
end
|
||||
|
||||
test "identify and analyze newly-attached, directly-uploaded blob" do
|
||||
blob = directly_upload_file_blob(content_type: "application/octet-stream")
|
||||
|
||||
perform_enqueued_jobs do
|
||||
@user.avatar.attach blob
|
||||
end
|
||||
|
||||
assert_equal true, @user.avatar.reload.metadata[:identified]
|
||||
assert_equal 4104, @user.avatar.metadata[:width]
|
||||
assert_equal 2736, @user.avatar.metadata[:height]
|
||||
end
|
||||
|
||||
test "identify newly-attached blob only once" do
|
||||
blob = create_file_blob
|
||||
assert_predicate blob, :identified?
|
||||
|
|
|
@ -54,6 +54,16 @@ class ActiveSupport::TestCase
|
|||
ActiveStorage::Blob.create_before_direct_upload! filename: filename, byte_size: byte_size, checksum: checksum, content_type: content_type
|
||||
end
|
||||
|
||||
def directly_upload_file_blob(filename: "racecar.jpg", content_type: "image/jpeg")
|
||||
file = file_fixture(filename)
|
||||
byte_size = file.size
|
||||
checksum = Digest::MD5.file(file).base64digest
|
||||
|
||||
create_blob_before_direct_upload(filename: filename, byte_size: byte_size, checksum: checksum, content_type: content_type).tap do |blob|
|
||||
ActiveStorage::Blob.service.upload(blob.key, file.open)
|
||||
end
|
||||
end
|
||||
|
||||
def read_image(blob_or_variant)
|
||||
MiniMagick::Image.open blob_or_variant.service.send(:path_for, blob_or_variant.key)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue