β

测试文件上传 (test file upload in Rails )

申思维的站点/Siwei's site 126 阅读

非常简单。 You can use fixture_file_upload method to test file uploading: Put your test file in "{Rails.root}/spec/fixtures/files" directory

before :each do
  @file = fixture_file_upload('files/test_lic.xml', 'text/xml')
end

it "can upload a license" do
  post :uploadLicense, :upload => @file
  response.should be_success
end

记得第二个参数是 mime类型, 比如  'image/png', 'image/jpeg' 啥的。  ( the second parameter is the MIME type)

作者:申思维的站点/Siwei's site
我是申思维,从事于WEB 和移动app开发 熟悉js (coffeescript), CSS, HTML,跟web相关的服务器(apache, nginx, passenger, mongrel, t
原文地址:测试文件上传 (test file upload in Rails ), 感谢原作者分享。

发表评论