Class: UploadProgressHelperTest
- Inherits:
-
Test::Unit::TestCase
- Object
- Test::Unit::TestCase
- UploadProgressHelperTest
- Includes:
- ActionView::Helpers::AssetTagHelper, ActionView::Helpers::DateHelper, ActionView::Helpers::FormTagHelper, ActionView::Helpers::JavaScriptHelper, ActionView::Helpers::NumberHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::UploadProgressHelper, ActionView::Helpers::UrlHelper
- Defined in:
- lib/upload_progress/test/upload_progress_helper_testx.rb
Instance Method Summary collapse
- #current_upload_id ⇒ Object
- #last_upload_id ⇒ Object
- #next_upload_id ⇒ Object
- #setup ⇒ Object
- #test_finish_upload_status ⇒ Object
- #test_form_tag_with_upload_progress ⇒ Object
- #test_form_tag_with_upload_progress_custom ⇒ Object
- #test_upload_progress_text ⇒ Object
- #test_upload_progress_update_bar_js ⇒ Object
- #test_upload_status_tag ⇒ Object
- #test_upload_status_text_tag ⇒ Object
- #upload_progress(upload_id = nil) ⇒ Object
Instance Method Details
#current_upload_id ⇒ Object
45 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 45 def current_upload_id; last_upload_id; end |
#last_upload_id ⇒ Object
44 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 44 def last_upload_id; @upload_id ||= 0; end |
#next_upload_id ⇒ Object
43 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 43 def next_upload_id; @upload_id = last_upload_id.succ; end |
#setup ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 48 def setup @controller = Class.new do def url_for(, *parameters_for_method_reference) "http://www.example.com" end end @controller = @controller.new end |
#test_finish_upload_status ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 104 def test_finish_upload_status assert_dom_equal( "<html><head><script language=\"javascript\" type=\"text/javascript\">function finish() { if (parent.document.uploadStatus0) { parent.document.uploadStatus0.stop();\n }\n }</script></head><body onload=\"finish()\"></body></html>", finish_upload_status ) assert_dom_equal( "<html><head><script language=\"javascript\" type=\"text/javascript\">function finish() { if (parent.document.uploadStatus0) { parent.document.uploadStatus0.stop(123);\n }\n }</script></head><body onload=\"finish()\"></body></html>", finish_upload_status(:client_js_argument => 123) ) assert_dom_equal( "<html><head><script language=\"javascript\" type=\"text/javascript\">function finish() { if (parent.document.uploadStatus0) { parent.document.uploadStatus0.stop();\nparent.location.replace('/redirected/');\n }\n }</script></head><body onload=\"finish()\"></body></html>", finish_upload_status(:redirect_to => '/redirected/') ) end |
#test_form_tag_with_upload_progress ⇒ Object
121 122 123 124 125 126 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 121 def test_form_tag_with_upload_progress assert_dom_equal( "<form action=\"http://www.example.com\" enctype=\"multipart/form-data\" method=\"post\" onsubmit=\"if (this.action.indexOf('upload_id') < 0){ this.action += '?upload_id=1'; }this.target = 'UploadTarget1';$('UploadStatus1').innerHTML='Upload starting...'; if($('UploadProgressBar1')){$('UploadProgressBar1').firstChild.firstChild.style.width='0%'}; if (document.uploadStatus1) { document.uploadStatus1.stop(); }document.uploadStatus1 = new Ajax.PeriodicalUpdater('UploadStatus1','http://www.example.com', Object.extend({asynchronous:true, evalScripts:true, onComplete:function(request){$('UploadStatus1').innerHTML='A message';if($('UploadProgressBar1')){$('UploadProgressBar1').firstChild.firstChild.style.width='100%'};document.uploadStatus1 = null}},{decay:1.8,frequency:2.0})); return true\"><iframe id=\"UploadTarget1\" name=\"UploadTarget1\" src=\"\" style=\"width:0px;height:0px;border:0\"></iframe>", form_tag_with_upload_progress ) end |
#test_form_tag_with_upload_progress_custom ⇒ Object
128 129 130 131 132 133 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 128 def test_form_tag_with_upload_progress_custom assert_dom_equal( "<form action=\"http://www.example.com\" enctype=\"multipart/form-data\" method=\"post\" onsubmit=\"if (this.action.indexOf('upload_id') < 0){ this.action += '?upload_id=5'; }this.target = 'awindow';$('UploadStatus0').innerHTML='Upload starting...'; if($('UploadProgressBar0')){$('UploadProgressBar0').firstChild.firstChild.style.width='0%'}; alert('foo'); if (document.uploadStatus0) { document.uploadStatus0.stop(); }document.uploadStatus0 = new Ajax.PeriodicalUpdater('UploadStatus0','http://www.example.com', Object.extend({asynchronous:true, evalScripts:true, onComplete:function(request){$('UploadStatus0').innerHTML='A message';if($('UploadProgressBar0')){$('UploadProgressBar0').firstChild.firstChild.style.width='100%'};document.uploadStatus0 = null; alert('bar')}},{decay:7,frequency:6})); return true\" target=\"awindow\">", form_tag_with_upload_progress({:upload_id => 5}, {:begin => "alert('foo')", :finish => "alert('bar')", :frequency => 6, :decay => 7, :target => 'awindow'}) ) end |
#test_upload_progress_text ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 72 def test_upload_progress_text @upload_progress = MockProgress.new(false, false) assert_equal( "Upload starting...", upload_progress_text ) @upload_progress = MockProgress.new(true, false) assert_equal( "828.7 MB of 456.2 MB at 990.1 MB/s; 10227 days remaining", upload_progress_text ) @upload_progress = MockProgress.new(true, true) assert_equal( "A message", upload_progress_text ) end |
#test_upload_progress_update_bar_js ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 92 def assert_equal( "if($('UploadProgressBar0')){$('UploadProgressBar0').firstChild.firstChild.style.width='0%'}", ) assert_equal( "if($('UploadProgressBar0')){$('UploadProgressBar0').firstChild.firstChild.style.width='50%'}", (50) ) end |
#test_upload_status_tag ⇒ Object
57 58 59 60 61 62 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 57 def test_upload_status_tag assert_dom_equal( '<div class="progressBar" id="UploadProgressBar0"><div class="border"><div class="background"><div class="foreground"></div></div></div></div><div class="uploadStatus" id="UploadStatus0"></div>', upload_status_tag ) end |
#test_upload_status_text_tag ⇒ Object
64 65 66 67 68 69 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 64 def test_upload_status_text_tag assert_dom_equal( '<div class="my-upload" id="my-id">Starting</div>', upload_status_text_tag('Starting', :class => 'my-upload', :id => 'my-id') ) end |
#upload_progress(upload_id = nil) ⇒ Object
46 |
# File 'lib/upload_progress/test/upload_progress_helper_testx.rb', line 46 def upload_progress(upload_id = nil); @upload_progress ||= MockProgress.new(false, true); end |