From 7644a581c2e1a27da4c39e9518c0844e098f7301 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Wed, 26 Jul 2017 14:58:59 -0400 Subject: Check variant image properties directly --- test/controllers/variants_controller_test.rb | 5 ++++- test/fixtures/files/racecar-100x100-monochrome.jpg | Bin 27586 -> 0 bytes test/fixtures/files/racecar-100x100.jpg | Bin 29446 -> 0 bytes test/models/variant_test.rb | 14 +++++++++----- test/test_helper.rb | 20 +------------------- 5 files changed, 14 insertions(+), 25 deletions(-) delete mode 100644 test/fixtures/files/racecar-100x100-monochrome.jpg delete mode 100644 test/fixtures/files/racecar-100x100.jpg diff --git a/test/controllers/variants_controller_test.rb b/test/controllers/variants_controller_test.rb index 83b00a132f..ec8103718b 100644 --- a/test/controllers/variants_controller_test.rb +++ b/test/controllers/variants_controller_test.rb @@ -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 diff --git a/test/fixtures/files/racecar-100x100-monochrome.jpg b/test/fixtures/files/racecar-100x100-monochrome.jpg deleted file mode 100644 index 39e683747e..0000000000 Binary files a/test/fixtures/files/racecar-100x100-monochrome.jpg and /dev/null differ diff --git a/test/fixtures/files/racecar-100x100.jpg b/test/fixtures/files/racecar-100x100.jpg deleted file mode 100644 index 2a515a4912..0000000000 Binary files a/test/fixtures/files/racecar-100x100.jpg and /dev/null differ diff --git a/test/models/variant_test.rb b/test/models/variant_test.rb index 3d890dfc0f..f06bd39a10 100644 --- a/test/models/variant_test.rb +++ b/test/models/variant_test.rb @@ -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 diff --git a/test/test_helper.rb b/test/test_helper.rb index f531cb8079..6c5d8f85ce 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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) -- cgit v1.2.3