【发布时间】:2016-05-30 16:44:15
【问题描述】:
我在测试图片下载时遇到了困难。
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
我的 RSpec 测试(控制器):
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
当我为这两个测试运行 rspec 测试时,我得到一个错误:“没有这样的文件或目录@rb_sysopen - /home/public/system/photos/files/000/000/001/foo/IMG123.JPG”
谢谢。
【问题讨论】:
标签: ruby-on-rails rspec