Keep VariantWithRecord API consistent with Variant
The `process` and `processed?` methods in Variant are private.
This commit is contained in:
parent
144dd24c05
commit
c18bcd5828
@ -13,18 +13,10 @@ def initialize(blob, variation)
|
||||
end
|
||||
|
||||
def processed
|
||||
process
|
||||
process unless processed?
|
||||
self
|
||||
end
|
||||
|
||||
def process
|
||||
transform_blob { |image| create_or_find_record(image: image) } unless processed?
|
||||
end
|
||||
|
||||
def processed?
|
||||
record.present?
|
||||
end
|
||||
|
||||
def image
|
||||
record&.image
|
||||
end
|
||||
@ -37,6 +29,14 @@ def destroy
|
||||
delegate :key, :url, :download, to: :image, allow_nil: true
|
||||
|
||||
private
|
||||
def processed?
|
||||
record.present?
|
||||
end
|
||||
|
||||
def process
|
||||
transform_blob { |image| create_or_find_record(image: image) }
|
||||
end
|
||||
|
||||
def transform_blob
|
||||
blob.open do |input|
|
||||
variation.transform(input) do |output|
|
||||
|
@ -9,7 +9,7 @@ class ActiveStorage::TransformJobTest < ActiveJob::TestCase
|
||||
test "creates variant" do
|
||||
transformations = { resize_to_limit: [100, 100] }
|
||||
|
||||
assert_changes -> { @blob.variant(transformations).processed? }, from: false, to: true do
|
||||
assert_changes -> { @blob.variant(transformations).send(:processed?) }, from: false, to: true do
|
||||
perform_enqueued_jobs do
|
||||
ActiveStorage::TransformJob.perform_later @blob, transformations
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ class ActiveStorage::VariantWithRecordTest < ActiveSupport::TestCase
|
||||
variant = blob.variant(resize_to_limit: [100, 100])
|
||||
|
||||
assert_difference -> { blob.variant_records.count }, +1 do
|
||||
variant.process
|
||||
variant.processed
|
||||
end
|
||||
|
||||
assert_match(/racecar\.jpg/, variant.url)
|
||||
@ -36,13 +36,13 @@ class ActiveStorage::VariantWithRecordTest < ActiveSupport::TestCase
|
||||
blob = create_file_blob(filename: "racecar.jpg")
|
||||
|
||||
assert_difference -> { blob.variant_records.count } do
|
||||
blob.variant(resize_to_limit: [100, 100]).process
|
||||
blob.variant(resize_to_limit: [100, 100]).processed
|
||||
end
|
||||
|
||||
variant = blob.variant(resize_to_limit: [100, 100])
|
||||
|
||||
assert_no_difference -> { blob.variant_records.count } do
|
||||
variant.process
|
||||
variant.processed
|
||||
end
|
||||
|
||||
assert_match(/racecar\.jpg/, variant.url)
|
||||
@ -54,7 +54,7 @@ class ActiveStorage::VariantWithRecordTest < ActiveSupport::TestCase
|
||||
|
||||
test "variant of a blob is on the same service" do
|
||||
blob = create_file_blob(filename: "racecar.jpg", service_name: "local_public")
|
||||
variant = blob.variant(resize_to_limit: [100, 100]).process
|
||||
variant = blob.variant(resize_to_limit: [100, 100]).processed
|
||||
|
||||
assert_equal "local_public", variant.image.blob.service_name
|
||||
end
|
||||
@ -65,12 +65,12 @@ class ActiveStorage::VariantWithRecordTest < ActiveSupport::TestCase
|
||||
|
||||
blob1 = directly_upload_file_blob(filename: "racecar.jpg")
|
||||
assert_difference -> { ActiveStorage::VariantRecord.count }, +1 do
|
||||
blob1.representation(resize_to_limit: [100, 100]).process
|
||||
blob1.representation(resize_to_limit: [100, 100]).processed
|
||||
end
|
||||
|
||||
blob2 = directly_upload_file_blob(filename: "racecar_rotated.jpg")
|
||||
assert_difference -> { ActiveStorage::VariantRecord.count }, +1 do
|
||||
blob2.representation(resize_to_limit: [100, 100]).process
|
||||
blob2.representation(resize_to_limit: [100, 100]).processed
|
||||
end
|
||||
|
||||
assert_no_difference -> { ActiveStorage::VariantRecord.count } do
|
||||
@ -126,12 +126,12 @@ class ActiveStorage::VariantWithRecordTest < ActiveSupport::TestCase
|
||||
|
||||
blob1 = directly_upload_file_blob(filename: "racecar.jpg")
|
||||
assert_difference -> { ActiveStorage::VariantRecord.count }, +1 do
|
||||
blob1.representation(resize_to_limit: [100, 100]).process
|
||||
blob1.representation(resize_to_limit: [100, 100]).processed
|
||||
end
|
||||
|
||||
blob2 = directly_upload_file_blob(filename: "racecar_rotated.jpg")
|
||||
assert_difference -> { ActiveStorage::VariantRecord.count }, +1 do
|
||||
blob2.representation(resize_to_limit: [100, 100]).process
|
||||
blob2.representation(resize_to_limit: [100, 100]).processed
|
||||
end
|
||||
|
||||
assert_no_difference -> { ActiveStorage::VariantRecord.count } do
|
||||
|
Loading…
Reference in New Issue
Block a user