Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 test upload file using fixtures (.yml) and paperclip

How can i create fixtures file for test paperclip upload? I search fews result in google but always use with FactoryGirl. I tried but not work:

img:
  image: <%= fixture_file_upload(Rails.root.join('test/fixtures/test_img.jpg'), 'image/jpeg') %>
like image 450
SolomonT Avatar asked Jan 31 '15 13:01

SolomonT


1 Answers

You cannot do that with fixtures. Fixtures are adding attribute values directly to the database, skipping the active record layer. Paperclip is a plugin for ActiveRecord, that processing and storing photos.

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

What you can do is to put attributes into the fixture so the paperclip will work as it should, just without 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

When you want to make everything correct, better to use FactoryGirl.

fixture_file_upload is only used for action controller.

like image 87
Dmitry Polushkin Avatar answered Nov 15 '22 06:11

Dmitry Polushkin