7

I am having difficulties with testing image download.

def download_img
  @image = Photo.find params[:id] unless params[:id].nil?
  @c = Cat.find params[:cat_id] unless params[:cat_id].nil?
  @foo = @image.foo unless @image.nil?

  send_file(Paperclip.io_adapters.for(@image.file).path, type: "jpeg", :disposition => "attachment", :filename => @image.name)
end

My RSpec test (controller):

describe 'download_img' do
before do
  get :download_img, { id: image.id }
end

it 'retrieves image by id' do
  img = Photo.find image.id
  expect(img).not_to be_nil
end

it 'downloads image' do
  page.response_headers["Content-Type"].should == "application/jpg"
  page.response_headers["Content-Disposition"].should == "attachment; filename=\"image.name.jpg\""
end
end

When I run rspec test for both tests I get an error: "No such file or directory @ rb_sysopen - /home/public/system/photos/files/000/000/001/foo/IMG123.JPG"

Thank you.

Michael
  • 125
  • 1
  • 9

1 Answers1

0

Is that image you are referring to in Photo.find image.id coming from fixtures? Will you please check if there's a corresponding file referenced from fixtures. I suppose you'll have to change the path in fixtures and create that file as well, a good place for it is spec/fixtures.

phil pirozhkov
  • 4,740
  • 2
  • 33
  • 40