What is the good way to store images for testing upload and removal ?
I wrote some fixtures for my products.
Product has attached images which are stored in a folder
spec/fixtures/product/attachments/pull_noir_1.jpg
When I launch the delete a product spec, the image is removed from the folder, and then, the next spec fails, because the image can't be found (Yes it has been removed)... public/uploads/product/attachments/683902633/pull_rouge_1.jpg
How am I supposed to set my uploader and where should I keep the images?
Here are some of my fixtures 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
My attachement_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
EDIT I re added the
#{model.id}
Still facing the same probleme
The failures
ActionController::RoutingError:
No route matches [GET] /uploads/product/attachments/683902633/pull_rouge_1.jpg
I don't think you need my specs but feel free to ask if I have to update the question with more code.
My rails_helper was missing this:
CarrierWave.configure do |config|
config.root = Rails.root.join('spec/fixtures')
config.cache_only = true
config.enable_processing = false
config.base_path = "/"
end