I had some initial difficulty testing my photos controller with an uploaded file for the :image field, because the test was reading :image as nil. What worked was wrapping the image in a content wrapper using Class: Rack::Test::UploadedFile. I have this implemented in my factory:

image { Rack::Test::UploadedFile.new(File.open(File.join(Rails.root, '/spec/support/my_image.jpg')), 'image/jpeg') }

The image file “my_image.jpg” sits in spec/support.

Tags: , , ,

In categories: Rails

COMMENTS

  1. Javier says:

    thanks for this, just save my life 😛

LEAVE A REPLY

Only the name field is required. Your email will not be published.