Question

How to change the factory:

FactoryGirl.define do

  factory :slide do

    association :album
    description Faker::Name.name    
    photo { fixture_file_upload(Rails.root.join('spec/fixtures/sample_1.jpg'), 'image/jpeg') }

  end
end

to provide this (photo is an array):

{"slide"=>
  {"description"=>"Rylan Gerhold",
   "photo"=>
    [#<ActionDispatch::Http::UploadedFile:0x00000005720510
      @content_type="image/jpeg",
      @headers=
       "Content-Disposition: form-data; name=\"slide[photo][]\"; filename=\"DSC_2382.JPG\"\r\nContent-Type: image/jpeg\r\n",
      @original_filename="DSC_2382.JPG",
      @tempfile=#<File:/tmp/RackMultipart20140328-1250-l4u0uv>>]},

rather than that:

{"slide"=>
  {"description"=>"Rylan Gerhold",
   "photo"=>
    #<Rack::Test::UploadedFile:0x0000000542b8a0
     @content_type="image/jpeg",
     @original_filename="sample_1.jpg",
     @tempfile=#<File:/tmp/sample_1.jpg20140328-32599-lwntv5>>},
 "album_id"=>"1",
 "controller"=>"slides",
 "action"=>"create"}
Was it helpful?

Solution

Use this instead

FactoryGirl.define do

  factory :slide do

    association :album
    description Faker::Name.name    
    photo [Rack::Test::UploadedFile.new("#{Rails.root}/spec/fixtures/sample_1.jpg", "image/jpeg")]

  end
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top