active_storage_validations icon indicating copy to clipboard operation
active_storage_validations copied to clipboard

Test matchers give MiniMagick::Error

Open vccoffey opened this issue 3 years ago • 1 comments

The model:

class ContentImage < ApplicationRecord
  has_one_attached :image

  validates :image,
            attached: true,
            content_type: [:png, :jpg, :jpeg, :gif],
            size: { less_than: 20.megabytes },
            dimension: { width: { min: 640 } }
end

the tests

require "spec_helper"
describe ContentImage do
  it { is_expected.to validate_content_type_of(:image).allowing(:gif, :jpg, :png) }
  it { is_expected.to validate_content_type_of(:image).rejecting(:html, :text, :pdf) }
  it { is_expected.to validate_dimensions_of(:image).width_min(640) }
  it { is_expected.to validate_size_of(:image).less_than(20.megabytes) }
end

gives errors:

  1) ContentImage should validate the content types allowed on attachment image
     Failure/Error: it { is_expected.to validate_content_type_of(:image).allowing(:gif, :jpg, :png) }
     
     MiniMagick::Error:
       `identify -format %[orientation] /var/folders/vk/ptccmv4j3kv1krwhz2k7xy7w0000gn/T/ActiveStorage20210323-22180-q4kkxa.gif[0]` failed with error:
       identify: improper image header `/var/folders/vk/ptccmv4j3kv1krwhz2k7xy7w0000gn/T/ActiveStorage20210323-22180-q4kkxa.gif' @ error/gif.c/ReadGIFImage/1028.


  2) ContentImage should validate file size of image
     Failure/Error: it { is_expected.to validate_size_of(:image).less_than(20.megabytes) }
     
     MiniMagick::Error:
       `identify -format %[orientation] /var/folders/vk/ptccmv4j3kv1krwhz2k7xy7w0000gn/T/ActiveStorage20210323-22180-1gnvv0v.png[0]` failed with error:
       identify: improper image header `/var/folders/vk/ptccmv4j3kv1krwhz2k7xy7w0000gn/T/ActiveStorage20210323-22180-1gnvv0v.png' @ error/png.c/ReadPNGImage/4283.

vccoffey avatar Mar 24 '21 02:03 vccoffey

Same error here, using Rails 5.2.6, every test fails with the improper image header thing !

svgr-slth avatar Oct 11 '21 13:10 svgr-slth

Hi @vccoffey & @svgr-slth, I reviewing all the issues of the gem, were you able to solve this issue? I found that I might be due to the version of imagemagik (MiniMagick uses it) you are using on your OS / container (as stated here -> updating imagemagik from 7.0.5-4 to 7.0.7-24 solved the issue)

Mth0158 avatar Dec 01 '23 16:12 Mth0158