Here’s small chunk of code that will help you out with testing paperclip. Basically it will stub any fie upload of any instance for given model. So now you won’t be left with ridiculous amount of files created after each test run. Yay!
module PaperclipMacros
def stub_paperclip(model)
before do
model.any_instance.stub(:save_attached_files).and_return(true)
model.any_instance.stub(:delete_attached_files).and_return(true)
Paperclip::Attachment.any_instance.stub(:post_process).and_return(true)
end
end
end
Put that file somehere under spec/support/
and in your spec_helper.rb
include it like using config.extend PaperclipMacros
. Now later in your test (of models or controllers, whatever) you can call it like that:
describe Download do
stub_paperclip(Download)
...
end