mirror of https://github.com/rails/rails
Merge pull request #49195 from p8/activestorage/variant-interface
Keep VariantWithRecord API consistent with Variant
This commit is contained in:
commit
099f979dc7
|
@ -7,6 +7,7 @@
|
|||
class ActiveStorage::VariantWithRecord
|
||||
attr_reader :blob, :variation
|
||||
delegate :service, to: :blob
|
||||
delegate :content_type, to: :variation
|
||||
|
||||
def initialize(blob, variation)
|
||||
@blob, @variation = blob, ActiveStorage::Variation.wrap(variation)
|
||||
|
@ -21,6 +22,10 @@ class ActiveStorage::VariantWithRecord
|
|||
record&.image
|
||||
end
|
||||
|
||||
def filename
|
||||
ActiveStorage::Filename.new "#{blob.filename.base}.#{variation.format.downcase}"
|
||||
end
|
||||
|
||||
# Destroys record and deletes file from service.
|
||||
def destroy
|
||||
record&.destroy
|
||||
|
|
|
@ -23,6 +23,8 @@ class ActiveStorage::VariantWithRecordTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
assert_match(/racecar\.jpg/, variant.url)
|
||||
assert_equal "racecar.jpg", variant.filename.to_s
|
||||
assert_equal "image/jpeg", variant.content_type
|
||||
|
||||
image = read_image(variant.image)
|
||||
assert_equal 100, image.width
|
||||
|
|
Loading…
Reference in New Issue