2016-05-30 20 views
1

イメージダウンロードのテストに問題があります。RSpecでsend_fileメソッドを使ってダウンロードイメージをテストする方法は?

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を - /ホーム/公共/システム/写真/ファイル/ 000/000/001/foo/IMG123.JPG "

ありがとうございます。

答えて

0

imagePhoto.find image.idの備品を参照していますか?あなたは、備品から参照される対応するファイルがあるかどうかチェックしてください。フィクスチャのパスを変更してそのファイルを作成しなければならないと思います。そのための良い場所はspec/fixturesです。

関連する問題