SORU
31 AĞUSTOS 2011, ÇARŞAMBA


test dosya upload rspec kullanarak raylar

Raylar bir dosya upload test etmek istiyorum, ama bunu nasıl emin değilim.

Burada denetleyicisi kodu:

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 ID
    @license.license_id = sessid   newpass

    #Save the license
    @license.save

    redirect_to :action => 'show', :id => @license.id 
end

Bu spec denedim, ama işe yaramıyor:

it "can upload a license and download a license" do
    file = File.new(Rails.root   'app/controllers/lic.xml')
    license = HashWithIndifferentAccess.new
    license[:datafile] = file
    info = {:id => 4}
    post :uploadLicense, {:license => info, :upload => license}
end

Nasıl dosya upload, rspec kullanarak taklit edebilir miyim?

CEVAP
28 Kasım 2011, PAZARTESİ


8* *yöntemi dosya yükleme test etmek için kullanabilirsiniz: Test dosya koy"{Raylar.root}/spec/Fikstür/dosyalar"dizin

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

Durumda şeklinde dosya bekliyor[''] Yükleme [''] veri dosyası . parametreler

it "can upload a license" do
  file = Hash.new
  file['datafile'] = @file
  post :uploadLicense, :upload => file
  response.should be_success
end

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Barnacules Nerdgasm

    Barnacules N

    20 Temmuz 2006
  • TV nEW

    TV nEW

    25 AĞUSTOS 2012
  • UKF

    UKF

    2 Aralık 2009