diff options
author | George Claghorn <george.claghorn@gmail.com> | 2018-04-23 16:01:16 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-23 16:01:16 -0500 |
commit | ef5902a2f195c2be5a4e9ad0f31003774a93aa1c (patch) | |
tree | d9366b40aa381688eb828d54628d5712bc5a1a60 /activestorage/test/models | |
parent | e970d15211a8efd7349ff0e90d44d887b85793c2 (diff) | |
parent | f2e2cef15bdb31353aee2254ca2ab378979cc24a (diff) | |
download | rails-ef5902a2f195c2be5a4e9ad0f31003774a93aa1c.tar.gz rails-ef5902a2f195c2be5a4e9ad0f31003774a93aa1c.tar.bz2 rails-ef5902a2f195c2be5a4e9ad0f31003774a93aa1c.zip |
Merge pull request #32471 from janko-m/use-image_processing-gem
Use ImageProcessing gem for ActiveStorage variants
Diffstat (limited to 'activestorage/test/models')
-rw-r--r-- | activestorage/test/models/variant_test.rb | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/activestorage/test/models/variant_test.rb b/activestorage/test/models/variant_test.rb index 0f3ada25c0..e74bbc9ab4 100644 --- a/activestorage/test/models/variant_test.rb +++ b/activestorage/test/models/variant_test.rb @@ -25,13 +25,30 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase assert_match(/Gray/, image.colorspace) end - test "center-weighted crop of JPEG blob" do + test "center-weighted crop of JPEG blob using :combine_options" do + begin + ActiveStorage.variant_processor = nil + blob = create_file_blob(filename: "racecar.jpg") + variant = ActiveSupport::Deprecation.silence do + blob.variant(combine_options: { + gravity: "center", + resize: "100x100^", + crop: "100x100+0+0", + }).processed + end + assert_match(/racecar\.jpg/, variant.service_url) + + image = read_image(variant) + assert_equal 100, image.width + assert_equal 100, image.height + ensure + ActiveStorage.variant_processor = :mini_magick + end + end + + test "center-weighted crop of JPEG blob using :resize_to_fill" do blob = create_file_blob(filename: "racecar.jpg") - variant = blob.variant(combine_options: { - gravity: "center", - resize: "100x100^", - crop: "100x100+0+0", - }).processed + variant = blob.variant(resize_to_fill: [100, 100]).processed assert_match(/racecar\.jpg/, variant.service_url) image = read_image(variant) @@ -80,4 +97,20 @@ class ActiveStorage::VariantTest < ActiveSupport::TestCase variant = blob.variant(font: "a" * 10_000).processed assert_operator variant.service_url.length, :<, 525 end + + test "works for vips processor" do + begin + ActiveStorage.variant_processor = :vips + blob = create_file_blob(filename: "racecar.jpg") + variant = blob.variant(thumbnail_image: 100).processed + + image = read_image(variant) + assert_equal 100, image.width + assert_equal 67, image.height + rescue LoadError + # libvips not installed + ensure + ActiveStorage.variant_processor = :mini_magick + end + end end |