5

Content-Type が異なるファイルを送信する Rails コントローラーがあります。

Exel-File の例、コントローラ セット Content-Type ="application/excel"

RSpec テストは次のとおりです。

describe "GET getfile" do
  it "Excel File" do
    controller.stub(:render)
    controller.should_receive(:send_file)
    get :getfile, :name => 'test+xls'
    controller.response.header.should == '???'
  end
end

テストからの答えは次のとおりです。

1) ExportController GET getfile Excel File
   Failure/Error: controller.response.header.should == ''
     expected: ""
          got: {"Content-Type"=>"text/html; charset=utf-8"} (using ==)
     Diff:
     @@ -1,2 +1,2 @@
     -""
     +"Content-Type" => "text/html; charset=utf-8"
4

1 に答える 1

0

思考ボットにジェムを使用する意思がある (または既に使用している) 場合は、ペーパークリップをジェムに引っ掛けます

https://github.com/thoughtbot/paperclip/blob/master/shoulda_macros/paperclip.rb

s3アップロードメソッドがあります。

于 2014-02-19T14:21:09.753 に答える