6
使用rspec测试文件上传-Rails
我想测试Rails中的文件上传,但不确定如何执行此操作。 这是控制器代码: def uploadLicense #Create the license object @license = License.create(params[:license]) #Get Session ID sessid = session[:session_id] puts "\n\nSession_id:\n#{sessid}\n" #Generate a random string chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a newpass = "" 1.upto(5) { |i| newpass << chars[rand(chars.size-1)] } #Get the original file name upload=params[:upload] name = upload['datafile'].original_filename @license.format …