Note that there are some explanatory texts on larger screens.

plurals
  1. POPaperclip::Attachment passed as string when using FactoryGirl
    primarykey
    data
    text
    <p>I am trying to create a functional test for paperclip 3.1.2 on rails 3.2.6 using FactoryGirl 3.0 and when i pass the file attachment my controller receives a string which is the file location and not the Paperclip::Attachment object.</p> <p>My factory is:</p> <pre><code>include ActionDispatch::TestProcess FactoryGirl.define do factory :artist do id 1 name 'MyString' photo {fixture_file_upload("#{Rails.root}/test/fixtures/files/rails.png",'image/png')} end end </code></pre> <p>And my test is:</p> <pre><code>test "should create artist" do assert_difference('Artist.count') do post :create, :artist =&gt; { name: @artist.name, photo: @artist.photo }, :html =&gt; { :multipart =&gt; true } end assert_redirected_to artist_path(assigns(:artist)) end </code></pre> <p>In my controller this : </p> <pre><code>params[:artist][:photo].class.name </code></pre> <p>equals "String", but this passes when i add it to the test </p> <pre><code>assert @artist.photo.class.name == "Paperclip::Attachment" </code></pre> <p>My current workaround is to create the fixture_file_upload in the test :</p> <pre><code>test "should create artist" do assert_difference('Artist.count') do photo = fixture_file_upload("/files/rails.png",'image/png') post :create, :artist =&gt; { name: @artist.name, photo: photo }, :html =&gt; { :multipart =&gt; true } end assert_redirected_to artist_path(assigns(:artist)) end </code></pre> <p>which works but creates a "Rack::Test::UploadedFile" and so I'm pretty confused why my factory returns a "Paperclip::Attachment" when the same method is called to create them both.</p> <p>Thanks in advance for any light that you can shed on this as obviously I would like to use the factory rather than defining the fixture_file_upload outside of it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload