Skip to content

Commit 435a347

Browse files
Fix rails#50005 transform_job not accepting previewables
The transform_job crahes if you want to preprocess a previewable files. This commit fixes that by using the blob's `representation` method to process variants or previews. Co-authored-by: Jonathan Hefner <[email protected]>
1 parent 4161ae7 commit 435a347

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

activestorage/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Fix `preprocessed: true` option for named variants of previewable files.
2+
3+
*Nico Wenterodt*
4+
15
* Allow accepting `service` as a proc as well in `has_one_attached` and `has_many_attached`.
26

37
*Yogesh Khater*

activestorage/app/jobs/active_storage/transform_job.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ class ActiveStorage::TransformJob < ActiveStorage::BaseJob
77
retry_on ActiveStorage::IntegrityError, attempts: 10, wait: :polynomially_longer
88

99
def perform(blob, transformations)
10-
blob.variant(transformations).processed
10+
blob.representation(transformations).processed
1111
end
1212
end

activestorage/test/jobs/transform_job_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ class ActiveStorage::TransformJobTest < ActiveJob::TestCase
1616
end
1717
end
1818

19+
test "creates variant for previewable file" do
20+
@blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf")
21+
transformations = { resize_to_limit: [100, 100] }
22+
23+
assert_changes -> { @blob.reload.preview(transformations).send(:processed?) }, from: false, to: true do
24+
perform_enqueued_jobs do
25+
ActiveStorage::TransformJob.perform_later @blob, transformations
26+
end
27+
end
28+
end
29+
1930
test "creates variant when untracked" do
2031
@was_tracking, ActiveStorage.track_variants = ActiveStorage.track_variants, false
2132
transformations = { resize_to_limit: [100, 100] }

0 commit comments

Comments
 (0)