forked from carrierwaveuploader/carrierwave
-
Notifications
You must be signed in to change notification settings - Fork 0
How to: Use test fixtures
chrisbloom7 edited this page Jun 6, 2011
·
7 revisions
Whereas other gems such as Paperclip allow you to sham mounted uploaders as Strings, CarrierWave requires actual files. Here is an example blueprints.rb file:
# Machinist example
Sham.image { File.open("#{Rails.root}/test/fixtures/files/rails.png") }
User.blueprint do
avatar { Sham.image }
end
EDIT:
I belive StringIO's also work
Attaching a file to a FactoryGirl object is pretty much identical.
# FactoryGirl example
Factory.define :brand do |f|
f.name "My Brand"
f.description "Foo"
f.logo { File.open(File.join(Rails.root, 'spec', 'support', 'brands', 'logos', 'logo_image.jpg')) }
end
AFAICT the curly braces are required to make FactoryGirl attach it lazily, i.e. whenever the factory is built.