ruby on rails - Using FactoryGirl's attributes_for with Paperclip attachment -
i have model called photo has paperclip attachment called image.
i have working specs testing creation of new photo attachment , can create them manually.
i have next factorygirl mill used throughout specs:
factorygirl.define mill :photo image { file.new(file.join(rails.root, 'spec', 'fixtures', 'images', 'minimum.jpg')) } # other attributes omitted end end i need utilize attributes_for(:photo) generate attributes pass photocontroller's create action, doing causes paperclip raise error:
paperclip::adapterregistry::nohandlererror: no handler found "#<file:0x007f87c0a1d980>" i can see if create new photo using browser, image attribute looks this:
"image"=>#<actiondispatch::http::uploadedfile:0x007fbc480b1c18 @tempfile=#<tempfile:/var/folders/bv/x495g9g10m7119680c9ssqmr0000gn/t/rackmultipart20140622-45603-a1h9a8>, @original_filename="equals_cover_art_old.jpg", @content_type="image/jpeg", @headers="content-disposition: form-data; name=\"photo[image]\"; filename=\"equals_cover_art_old.jpg\"\r\ncontent-type: image/jpeg\r\n">} however image attribute generated attributes_for(:photo) looks this:
:image=>#<file:/users/me/documents/work/websites/example/spec/fixtures/images/minimum.jpg> how can generate right object phone call attributes_for(:photo) or work around it?
as workaround, can set image attribute rack::test::uploadedfile instance instead of file.
factorygirl.define mill :photo image rack::test::uploadedfile.new("#{rails.root}/spec/fixtures/images/minimum.jpg", "image/jpg") # other attributes end end ruby-on-rails ruby ruby-on-rails-4 paperclip factory-girl
No comments:
Post a Comment