Class: MultipartProgressTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
lib/upload_progress/test/multipart_progress_testx.rb

Instance Method Summary collapse

Instance Method Details

#test_basic_setupObject



292
293
294
295
296
297
298
299
300
301
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 292

def test_basic_setup
  test_logger.debug('test_basic_setup')

  cgi, request, response = new_request(100000)
  assert_not_nil(request.session)
  assert_not_nil(request.session[:uploads], "uploads collection not set")
  assert_not_nil(request.session[:uploads][cgi.upload_id], "upload id not set")
  progress = request.session[:uploads][cgi.upload_id]
  assert_equal(true, progress.finished?)
end

#test_domain_language_doubleObject



202
203
204
205
206
207
208
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 202

def test_domain_language_double
  c = Controllers::DoubleUploadController.new
  assert_respond_to(c, :one)
  assert_respond_to(c, :two)
  assert_respond_to(c, :upload_status)
  assert_respond_to(c, :finish_upload_status)
end

#test_domain_language_double_seperateObject



218
219
220
221
222
223
224
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 218

def test_domain_language_double_seperate
  c = Controllers::DoubleSeperateController.new
  assert_respond_to(c, :one)
  assert_respond_to(c, :two)
  assert_respond_to(c, :upload_status)
  assert_respond_to(c, :finish_upload_status)
end

#test_domain_language_double_statusObject



210
211
212
213
214
215
216
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 210

def test_domain_language_double_status
  c = Controllers::DoubleStatusUploadController.new
  assert_respond_to(c, :one)
  assert_respond_to(c, :two)
  assert_respond_to(c, :custom_status)
  assert_respond_to(c, :finish_upload_status)
end

#test_domain_language_singleObject



195
196
197
198
199
200
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 195

def test_domain_language_single
  c = Controllers::SingleUploadController.new
  assert_respond_to(c, :one)
  assert_respond_to(c, :upload_status)
  assert_respond_to(c, :finish_upload_status)
end

#test_finish_status_finish_paramObject



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 270

def test_finish_status_finish_param
  test_logger.debug('test_finish_status_param')

  res = process(:action => :finish_param_string, :upload_id => 1)
  assert_match(/stop\('a string'\)/s, res.body)
  assert_no_redirect res

  res = process(:action => :finish_param_dict, :upload_id => 1)
  assert_match(/stop\(\{a: 'b'\}\)/s, res.body)
  assert_no_redirect res

  res = process(:action => :finish_param_number, :upload_id => 1)
  assert_match(/stop\(123\)/s, res.body)
  assert_no_redirect res

  res = process(:action => :finish_param_number_redirect, :upload_id => 1)
  test_logger.debug('test_finish_status_param: ' + res.body)
  assert_match(/stop\(123\)/s, res.body)
  assert_match(/replace\('\http:\/\/localhost\/redirected\/'\).*?/s, res.body)
  assert_no_redirect res
end

#test_finish_status_norenderedObject



226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 226

def test_finish_status_norendered
  # Fails to render the upload finish script because there is no view associated with this action
  test_logger.debug('test_finish_status_norendered')

  res = process(:action => 'norendered', :upload_id => 1)
  assert_match(/ActionView::ActionViewError/s, res.body)
  
  res = process(:action => :upload_status, :upload_id => 1)
  assert_match(/Upload finished/s, res.body)

  res = process(:action => :norendered)
  assert_match(/ActionView::ActionViewError/s, res.body)
end

#test_finish_status_redirectedObject



255
256
257
258
259
260
261
262
263
264
265
266
267
268
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 255

def test_finish_status_redirected
  test_logger.debug('test_finish_status_redirected')

  res = process(:action => :redirected, :upload_id => 1)
  assert_match(/location\.replace/s, res.body)
  
  res = process(:action => :redirected)
  assert_no_match(/location\.replace/s, res.body)
  assert_match(/\/redirected\//s, res.headers['location'])
  assert_match(/302 .*$/, res.headers['Status'])

  res = process(:action => :upload_status, :upload_id => 1)
  assert_match(/Upload finished/s, res.body)
end

#test_finish_status_renderedObject



240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 240

def test_finish_status_rendered
  test_logger.debug('test_finish_status_rendered')

  res = process(:action => :rendered, :upload_id => 1)
  assert_match(/stop\(\)/s, res.body)
  assert_no_match(/rendered/s, res.body)
  
  res = process(:action => :upload_status, :upload_id => 1)
  assert_match(/Upload finished/s, res.body)
  
  res = process(:action => :rendered)
  assert_no_match(/stop\(\)/s, res.body)
  assert_match(/rendered/, res.body)
end

#test_paramsObject



303
304
305
306
307
308
309
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 303

def test_params
  test_logger.debug('test_params')

  cgi, request, response = new_request(1000)
  assert(!request.params.empty?)
  assert(!request.params['param1'].empty?)
end

#test_share_sessionObject



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 311

def test_share_session
  cgi, request, response = new_request(100000) do |cgi, req|
    if cgi.stdinput.tell > 50000
      # force a save
      cgi.stdinput.save_progress rescue flunk('Something else is wrong, our wrapper isnt setup, is ActionController::Base.logger set?')

      other_session = CGI::Session.new(cgi, cgi.session_options.merge({'session_id' => cgi.session_id}))
      assert_not_nil(other_session[:uploads])
      assert_not_nil(other_session[:uploads][cgi.upload_id])
      assert_in_delta(cgi.stdinput.session[:uploads][cgi.upload_id].bitrate, other_session[:uploads][cgi.upload_id].bitrate, 1000.0, "Seperate session does not share data from original session")

      other_session.close
    end
  end
end

#test_upload_idsObject



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/upload_progress/test/multipart_progress_testx.rb', line 327

def test_upload_ids
  c = Controllers::MockController.new
  (1..222).each do |id|
    c.params = {}

    assert_equal((id-1).to_s, c.last_upload_id, "last_upload_id is out of sync")
    assert_equal(id.to_s, c.next_upload_id, "next_upload_id is out of sync")
    assert_equal(id.to_s, c.current_upload_id, "current_upload_id is out of sync")

    c.params = {:upload_id => (id-1).to_s}
    assert_equal((id-1).to_s, c.current_upload_id, "current_upload_id is out of sync")

    c.session[:uploads][id] = {}
  end
end