6

I have a Rails Controller that send a file with different Content-Type

Example for Exel-File, the controller set Content-Type = "application/excel"

and here is the RSpec test:

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

The answer from the test is:

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"
romus
  • 63
  • 1
  • 4
  • `controller.stub(:render)`, `controller.should_receive(:send_file)`. These lines change controller methods to return nil when called. You cannot check that method is called and it's return value in a single test with rspec matchers. Split tests or use some other gem for expectations. And it would be great to see controller code too if it didn't help. – faron Dec 02 '13 at 09:23

1 Answers1

0

If you're willing (or already using) the thoughtbot shoulda gem, paperclip hooks into it

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

and has an s3 upload method.

John Paul Ashenfelter
  • 3,135
  • 1
  • 22
  • 29