Created
November 21, 2011 13:33
-
-
Save terut/1382625 to your computer and use it in GitHub Desktop.
Clean up carrierwave's files for rspec.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.configure do |config| | |
# ... | |
config.after(:all) do | |
if Rails.env.test? | |
FileUtils.rm_rf(Dir["#{Rails.root}/spec/support/uploads"]) | |
end | |
end | |
end | |
# put logic in this file or initalizer/carrierwave.rb | |
if defined?(CarrierWave) | |
CarrierWave::Uploader::Base.descendants.each do |klass| | |
next if klass.anonymous? | |
klass.class_eval do | |
def cache_dir | |
"#{Rails.root}/spec/support/uploads/tmp" | |
end | |
def store_dir | |
"#{Rails.root}/spec/support/uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" | |
end | |
end | |
end | |
end |
It worked for me in this way:
if defined?(CarrierWave)
CarrierWave::Uploader::Base.descendants.each do |klass|
next if klass.anonymous?
klass.class_eval do
def store_dir
"test_uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
def cache_dir
"test_uploads/tmp"
end
end
end
end
config.after(:all) do
if Rails.env.test?
FileUtils.rm_rf(Rails.root + "public/test_uploads")
end
end
Woohoo! Thanks @gbpereira!
This was the line that I needed before the if defined?
(putting here for posterity):
Dir["#{Rails.root}/app/uploaders/*.rb"].each { |file| require file }
I'm use carrierwave (2.0.1)
with rails 6.0.0 and it doesn't work for me.
My solution:
initalizer/carrierwave.rb
CarrierWave.configure do |config|
config.asset_host = ActionController::Base.asset_host
end
if Rails.env.test?
CarrierWave.configure do |config|
config.root = Rails.root.join('spec/support')
config.storage = :file
config.enable_processing = false
end
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately it doesn't work now.