首页 > 解决方案 > CarrierWave config.enable_processing = false 在 Rspec 的测试模式下不起作用

问题描述

当我使用以下工厂运行 Rspec 测试时,它会在 public/test/company/ 的本地存储库中创建文件

载波.rb

if Rails.env.test?
  CarrierWave.configure do |config|
    config.storage = :file
    config.enable_processing = false
  end
else
...
end

当我明确禁用处理时,我不明白为什么它会在测试模式下创建文件。我想在不处理和存储图像的情况下运行我的测试套件。关于改变什么的任何提示?

image_uploader.rb

class ImageUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  def store_dir
    "#{model.class.to_s.underscore}/#{model.id}"
  end

  process resize_to_fit: [250, 250]

  version :thumb do
    process resize_to_fit: [75, 75]
  end

  def extension_allowlist
    %w(jpg jpeg gif png svg)
  end

  def filename
    @name ||= "#{mounted_as}.png" if original_filename.present?
  end
end

工厂.rb

factory :company do
  name  { 'stackoverflow' }
  logo  { File.new(Rails.root.join('spec', 'fixtures', 'companies', "1.png")) }
end

标签: ruby-on-railscarrierwave

解决方案


推荐阅读