mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Check variant image properties directly
This commit is contained in:
parent
0605ed9a8e
commit
7644a581c2
5 changed files with 14 additions and 25 deletions
|
@ -18,6 +18,9 @@ class ActiveStorage::VariantsControllerTest < ActionController::TestCase
|
|||
variation_key: ActiveStorage::Variation.encode(resize: "100x100") }
|
||||
|
||||
assert_redirected_to /racecar.jpg\?disposition=inline/
|
||||
assert_equal_image_dimensions "racecar-100x100.jpg", @blob.variant(resize: "100x100")
|
||||
|
||||
image = read_image_variant(@blob.variant(resize: "100x100"))
|
||||
assert_equal 100, image.width
|
||||
assert_equal 67, image.height
|
||||
end
|
||||
end
|
||||
|
|
BIN
test/fixtures/files/racecar-100x100-monochrome.jpg
vendored
BIN
test/fixtures/files/racecar-100x100-monochrome.jpg
vendored
Binary file not shown.
Before Width: | Height: | Size: 27 KiB |
BIN
test/fixtures/files/racecar-100x100.jpg
vendored
BIN
test/fixtures/files/racecar-100x100.jpg
vendored
Binary file not shown.
Before Width: | Height: | Size: 29 KiB |
|
@ -8,16 +8,20 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase
|
|||
|
||||
test "resized variation" do
|
||||
variant = @blob.variant(resize: "100x100").processed
|
||||
|
||||
assert_match /racecar.jpg/, variant.service_url
|
||||
assert_equal_image_dimensions "racecar-100x100.jpg", variant
|
||||
|
||||
image = read_image_variant(variant)
|
||||
assert_equal 100, image.width
|
||||
assert_equal 67, image.height
|
||||
end
|
||||
|
||||
test "resized and monochrome variation" do
|
||||
variant = @blob.variant(resize: "100x100", monochrome: true).processed
|
||||
|
||||
assert_match /racecar.jpg/, variant.service_url
|
||||
assert_equal_image_dimensions "racecar-100x100-monochrome.jpg", variant
|
||||
assert_equal_image_colorspace "racecar-100x100-monochrome.jpg", variant
|
||||
|
||||
image = read_image_variant(variant)
|
||||
assert_equal 100, image.width
|
||||
assert_equal 67, image.height
|
||||
assert_equal "Grayscale", image.colorspace
|
||||
end
|
||||
end
|
||||
|
|
|
@ -44,28 +44,10 @@ class ActiveSupport::TestCase
|
|||
io: file_fixture(filename).open,
|
||||
filename: filename, content_type: content_type
|
||||
end
|
||||
|
||||
|
||||
def create_blob_before_direct_upload(filename: "hello.txt", byte_size:, checksum:, content_type: "text/plain")
|
||||
ActiveStorage::Blob.create_before_direct_upload! filename: filename, byte_size: byte_size, checksum: checksum, content_type: content_type
|
||||
end
|
||||
|
||||
|
||||
def assert_equal_image_dimensions(fixture_filename, variant)
|
||||
expected_image, actual_image = read_image_fixture(fixture_filename), read_image_variant(variant)
|
||||
|
||||
assert_equal expected_image.width, actual_image.width
|
||||
assert_equal expected_image.height, actual_image.height
|
||||
end
|
||||
|
||||
def assert_equal_image_colorspace(fixture_filename, variant)
|
||||
expected_image, actual_image = read_image_fixture(fixture_filename), read_image_variant(variant)
|
||||
|
||||
assert_equal expected_image.colorspace, actual_image.colorspace
|
||||
end
|
||||
|
||||
def read_image_fixture(fixture_filename)
|
||||
MiniMagick::Image.open file_fixture(fixture_filename)
|
||||
end
|
||||
|
||||
def read_image_variant(variant)
|
||||
MiniMagick::Image.open variant.service.send(:path_for, variant.key)
|
||||
|
|
Loading…
Reference in a new issue