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

1

8

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') %>
Jerid answered 31/1, 2015 at 13:49 Comment(0)
C
5

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.

Catenate answered 3/9, 2015 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.