Rails 4 boot file using fixtures (.yml) and a paper clip

How can I create fixtures file for test load paperclip? I am looking for some results on Google, but always use them with FactoryGirl. I tried but did not work:

img: image: <%= fixture_file_upload(Rails.root.join('test/fixtures/test_img.jpg'), 'image/jpeg') %> 
+7
ruby-on-rails ruby-on-rails-4 paperclip
source share
1 answer

You cannot do this with fixtures. Luminaires add attribute values ​​directly to the database, skipping the active recording layer. Paperclip is an ActiveRecord plugin that processes and stores photos.

Saving a real image can only be done by passing arguments directly to a new record.

What you can do is put the attributes in the fixture so that the paper clip works as it should, without a real file.

  photo_file_name: temp_file.jpg photo_content_type: image/jpeg photo_file_size: 223312 photo_updated_at: 2015-02-29 10:30:19 Z 

If you want to do everything right, it is better to use FactoryGirl .

fixture_file_upload used only for action controller.

+4
source share

All Articles