gpt4 book ai didi

ruby-on-rails - 带有内容类型检查的 RSpec send_file 测试

转载 作者:行者123 更新时间:2023-12-03 17:57:25 30 4
gpt4 key购买 nike

我有一个 Rails Controller ,它发送一个具有不同内容类型的文件

Exel-File 示例, Controller 设置 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"

最佳答案

如果您愿意(或已经在使用)Thoughtbot shoulda gem,请使用回形针钩住它

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

并有一个 s3 上传方法。

关于ruby-on-rails - 带有内容类型检查的 RSpec send_file 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9140099/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com