Skip to content

Commit c18bcd5

Browse files
committed
Keep VariantWithRecord API consistent with Variant
The `process` and `processed?` methods in Variant are private.
1 parent 144dd24 commit c18bcd5

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

activestorage/app/models/active_storage/variant_with_record.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,10 @@ def initialize(blob, variation)
1313
end
1414

1515
def processed
16-
process
16+
process unless processed?
1717
self
1818
end
1919

20-
def process
21-
transform_blob { |image| create_or_find_record(image: image) } unless processed?
22-
end
23-
24-
def processed?
25-
record.present?
26-
end
27-
2820
def image
2921
record&.image
3022
end
@@ -37,6 +29,14 @@ def destroy
3729
delegate :key, :url, :download, to: :image, allow_nil: true
3830

3931
private
32+
def processed?
33+
record.present?
34+
end
35+
36+
def process
37+
transform_blob { |image| create_or_find_record(image: image) }
38+
end
39+
4040
def transform_blob
4141
blob.open do |input|
4242
variation.transform(input) do |output|

activestorage/test/jobs/transform_job_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ActiveStorage::TransformJobTest < ActiveJob::TestCase
99
test "creates variant" do
1010
transformations = { resize_to_limit: [100, 100] }
1111

12-
assert_changes -> { @blob.variant(transformations).processed? }, from: false, to: true do
12+
assert_changes -> { @blob.variant(transformations).send(:processed?) }, from: false, to: true do
1313
perform_enqueued_jobs do
1414
ActiveStorage::TransformJob.perform_later @blob, transformations
1515
end

activestorage/test/models/variant_with_record_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ActiveStorage::VariantWithRecordTest < ActiveSupport::TestCase
1919
variant = blob.variant(resize_to_limit: [100, 100])
2020

2121
assert_difference -> { blob.variant_records.count }, +1 do
22-
variant.process
22+
variant.processed
2323
end
2424

2525
assert_match(/racecar\.jpg/, variant.url)
@@ -36,13 +36,13 @@ class ActiveStorage::VariantWithRecordTest < ActiveSupport::TestCase
3636
blob = create_file_blob(filename: "racecar.jpg")
3737

3838
assert_difference -> { blob.variant_records.count } do
39-
blob.variant(resize_to_limit: [100, 100]).process
39+
blob.variant(resize_to_limit: [100, 100]).processed
4040
end
4141

4242
variant = blob.variant(resize_to_limit: [100, 100])
4343

4444
assert_no_difference -> { blob.variant_records.count } do
45-
variant.process
45+
variant.processed
4646
end
4747

4848
assert_match(/racecar\.jpg/, variant.url)
@@ -54,7 +54,7 @@ class ActiveStorage::VariantWithRecordTest < ActiveSupport::TestCase
5454

5555
test "variant of a blob is on the same service" do
5656
blob = create_file_blob(filename: "racecar.jpg", service_name: "local_public")
57-
variant = blob.variant(resize_to_limit: [100, 100]).process
57+
variant = blob.variant(resize_to_limit: [100, 100]).processed
5858

5959
assert_equal "local_public", variant.image.blob.service_name
6060
end
@@ -65,12 +65,12 @@ class ActiveStorage::VariantWithRecordTest < ActiveSupport::TestCase
6565

6666
blob1 = directly_upload_file_blob(filename: "racecar.jpg")
6767
assert_difference -> { ActiveStorage::VariantRecord.count }, +1 do
68-
blob1.representation(resize_to_limit: [100, 100]).process
68+
blob1.representation(resize_to_limit: [100, 100]).processed
6969
end
7070

7171
blob2 = directly_upload_file_blob(filename: "racecar_rotated.jpg")
7272
assert_difference -> { ActiveStorage::VariantRecord.count }, +1 do
73-
blob2.representation(resize_to_limit: [100, 100]).process
73+
blob2.representation(resize_to_limit: [100, 100]).processed
7474
end
7575

7676
assert_no_difference -> { ActiveStorage::VariantRecord.count } do
@@ -126,12 +126,12 @@ class ActiveStorage::VariantWithRecordTest < ActiveSupport::TestCase
126126

127127
blob1 = directly_upload_file_blob(filename: "racecar.jpg")
128128
assert_difference -> { ActiveStorage::VariantRecord.count }, +1 do
129-
blob1.representation(resize_to_limit: [100, 100]).process
129+
blob1.representation(resize_to_limit: [100, 100]).processed
130130
end
131131

132132
blob2 = directly_upload_file_blob(filename: "racecar_rotated.jpg")
133133
assert_difference -> { ActiveStorage::VariantRecord.count }, +1 do
134-
blob2.representation(resize_to_limit: [100, 100]).process
134+
blob2.representation(resize_to_limit: [100, 100]).processed
135135
end
136136

137137
assert_no_difference -> { ActiveStorage::VariantRecord.count } do

0 commit comments

Comments
 (0)