actionpack 1.11.2 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +392 -5
- data/lib/action_controller.rb +8 -4
- data/lib/action_controller/assertions.rb +9 -10
- data/lib/action_controller/base.rb +177 -88
- data/lib/action_controller/benchmarking.rb +5 -5
- data/lib/action_controller/caching.rb +44 -36
- data/lib/action_controller/cgi_ext/cgi_methods.rb +71 -6
- data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +1 -1
- data/lib/action_controller/cgi_process.rb +36 -24
- data/lib/action_controller/components.rb +152 -52
- data/lib/action_controller/dependencies.rb +1 -1
- data/lib/action_controller/deprecated_redirects.rb +2 -2
- data/lib/action_controller/deprecated_request_methods.rb +34 -0
- data/lib/action_controller/filters.rb +59 -19
- data/lib/action_controller/flash.rb +53 -47
- data/lib/action_controller/helpers.rb +2 -2
- data/lib/action_controller/integration.rb +524 -0
- data/lib/action_controller/layout.rb +58 -23
- data/lib/action_controller/mime_responds.rb +163 -0
- data/lib/action_controller/mime_type.rb +142 -0
- data/lib/action_controller/pagination.rb +13 -7
- data/lib/action_controller/request.rb +59 -56
- data/lib/action_controller/rescue.rb +1 -1
- data/lib/action_controller/routing.rb +29 -10
- data/lib/action_controller/scaffolding.rb +8 -0
- data/lib/action_controller/session/active_record_store.rb +21 -10
- data/lib/action_controller/session/mem_cache_store.rb +18 -12
- data/lib/action_controller/session_management.rb +30 -11
- data/lib/action_controller/templates/rescues/_trace.rhtml +1 -1
- data/lib/action_controller/templates/scaffolds/layout.rhtml +4 -4
- data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
- data/lib/action_controller/test_process.rb +189 -118
- data/lib/action_controller/vendor/html-scanner/html/node.rb +20 -1
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +3 -0
- data/lib/action_controller/vendor/html-scanner/html/version.rb +1 -1
- data/lib/action_controller/vendor/xml_node.rb +97 -0
- data/lib/action_controller/verification.rb +2 -0
- data/lib/action_pack/version.rb +3 -3
- data/lib/action_view.rb +0 -2
- data/lib/action_view/base.rb +109 -36
- data/lib/action_view/compiled_templates.rb +1 -1
- data/lib/action_view/helpers/active_record_helper.rb +4 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +6 -7
- data/lib/action_view/helpers/capture_helper.rb +49 -12
- data/lib/action_view/helpers/date_helper.rb +14 -4
- data/lib/action_view/helpers/form_helper.rb +136 -20
- data/lib/action_view/helpers/form_options_helper.rb +29 -7
- data/lib/action_view/helpers/form_tag_helper.rb +22 -20
- data/lib/action_view/helpers/java_script_macros_helper.rb +29 -9
- data/lib/action_view/helpers/javascript_helper.rb +50 -446
- data/lib/action_view/helpers/javascripts/controls.js +95 -30
- data/lib/action_view/helpers/javascripts/dragdrop.js +161 -21
- data/lib/action_view/helpers/javascripts/effects.js +310 -211
- data/lib/action_view/helpers/javascripts/prototype.js +228 -28
- data/lib/action_view/helpers/number_helper.rb +9 -9
- data/lib/action_view/helpers/pagination_helper.rb +1 -1
- data/lib/action_view/helpers/prototype_helper.rb +900 -0
- data/lib/action_view/helpers/scriptaculous_helper.rb +135 -0
- data/lib/action_view/helpers/text_helper.rb +7 -6
- data/lib/action_view/helpers/url_helper.rb +23 -14
- data/lib/action_view/partials.rb +12 -4
- data/rakefile +13 -5
- data/test/abstract_unit.rb +4 -3
- data/test/active_record_unit.rb +88 -0
- data/test/{controller → activerecord}/active_record_assertions_test.rb +7 -50
- data/test/{controller → activerecord}/active_record_store_test.rb +27 -4
- data/test/activerecord/pagination_test.rb +161 -0
- data/test/controller/action_pack_assertions_test.rb +18 -15
- data/test/controller/base_test.rb +31 -42
- data/test/controller/benchmark_test.rb +8 -11
- data/test/controller/capture_test.rb +33 -1
- data/test/controller/cgi_test.rb +33 -0
- data/test/controller/custom_handler_test.rb +8 -0
- data/test/controller/fake_controllers.rb +9 -17
- data/test/controller/filters_test.rb +32 -3
- data/test/controller/flash_test.rb +26 -41
- data/test/controller/fragment_store_setting_test.rb +1 -1
- data/test/controller/layout_test.rb +73 -0
- data/test/controller/mime_responds_test.rb +257 -0
- data/test/controller/mime_type_test.rb +24 -0
- data/test/controller/new_render_test.rb +157 -1
- data/test/controller/redirect_test.rb +23 -0
- data/test/controller/render_test.rb +54 -56
- data/test/controller/request_test.rb +25 -0
- data/test/controller/routing_test.rb +74 -66
- data/test/controller/test_test.rb +66 -1
- data/test/controller/verification_test.rb +3 -1
- data/test/controller/webservice_test.rb +255 -0
- data/test/fixtures/companies.yml +24 -0
- data/test/fixtures/company.rb +9 -0
- data/test/fixtures/db_definitions/sqlite.sql +42 -0
- data/test/fixtures/developer.rb +7 -0
- data/test/fixtures/developers.yml +21 -0
- data/test/fixtures/developers_projects.yml +13 -0
- data/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/item.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/layout_test.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/third_party_template_library.mab +1 -0
- data/test/fixtures/layout_tests/views/hello.rhtml +1 -0
- data/test/fixtures/multipart/mona_lisa.jpg +0 -0
- data/test/fixtures/project.rb +3 -0
- data/test/fixtures/projects.yml +7 -0
- data/test/fixtures/replies.yml +13 -0
- data/test/fixtures/reply.rb +5 -0
- data/test/fixtures/respond_to/all_types_with_layout.rhtml +1 -0
- data/test/fixtures/respond_to/all_types_with_layout.rjs +1 -0
- data/test/fixtures/respond_to/layouts/standard.rhtml +1 -0
- data/test/fixtures/respond_to/using_defaults.rhtml +1 -0
- data/test/fixtures/respond_to/using_defaults.rjs +1 -0
- data/test/fixtures/respond_to/using_defaults.rxml +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.rhtml +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.rjs +1 -0
- data/test/fixtures/respond_to/using_defaults_with_type_list.rxml +1 -0
- data/test/fixtures/test/block_content_for.rhtml +2 -0
- data/test/fixtures/test/delete_with_js.rjs +2 -0
- data/test/fixtures/test/dot.directory/render_file_with_ivar.rhtml +1 -0
- data/test/fixtures/test/enum_rjs_test.rjs +6 -0
- data/test/fixtures/test/erb_content_for.rhtml +2 -0
- data/test/fixtures/test/hello_world.rxml +3 -0
- data/test/fixtures/test/hello_world_with_layout_false.rhtml +1 -0
- data/test/fixtures/test/non_erb_block_content_for.rxml +4 -0
- data/test/fixtures/topic.rb +3 -0
- data/test/fixtures/topics.yml +22 -0
- data/test/template/active_record_helper_test.rb +4 -0
- data/test/template/asset_tag_helper_test.rb +7 -2
- data/test/template/date_helper_test.rb +39 -2
- data/test/template/form_helper_test.rb +238 -5
- data/test/template/form_options_helper_test.rb +78 -0
- data/test/template/form_tag_helper_test.rb +11 -0
- data/test/template/java_script_macros_helper_test.rb +51 -6
- data/test/template/javascript_helper_test.rb +7 -153
- data/test/template/number_helper_test.rb +14 -13
- data/test/template/prototype_helper_test.rb +423 -0
- data/test/template/scriptaculous_helper_test.rb +90 -0
- data/test/template/text_helper_test.rb +12 -9
- data/test/template/url_helper_test.rb +31 -15
- metadata +291 -246
- data/lib/action_controller/cgi_ext/multipart_progress.rb +0 -169
- data/lib/action_controller/upload_progress.rb +0 -473
- data/lib/action_controller/vendor/html-scanner/html/node.rb.rej +0 -17
- data/lib/action_view/helpers/upload_progress_helper.rb +0 -433
- data/lib/action_view/vendor/builder.rb +0 -13
- data/lib/action_view/vendor/builder/blankslate.rb +0 -53
- data/lib/action_view/vendor/builder/xmlbase.rb +0 -143
- data/lib/action_view/vendor/builder/xmlevents.rb +0 -63
- data/lib/action_view/vendor/builder/xmlmarkup.rb +0 -308
- data/test/controller/multipart_progress_testx.rb +0 -365
- data/test/controller/upload_progress_testx.rb +0 -89
- data/test/template/upload_progress_helper_testx.rb +0 -136
@@ -1,365 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
-
require 'logger'
|
3
|
-
require 'test/unit'
|
4
|
-
require 'cgi'
|
5
|
-
require 'stringio'
|
6
|
-
|
7
|
-
DEBUG=false
|
8
|
-
|
9
|
-
def test_logger
|
10
|
-
if DEBUG then ActionController::Base.logger = Logger.new(STDERR)
|
11
|
-
else ActionController::Base.logger = Logger.new(StringIO.new)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Provide a static version of the Controllers module instead of the auto-loading version.
|
16
|
-
# We don't want these tests to fail when dependencies are to blame.
|
17
|
-
module Controllers
|
18
|
-
class EmptyController < ActionController::Base
|
19
|
-
end
|
20
|
-
class ApplicationController < ActionController::Base
|
21
|
-
end
|
22
|
-
|
23
|
-
class MockController < ActionController::Base
|
24
|
-
def initialize
|
25
|
-
super
|
26
|
-
@session = {:uploads => {}}
|
27
|
-
@params = {}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class SingleUploadController < ActionController::Base
|
32
|
-
upload_status_for :one
|
33
|
-
|
34
|
-
def one; end
|
35
|
-
end
|
36
|
-
|
37
|
-
class DoubleUploadController < ActionController::Base
|
38
|
-
upload_status_for :one, :two
|
39
|
-
|
40
|
-
def one; end
|
41
|
-
def two; end
|
42
|
-
end
|
43
|
-
|
44
|
-
class DoubleStatusUploadController < ActionController::Base
|
45
|
-
upload_status_for :one, :two, :status => :custom_status
|
46
|
-
|
47
|
-
def one; end
|
48
|
-
def two; end
|
49
|
-
end
|
50
|
-
|
51
|
-
class DoubleSeperateController < ActionController::Base
|
52
|
-
upload_status_for :one
|
53
|
-
upload_status_for :two
|
54
|
-
|
55
|
-
def one; end
|
56
|
-
def two; end
|
57
|
-
end
|
58
|
-
|
59
|
-
class UploadController < ActionController::Base
|
60
|
-
upload_status_for :norendered, :rendered, :redirected, :finish_param_dict, :finish_param_string, :finish_param_number
|
61
|
-
|
62
|
-
def norendered
|
63
|
-
end
|
64
|
-
|
65
|
-
def rendered
|
66
|
-
render_text("rendered")
|
67
|
-
end
|
68
|
-
|
69
|
-
def redirected
|
70
|
-
redirect_to "/redirected/"
|
71
|
-
end
|
72
|
-
|
73
|
-
def finish_param_dict
|
74
|
-
finish_upload_status "{a: 'b'}"
|
75
|
-
end
|
76
|
-
|
77
|
-
def finish_param_string
|
78
|
-
finish_upload_status "'a string'"
|
79
|
-
end
|
80
|
-
|
81
|
-
def finish_param_number
|
82
|
-
finish_upload_status 123
|
83
|
-
end
|
84
|
-
|
85
|
-
def finish_param_number_redirect
|
86
|
-
redirect_to "/redirected/"
|
87
|
-
finish_upload_status 123
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class MockIO < StringIO
|
93
|
-
def initialize(data='', &block)
|
94
|
-
test_logger.debug("MockIO inializing data: #{data[0..20]}")
|
95
|
-
|
96
|
-
@block = block
|
97
|
-
super(data)
|
98
|
-
end
|
99
|
-
|
100
|
-
def write(data)
|
101
|
-
test_logger.debug("MockIO write #{data.size} data: #{data[0..20]}")
|
102
|
-
super
|
103
|
-
end
|
104
|
-
def read(size)
|
105
|
-
test_logger.debug("MockIO getting data from super")
|
106
|
-
data = super
|
107
|
-
|
108
|
-
test_logger.debug("Calling read callback")
|
109
|
-
@block.call
|
110
|
-
|
111
|
-
test_logger.debug("Returning data: #{data.size}")
|
112
|
-
data
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
class MockCGI < CGI
|
117
|
-
BOUNDARY = '----------0xKhTmLbOuNdArY'
|
118
|
-
FILENAME = 'dummy.nul'
|
119
|
-
|
120
|
-
attr_reader :upload_id, :session_options, :session_id
|
121
|
-
|
122
|
-
def initialize(size=1000, url='/test', &block)
|
123
|
-
@url = url
|
124
|
-
@env = {}
|
125
|
-
@sio = MockIO.new('') { block.call(self) if block_given? }
|
126
|
-
|
127
|
-
@upload_id = '1'
|
128
|
-
|
129
|
-
add_param('param1', 'value1')
|
130
|
-
add_data(size)
|
131
|
-
add_param('param1', 'value2')
|
132
|
-
add_end_boundary
|
133
|
-
init_env
|
134
|
-
@sio.rewind
|
135
|
-
super()
|
136
|
-
end
|
137
|
-
|
138
|
-
#def stdinput_without_progress
|
139
|
-
# @sio
|
140
|
-
#end
|
141
|
-
|
142
|
-
def stdinput
|
143
|
-
@sio
|
144
|
-
end
|
145
|
-
|
146
|
-
def env_table
|
147
|
-
@env
|
148
|
-
end
|
149
|
-
|
150
|
-
private
|
151
|
-
def init_env
|
152
|
-
@env['HTTP_HOST'] = 'localhost'
|
153
|
-
@env['SERVER_PORT'] = '80'
|
154
|
-
@env['REQUEST_METHOD'] = "POST"
|
155
|
-
@env['QUERY_STRING'] = @url.split('?')[1] || "upload_id=#{upload_id}&query_param=query_value"
|
156
|
-
@env['REQUEST_URI'] = @url
|
157
|
-
@env['SCRIPT_NAME'] = @url.split('?').first.split('/').last
|
158
|
-
@env['PATH_INFO'] = @url.split('?').first
|
159
|
-
@env['CONTENT_TYPE'] = "multipart/form-data; boundary=#{BOUNDARY}"
|
160
|
-
@env['CONTENT_LENGTH'] = @sio.tell - EOL.size
|
161
|
-
|
162
|
-
@session_options = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.inject({}) { |options, pair|
|
163
|
-
options[pair.first.to_s] = pair.last; options
|
164
|
-
}
|
165
|
-
session = CGI::Session.new({}, @session_options.merge({'new_session' => true}))
|
166
|
-
@session_id = session.session_id
|
167
|
-
@env['COOKIE'] = "_session_id=#{session.session_id}"
|
168
|
-
session.close
|
169
|
-
end
|
170
|
-
|
171
|
-
def add_param(name, value)
|
172
|
-
add_boundary
|
173
|
-
@sio << "Content-Disposition: form-data; name=\"#{name}\"" << EOL << EOL
|
174
|
-
@sio << value.to_s << EOL
|
175
|
-
end
|
176
|
-
|
177
|
-
def add_data(size)
|
178
|
-
add_boundary
|
179
|
-
@sio << "Content-Disposition: form-data; name=\"file\"; filename=\"#{FILENAME}\"" << EOL
|
180
|
-
@sio << "Content-Type: application/octet-stream" << EOL << EOL
|
181
|
-
@sio << "." * size
|
182
|
-
@sio << EOL
|
183
|
-
end
|
184
|
-
|
185
|
-
def add_boundary
|
186
|
-
@sio << "--" << BOUNDARY << EOL
|
187
|
-
end
|
188
|
-
|
189
|
-
def add_end_boundary
|
190
|
-
@sio << "--" << BOUNDARY << "--" << EOL
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
class MultipartProgressTest < Test::Unit::TestCase
|
195
|
-
|
196
|
-
def test_domain_language_single
|
197
|
-
c = Controllers::SingleUploadController.new
|
198
|
-
assert_respond_to(c, :one)
|
199
|
-
assert_respond_to(c, :upload_status)
|
200
|
-
assert_respond_to(c, :finish_upload_status)
|
201
|
-
end
|
202
|
-
|
203
|
-
def test_domain_language_double
|
204
|
-
c = Controllers::DoubleUploadController.new
|
205
|
-
assert_respond_to(c, :one)
|
206
|
-
assert_respond_to(c, :two)
|
207
|
-
assert_respond_to(c, :upload_status)
|
208
|
-
assert_respond_to(c, :finish_upload_status)
|
209
|
-
end
|
210
|
-
|
211
|
-
def test_domain_language_double_status
|
212
|
-
c = Controllers::DoubleStatusUploadController.new
|
213
|
-
assert_respond_to(c, :one)
|
214
|
-
assert_respond_to(c, :two)
|
215
|
-
assert_respond_to(c, :custom_status)
|
216
|
-
assert_respond_to(c, :finish_upload_status)
|
217
|
-
end
|
218
|
-
|
219
|
-
def test_domain_language_double_seperate
|
220
|
-
c = Controllers::DoubleSeperateController.new
|
221
|
-
assert_respond_to(c, :one)
|
222
|
-
assert_respond_to(c, :two)
|
223
|
-
assert_respond_to(c, :upload_status)
|
224
|
-
assert_respond_to(c, :finish_upload_status)
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_finish_status_norendered
|
228
|
-
# Fails to render the upload finish script because there is no view associated with this action
|
229
|
-
test_logger.debug('test_finish_status_norendered')
|
230
|
-
|
231
|
-
res = process(:action => 'norendered', :upload_id => 1)
|
232
|
-
assert_match(/ActionView::ActionViewError/s, res.body)
|
233
|
-
|
234
|
-
res = process(:action => :upload_status, :upload_id => 1)
|
235
|
-
assert_match(/Upload finished/s, res.body)
|
236
|
-
|
237
|
-
res = process(:action => :norendered)
|
238
|
-
assert_match(/ActionView::ActionViewError/s, res.body)
|
239
|
-
end
|
240
|
-
|
241
|
-
def test_finish_status_rendered
|
242
|
-
test_logger.debug('test_finish_status_rendered')
|
243
|
-
|
244
|
-
res = process(:action => :rendered, :upload_id => 1)
|
245
|
-
assert_match(/stop\(\)/s, res.body)
|
246
|
-
assert_no_match(/rendered/s, res.body)
|
247
|
-
|
248
|
-
res = process(:action => :upload_status, :upload_id => 1)
|
249
|
-
assert_match(/Upload finished/s, res.body)
|
250
|
-
|
251
|
-
res = process(:action => :rendered)
|
252
|
-
assert_no_match(/stop\(\)/s, res.body)
|
253
|
-
assert_match(/rendered/, res.body)
|
254
|
-
end
|
255
|
-
|
256
|
-
def test_finish_status_redirected
|
257
|
-
test_logger.debug('test_finish_status_redirected')
|
258
|
-
|
259
|
-
res = process(:action => :redirected, :upload_id => 1)
|
260
|
-
assert_match(/location\.replace/s, res.body)
|
261
|
-
|
262
|
-
res = process(:action => :redirected)
|
263
|
-
assert_no_match(/location\.replace/s, res.body)
|
264
|
-
assert_match(/\/redirected\//s, res.headers['location'])
|
265
|
-
assert_match(/302 .*$/, res.headers['Status'])
|
266
|
-
|
267
|
-
res = process(:action => :upload_status, :upload_id => 1)
|
268
|
-
assert_match(/Upload finished/s, res.body)
|
269
|
-
end
|
270
|
-
|
271
|
-
def test_finish_status_finish_param
|
272
|
-
test_logger.debug('test_finish_status_param')
|
273
|
-
|
274
|
-
res = process(:action => :finish_param_string, :upload_id => 1)
|
275
|
-
assert_match(/stop\('a string'\)/s, res.body)
|
276
|
-
assert_no_redirect res
|
277
|
-
|
278
|
-
res = process(:action => :finish_param_dict, :upload_id => 1)
|
279
|
-
assert_match(/stop\(\{a: 'b'\}\)/s, res.body)
|
280
|
-
assert_no_redirect res
|
281
|
-
|
282
|
-
res = process(:action => :finish_param_number, :upload_id => 1)
|
283
|
-
assert_match(/stop\(123\)/s, res.body)
|
284
|
-
assert_no_redirect res
|
285
|
-
|
286
|
-
res = process(:action => :finish_param_number_redirect, :upload_id => 1)
|
287
|
-
test_logger.debug('test_finish_status_param: ' + res.body)
|
288
|
-
assert_match(/stop\(123\)/s, res.body)
|
289
|
-
assert_match(/replace\('\http:\/\/localhost\/redirected\/'\).*?/s, res.body)
|
290
|
-
assert_no_redirect res
|
291
|
-
end
|
292
|
-
|
293
|
-
def test_basic_setup
|
294
|
-
test_logger.debug('test_basic_setup')
|
295
|
-
|
296
|
-
cgi, request, response = new_request(100000)
|
297
|
-
assert_not_nil(request.session)
|
298
|
-
assert_not_nil(request.session[:uploads], "uploads collection not set")
|
299
|
-
assert_not_nil(request.session[:uploads][cgi.upload_id], "upload id not set")
|
300
|
-
progress = request.session[:uploads][cgi.upload_id]
|
301
|
-
assert_equal(true, progress.finished?)
|
302
|
-
end
|
303
|
-
|
304
|
-
def test_params
|
305
|
-
test_logger.debug('test_params')
|
306
|
-
|
307
|
-
cgi, request, response = new_request(1000)
|
308
|
-
assert(!request.params.empty?)
|
309
|
-
assert(!request.params['param1'].empty?)
|
310
|
-
end
|
311
|
-
|
312
|
-
def test_share_session
|
313
|
-
cgi, request, response = new_request(100000) do |cgi, req|
|
314
|
-
if cgi.stdinput.tell > 50000
|
315
|
-
# force a save
|
316
|
-
cgi.stdinput.save_progress rescue flunk('Something else is wrong, our wrapper isnt setup, is ActionController::Base.logger set?')
|
317
|
-
|
318
|
-
other_session = CGI::Session.new(cgi, cgi.session_options.merge({'session_id' => cgi.session_id}))
|
319
|
-
assert_not_nil(other_session[:uploads])
|
320
|
-
assert_not_nil(other_session[:uploads][cgi.upload_id])
|
321
|
-
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")
|
322
|
-
|
323
|
-
other_session.close
|
324
|
-
end
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
def test_upload_ids
|
329
|
-
c = Controllers::MockController.new
|
330
|
-
(1..222).each do |id|
|
331
|
-
c.params = {}
|
332
|
-
|
333
|
-
assert_equal((id-1).to_s, c.last_upload_id, "last_upload_id is out of sync")
|
334
|
-
assert_equal(id.to_s, c.next_upload_id, "next_upload_id is out of sync")
|
335
|
-
assert_equal(id.to_s, c.current_upload_id, "current_upload_id is out of sync")
|
336
|
-
|
337
|
-
c.params = {:upload_id => (id-1).to_s}
|
338
|
-
assert_equal((id-1).to_s, c.current_upload_id, "current_upload_id is out of sync")
|
339
|
-
|
340
|
-
c.session[:uploads][id] = {}
|
341
|
-
end
|
342
|
-
end
|
343
|
-
|
344
|
-
private
|
345
|
-
def new_request(size=1000, url='/test', &block)
|
346
|
-
test_logger.debug('Creating MockCGI')
|
347
|
-
cgi = MockCGI.new(size, url) do |cgi|
|
348
|
-
block.call(cgi) if block_given?
|
349
|
-
end
|
350
|
-
|
351
|
-
assert(cgi.private_methods.include?("read_multipart_with_progress"))
|
352
|
-
return [cgi, ActionController::CgiRequest.new(cgi), ActionController::CgiResponse.new(cgi)]
|
353
|
-
end
|
354
|
-
|
355
|
-
def process(options = {})
|
356
|
-
Controllers::UploadController.process(*(new_request(1000, '/upload?' + options.map {|k,v| "#{k}=#{v}"}.join('&'))[1..2]))
|
357
|
-
end
|
358
|
-
|
359
|
-
def assert_no_redirect(res)
|
360
|
-
assert_nil(res.redirected_to)
|
361
|
-
assert_nil(res.headers['location'])
|
362
|
-
assert_match(/200 .*$/, res.headers['Status'])
|
363
|
-
end
|
364
|
-
|
365
|
-
end
|
@@ -1,89 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
-
require 'test/unit'
|
3
|
-
require 'cgi'
|
4
|
-
require 'stringio'
|
5
|
-
|
6
|
-
class UploadProgressTest < Test::Unit::TestCase
|
7
|
-
def test_remaining
|
8
|
-
progress = new_progress(20000)
|
9
|
-
assert_equal(0, progress.received_bytes)
|
10
|
-
assert_equal(20000, progress.remaining_bytes)
|
11
|
-
progress.update!(10000, 1.0)
|
12
|
-
assert_equal(10000, progress.remaining_bytes)
|
13
|
-
assert_equal(1.0, progress.remaining_seconds)
|
14
|
-
assert_equal(50, progress.completed_percent)
|
15
|
-
assert_equal(true, progress.started?)
|
16
|
-
assert_equal(false, progress.finished?)
|
17
|
-
assert_equal(false, progress.stalled?)
|
18
|
-
progress.update!(10000, 2.0)
|
19
|
-
assert_equal(true, progress.finished?)
|
20
|
-
assert_equal(0.0, progress.remaining_seconds)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_stalled
|
24
|
-
progress = new_progress(10000)
|
25
|
-
assert_equal(false, progress.stalled?)
|
26
|
-
progress.update!(100, 1.0)
|
27
|
-
assert_equal(false, progress.stalled?)
|
28
|
-
progress.update!(100, 20.0)
|
29
|
-
assert_equal(true, progress.stalled?)
|
30
|
-
assert_in_delta(0.0, progress.bitrate, 0.001)
|
31
|
-
progress.update!(100, 21.0)
|
32
|
-
assert_equal(false, progress.stalled?)
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_elapsed
|
36
|
-
progress = new_progress(10000)
|
37
|
-
(1..5).each do |t|
|
38
|
-
progress.update!(1000, Float(t))
|
39
|
-
end
|
40
|
-
assert_in_delta(5.0, progress.elapsed_seconds, 0.001)
|
41
|
-
assert_equal(10000, progress.total_bytes)
|
42
|
-
assert_equal(5000, progress.received_bytes)
|
43
|
-
assert_equal(5000, progress.remaining_bytes)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_overflow
|
47
|
-
progress = new_progress(10000)
|
48
|
-
progress.update!(20000, 1.0)
|
49
|
-
assert_equal(10000, progress.received_bytes)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_zero
|
53
|
-
progress = new_progress(0)
|
54
|
-
assert_equal(0, progress.total_bytes)
|
55
|
-
assert_equal(0, progress.remaining_bytes)
|
56
|
-
assert_equal(false, progress.started?)
|
57
|
-
assert_equal(true, progress.finished?)
|
58
|
-
assert_equal(0, progress.bitrate)
|
59
|
-
assert_equal(0, progress.completed_percent)
|
60
|
-
assert_equal(0, progress.remaining_seconds)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_finished
|
64
|
-
progress = new_progress(10000)
|
65
|
-
(1..9).each do |t|
|
66
|
-
progress.update!(1000, Float(t))
|
67
|
-
assert_equal(false, progress.finished?)
|
68
|
-
assert_equal(1000.0, progress.bitrate)
|
69
|
-
assert_equal(false, progress.stalled?)
|
70
|
-
end
|
71
|
-
assert_equal(false, progress.finished?)
|
72
|
-
progress.update!(1000, 10.0)
|
73
|
-
assert_equal(true, progress.finished?)
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_rapid_samples
|
77
|
-
progress = new_progress(10000)
|
78
|
-
(1..1000).each do |t|
|
79
|
-
progress.update!(10, t/100.0)
|
80
|
-
end
|
81
|
-
assert_in_delta(1000.0, progress.bitrate, 0.001)
|
82
|
-
assert_equal(true, progress.finished?)
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
def new_progress(total)
|
87
|
-
ActionController::UploadProgress::Progress.new(total)
|
88
|
-
end
|
89
|
-
end
|