Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails with ActiveRecord and CarrierWave uploader #46

Open
SkyWriter opened this issue Aug 11, 2023 · 0 comments
Open

Fails with ActiveRecord and CarrierWave uploader #46

SkyWriter opened this issue Aug 11, 2023 · 0 comments

Comments

@SkyWriter
Copy link

SkyWriter commented Aug 11, 2023

Greetings, and thank you so much for all the work you guys put into the gem!

Now to the business... I have the following kind of model:

class VaultDoc < BaseModel
  mount_uploader :document, VaultDocUploader

  validates :document,
            file_size: { less_than_or_equal_to: 25.megabytes },
            file_content_type: { allow: ->(record) { record.allow_content_types }, mode: :strict },
            on: :create
end

With the following kind of VaultDocUploader:

class VaultDocUploader < CarrierWave::Uploader::Base
  include CarrierWave::RMagick
  
  storage :file

  version :thumb, if: :thumbable? do
    process resize_to_fit: [315, 445], if: :image?
    process pdf_preview: [315, 445], if: :pdf?
  end

  def thumbable?(file)
    image?(file) || pdf?(file)
  end

  def image?(file)
    file.content_type.include? 'image'
  end

  def pdf?(file)
    file.content_type == 'application/pdf'
  end
end

(There's a lot more to it, but seems to be irrelevant)

Validation raises an exception when I'm trying to create an instance of VaultDoc during tests:

NoMethodError: undefined method `eof?' for #<VaultDocUploader:0x00007feaa4a46168 @model=#<VaultDoc id: nil ...>, @mounted_as=:document, @staged=true, @file=#<CarrierWave::SanitizedFile:0x000000000d962d20 @file="/app/tmp/vault-cache/1691776062-272660352770104-0001-2145/logo.png", @original_filename="logo.png", @content_type="image/png", @content=nil>, @filename="logo.png", @cache_id="1691776062-272660352770104-0001-2145", @identifier=nil, @versions={:thumb=>#<VaultDocUploader::Uploader22380:0x000000000d960750 @model=#<VaultDoc id: nil, document: nil, state: "uploaded", title: "My Document", original_filename: nil, thumb_present: true, created_at: nil, deleted_at: nil, vault_keeper_id: "93419cd4-87ca-42ec-8ae4-ecfda99b7620">, @mounted_as=:document, @staged=true, @file=#<CarrierWave::SanitizedFile:0x000000000d96a8e0 @file="/app/tmp/vault-cache/1691776062-272660352770104-0001-2145/thumb_logo.png", @original_filename="logo.png", @content_type="image/png", @content=nil>, @filename="logo.png", @cache_id="1691776062-272660352770104-0001-2145", @identifier=nil, @versions={}, @format=nil, @parent_version=#<VaultDocUploader:0x00007feaa4a46168 ...>, @parent_cache_id="1691776062-272660352770104-0001-2145", @original_filename="logo.png", @geometry={:width=>315, :height=>315}, @cache_storage=#<CarrierWave::Storage::File:0x000000000a47d088 @uploader=#<VaultDocUploader::Uploader22380:0x000000000d960750 ...>, @cache_called=nil>>}, @format=nil, @original_filename="logo.png", @cache_storage=#<CarrierWave::Storage::File:0x000000000d961628 @uploader=#<VaultDocUploader:0x00007feaa4a46168 ...>, @cache_called=nil>> # /gems/file_validators-3.0.0/lib/file_validators/mime_type_analyzer.rb:27:in `extract_with_file' # /gems/file_validators-3.0.0/lib/file_validators/mime_type_analyzer.rb:16:in `call' # /gems/file_validators-3.0.0/lib/file_validators/validators/file_content_type_validator.rb:60:in `get_content_type'

This used to work on v2.3.0 and worked up to v3.0.0.beta1 (inclusive), whereas v3.0.0.beta2 and v3.0.0 (release) don't work.

Here are my thoughts on what's happened: https://github.com/musaffa/file_validators/pull/32/files#r1291636492

@SkyWriter SkyWriter changed the title Fails with ActiveRecord and CarrierWave uploader during RSpec run Fails with ActiveRecord and CarrierWave uploader Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant