相关疑难解决方法(0)

使用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 = 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)

tdd file-upload ruby-on-rails rspec-rails

138
推荐指数
5
解决办法
7万
查看次数

如何在rails中测试文件上传?

我有一个控制器,负责接受JSON文件,然后处理JSON文件,为我们的应用程序做一些用户维护.在用户测试文件上传和处理工作,但当然我想在我们的测试中自动化测试用户维护的过程.如何在功能测试框架中将文件上传到控制器?

ruby testing upload ruby-on-rails

99
推荐指数
4
解决办法
4万
查看次数

标签 统计

ruby-on-rails ×2

file-upload ×1

rspec-rails ×1

ruby ×1

tdd ×1

testing ×1

upload ×1