forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't enqueue jobs to process a preview image if no variant requires it
This follows up on rails#51030, that introduces a behaviour change for previewable attachments that don't specify any variants at all or no variants that require pre-processing via `TransformJob`. Before, when no variant required pre-processing, Attachment#transform_variants_later didn't do anything. Now, a `ActiveStorage::PreviewImageJob` is enqueued with the attachment's blob and a empty array.
- Loading branch information
Showing
6 changed files
with
62 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require "database/setup" | ||
|
||
class ActiveStorage::PreviewImageJobTest < ActiveJob::TestCase | ||
setup do | ||
@blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf") | ||
@transformation = { resize_to_limit: [ 100, 100 ] } | ||
end | ||
|
||
test "creates preview" do | ||
assert_changes -> { @blob.preview_image.attached? }, from: false, to: true do | ||
ActiveStorage::PreviewImageJob.perform_now @blob, [ @transformation ] | ||
end | ||
end | ||
|
||
test "enqueues transform variant jobs" do | ||
assert_enqueued_with job: ActiveStorage::TransformJob, args: [ @blob, @transformation ] do | ||
ActiveStorage::PreviewImageJob.perform_now @blob, [ @transformation ] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters