def upload_fixture_file filename, content_type
ActionDispatch::Http::UploadedFile.new({
:filename => filename,
:content_type => content_type,
:tempfile => File.new("#{Rails.root}/test/fixtures/files/" + filename)
})
end
test "should deny exe file upload" do
file = upload_fixture_file 'SkypeSetup.exe', "application/exe"
assert_no_difference 'Upload.count' do
post :create, :upload => { :case_id=> cases(:fred_and_oliver_open).id, :file => file, :reviewed => :false, :user_id => users(:fred).id }
end
end
运行上面的测试产生“Upload.count”没有改变0。在我的应用程序上我得到预期的“发生错误:文件您不允许上传“exe”文件,允许的类型:[“jpg”,“ jpeg"、"gif"、"png"、"pdf"、"doc"、"docs"、"rtf"、"ods"、"bmp"、"odt"]"
为什么会这样?谢谢