If you are trying to test a model with that has a Carrierwave uploader mounted, validations on the field, and you’re using FactoryGirl, you are more than likely goin to get an error thank looks something like this…
/path/to/your/ruby/gems/activerecord-3.2.3/lib/active_record/validations.rb:56:in `save!': Validation failed: Logo can't be blank (ActiveRecord::RecordInvalid)
Fortunately, getting around this error is pretty easy. You can beat in there steps
- Drop a test image file somewhere in the app folder. I put mine in test/fixtures/files.
- Put
in the top of the factory file for the model you are testing.include ActionDispatch::TestProcess - Update the uploader field in your factory to use fixture_file_upload method and pass it in a hash with your test image info. It should look like this…
logo {fixture_file_upload('test/fixtures/files/test_image.jpg', 'image/jpg')}
Run those test again, you should be all set.






