Тестирование RSpec send_file с проверкой Content-Type - PullRequest
5 голосов
/ 04 февраля 2012

У меня есть Rails Controller, который отправляет файл с другим Content-Type

Пример для 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"

1 Ответ

0 голосов
/ 19 февраля 2014

Если вы хотите (или уже используете) мыслитель должен быть драгоценным камнем, скрепка в него зацепляется

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

и имеет метод загрузки s3.

...