存储用于测试上传和删除的图像的好方法是什么?

时间:2019-01-16 23:50:55

标签: ruby-on-rails rspec carrierwave fixtures

存储用于测试上传和删除的图像的好方法是什么?

  • 我正在使用Carrierwave上传我的图片
  • 我的功能规格的RSpec

我为产品写了一些灯具。

产品已附加存储在文件夹中的图像 spec/fixtures/product/attachments/pull_noir_1.jpg

当我启动删除产品规格时,该图像将从文件夹中删除,然后下一个规格失败,因为找不到该图像(是的,它已被删除) ... public/uploads/product/attachments/683902633/pull_rouge_1.jpg

我应该如何设置我的上传器,应该在哪里保存图片?

这是我的一些固定装置 products.yml

warm_sweat:
  title: Gros pull
  price: 30
  color: Noir
  category: pull
  user: nelly
  attachments: pull_rouge_1.jpg

black_k_l:
  title: Pull Kenzaro
  price: 20
  color: Noir
  category: pull
  user: nelly
  attachments: pull_noir_1.jpg

我的 attachment_uploader.rb

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

  storage :file

  if Rails.env.production?
    storage :fog
  else
    storage :file
  end

  version :thumb do
     process resize_to_fill: [280, 280]
   end

  def default_url(*args)
     "/images/fallback/" + [version_name, "random.jpg"].compact.join('_')
   end

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

  def extension_white_list
    %w(jpg jpeg gif png)
  end
end
  

编辑我重新添加了#{model.id}仍然面临同样的问题

失败

 ActionController::RoutingError:
           No route matches [GET] /uploads/product/attachments/683902633/pull_rouge_1.jpg

我认为您不需要我的规格,但可以随时询问我是否必须使用更多代码来更新问题。

1 个答案:

答案 0 :(得分:0)

我的rails_helper缺少此信息:

CarrierWave.configure do |config|
  config.root              = Rails.root.join('spec/fixtures')
  config.cache_only        = true
  config.enable_processing = false
  config.base_path         = "/"
end
相关问题