Skip to content

Commit

Permalink
Merge pull request #50006 from nicowenterodt/preprocess_previewables
Browse files Browse the repository at this point in the history
Fix #50005 transform_job not accepting previewables

(cherry picked from commit 17c82c6)
  • Loading branch information
jonathanhefner committed Nov 11, 2023
1 parent 4148890 commit bbe30c8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions activestorage/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* Fix `preprocessed: true` option for named variants of previewable files.

*Nico Wenterodt*


## Rails 7.1.2 (November 10, 2023) ##

* No changes.
Expand Down
2 changes: 1 addition & 1 deletion activestorage/app/jobs/active_storage/transform_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class ActiveStorage::TransformJob < ActiveStorage::BaseJob
retry_on ActiveStorage::IntegrityError, attempts: 10, wait: :polynomially_longer

def perform(blob, transformations)
blob.variant(transformations).processed
blob.representation(transformations).processed
end
end
11 changes: 11 additions & 0 deletions activestorage/test/jobs/transform_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ class ActiveStorage::TransformJobTest < ActiveJob::TestCase
end
end

test "creates variant for previewable file" do
@blob = create_file_blob(filename: "report.pdf", content_type: "application/pdf")
transformations = { resize_to_limit: [100, 100] }

assert_changes -> { @blob.reload.preview(transformations).send(:processed?) }, from: false, to: true do
perform_enqueued_jobs do
ActiveStorage::TransformJob.perform_later @blob, transformations
end
end
end

test "creates variant when untracked" do
@was_tracking, ActiveStorage.track_variants = ActiveStorage.track_variants, false
transformations = { resize_to_limit: [100, 100] }
Expand Down

0 comments on commit bbe30c8

Please sign in to comment.