我想在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 = File.extname(name)
#calculate license ID and location
@license.location = './public/licenses/' + sessid + newpass + name
#Save the license file
#Fileupload.save(params[:upload], @license.location)
File.open(@license.location, "wb") { |f| f.write(upload['datafile'].read) }
#Set license …Run Code Online (Sandbox Code Playgroud) 我有一个控制器,负责接受JSON文件,然后处理JSON文件,为我们的应用程序做一些用户维护.在用户测试文件上传和处理工作,但当然我想在我们的测试中自动化测试用户维护的过程.如何在功能测试框架中将文件上传到控制器?