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
@@ -6,12 +6,14 @@ end
|
|
6
6
|
|
7
7
|
module ActionController #:nodoc:
|
8
8
|
module SessionManagement #:nodoc:
|
9
|
-
def self.
|
10
|
-
super
|
9
|
+
def self.included(base)
|
11
10
|
base.extend(ClassMethods)
|
12
|
-
|
13
|
-
base.send
|
14
|
-
base.
|
11
|
+
|
12
|
+
base.send :alias_method, :process_without_session_management_support, :process
|
13
|
+
base.send :alias_method, :process, :process_with_session_management_support
|
14
|
+
|
15
|
+
base.send :alias_method, :process_cleanup_without_session_management_support, :process_cleanup
|
16
|
+
base.send :alias_method, :process_cleanup, :process_cleanup_with_session_management_support
|
15
17
|
end
|
16
18
|
|
17
19
|
module ClassMethods
|
@@ -111,15 +113,32 @@ module ActionController #:nodoc:
|
|
111
113
|
end
|
112
114
|
|
113
115
|
def process_with_session_management_support(request, response, method = :perform_action, *arguments) #:nodoc:
|
114
|
-
|
115
|
-
request.session_options = self.class.session_options_for(request, action)
|
116
|
+
set_session_options(request)
|
116
117
|
process_without_session_management_support(request, response, method, *arguments)
|
117
118
|
end
|
118
|
-
|
119
|
+
|
119
120
|
private
|
120
|
-
def
|
121
|
-
|
122
|
-
|
121
|
+
def set_session_options(request)
|
122
|
+
request.session_options = self.class.session_options_for(request, request.parameters["action"] || "index")
|
123
|
+
end
|
124
|
+
|
125
|
+
def process_cleanup_with_session_management_support
|
126
|
+
process_cleanup_without_session_management_support
|
127
|
+
clear_persistent_model_associations
|
128
|
+
end
|
129
|
+
|
130
|
+
# Clear cached associations in session data so they don't overflow
|
131
|
+
# the database field. Only applies to ActiveRecordStore since there
|
132
|
+
# is not a standard way to iterate over session data.
|
133
|
+
def clear_persistent_model_associations #:doc:
|
134
|
+
if defined?(@session) && @session.instance_variables.include?('@data')
|
135
|
+
session_data = @session.instance_variable_get('@data')
|
136
|
+
|
137
|
+
if session_data && session_data.respond_to?(:each_value)
|
138
|
+
session_data.each_value do |obj|
|
139
|
+
obj.clear_association_cache if obj.respond_to?(:clear_association_cache)
|
140
|
+
end
|
141
|
+
end
|
123
142
|
end
|
124
143
|
end
|
125
144
|
end
|
@@ -28,7 +28,7 @@
|
|
28
28
|
display: table;
|
29
29
|
}
|
30
30
|
|
31
|
-
#
|
31
|
+
#errorExplanation {
|
32
32
|
width: 400px;
|
33
33
|
border: 2px solid red;
|
34
34
|
padding: 7px;
|
@@ -37,7 +37,7 @@
|
|
37
37
|
background-color: #f0f0f0;
|
38
38
|
}
|
39
39
|
|
40
|
-
#
|
40
|
+
#errorExplanation h2 {
|
41
41
|
text-align: left;
|
42
42
|
font-weight: bold;
|
43
43
|
padding: 5px 5px 5px 15px;
|
@@ -47,13 +47,13 @@
|
|
47
47
|
color: #fff;
|
48
48
|
}
|
49
49
|
|
50
|
-
#
|
50
|
+
#errorExplanation p {
|
51
51
|
color: #333;
|
52
52
|
margin-bottom: 0;
|
53
53
|
padding: 5px;
|
54
54
|
}
|
55
55
|
|
56
|
-
#
|
56
|
+
#errorExplanation ul li {
|
57
57
|
font-size: 12px;
|
58
58
|
list-style: square;
|
59
59
|
}
|
@@ -14,7 +14,7 @@
|
|
14
14
|
<% end %>
|
15
15
|
<td><%= link_to "Show", :action => "show#{@scaffold_suffix}", :id => entry %></td>
|
16
16
|
<td><%= link_to "Edit", :action => "edit#{@scaffold_suffix}", :id => entry %></td>
|
17
|
-
<td><%= link_to "Destroy", {:action => "destroy#{@scaffold_suffix}", :id => entry}, {:confirm => "Are you sure?"} %></td>
|
17
|
+
<td><%= link_to "Destroy", {:action => "destroy#{@scaffold_suffix}", :id => entry}, { :confirm => "Are you sure?", :post => true} %></td>
|
18
18
|
</tr>
|
19
19
|
<% end %>
|
20
20
|
</table>
|
@@ -41,7 +41,21 @@ module ActionController #:nodoc:
|
|
41
41
|
def reset_session
|
42
42
|
@session = {}
|
43
43
|
end
|
44
|
+
|
45
|
+
def raw_post
|
46
|
+
if raw_post = env['RAW_POST_DATA']
|
47
|
+
raw_post
|
48
|
+
else
|
49
|
+
params = self.request_parameters.dup
|
50
|
+
%w(controller action only_path).each do |k|
|
51
|
+
params.delete(k)
|
52
|
+
params.delete(k.to_sym)
|
53
|
+
end
|
44
54
|
|
55
|
+
params.map { |k,v| [ CGI.escape(k.to_s), CGI.escape(v.to_s) ].join('=') }.sort.join('&')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
45
59
|
def port=(number)
|
46
60
|
@env["SERVER_PORT"] = number.to_i
|
47
61
|
@port_as_int = nil
|
@@ -102,8 +116,9 @@ module ActionController #:nodoc:
|
|
102
116
|
|
103
117
|
def recycle!
|
104
118
|
self.request_parameters = {}
|
105
|
-
self.query_parameters = {}
|
106
|
-
self.path_parameters = {}
|
119
|
+
self.query_parameters = {}
|
120
|
+
self.path_parameters = {}
|
121
|
+
@request_method, @accepts, @content_type = nil, nil, nil
|
107
122
|
end
|
108
123
|
|
109
124
|
private
|
@@ -120,7 +135,9 @@ module ActionController #:nodoc:
|
|
120
135
|
end
|
121
136
|
end
|
122
137
|
|
123
|
-
|
138
|
+
# A refactoring of TestResponse to allow the same behavior to be applied
|
139
|
+
# to the "real" CgiResponse class in integration tests.
|
140
|
+
module TestResponseBehavior #:nodoc:
|
124
141
|
# the response code of the request
|
125
142
|
def response_code
|
126
143
|
headers['Status'][0,3].to_i rescue 0
|
@@ -248,7 +265,11 @@ module ActionController #:nodoc:
|
|
248
265
|
sio.rewind
|
249
266
|
sio.read
|
250
267
|
end
|
251
|
-
end
|
268
|
+
end
|
269
|
+
|
270
|
+
class TestResponse < AbstractResponse #:nodoc:
|
271
|
+
include TestResponseBehavior
|
272
|
+
end
|
252
273
|
|
253
274
|
class TestSession #:nodoc:
|
254
275
|
def initialize(attributes = {})
|
@@ -271,141 +292,191 @@ end
|
|
271
292
|
def close() end
|
272
293
|
def delete() @attributes = {} end
|
273
294
|
end
|
274
|
-
|
275
|
-
|
276
|
-
module
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
295
|
+
|
296
|
+
# Essentially generates a modified Tempfile object similar to the object
|
297
|
+
# you'd get from the standard library CGI module in a multipart
|
298
|
+
# request. This means you can use an ActionController::TestUploadedFile
|
299
|
+
# object in the params of a test request in order to simulate
|
300
|
+
# a file upload.
|
301
|
+
#
|
302
|
+
# Usage example, within a functional test:
|
303
|
+
# post :change_avatar, :avatar => ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/spongebob.png', 'image/png')
|
304
|
+
class TestUploadedFile
|
305
|
+
# The filename, *not* including the path, of the "uploaded" file
|
306
|
+
attr_reader :original_filename
|
307
|
+
|
308
|
+
# The content type of the "uploaded" file
|
309
|
+
attr_reader :content_type
|
310
|
+
|
311
|
+
def initialize(path, content_type = 'text/plain')
|
312
|
+
raise "file does not exist" unless File.exist?(path)
|
313
|
+
@content_type = content_type
|
314
|
+
@original_filename = path.sub(/^.*#{File::SEPARATOR}([^#{File::SEPARATOR}]+)$/) { $1 }
|
315
|
+
@tempfile = Tempfile.new(@original_filename)
|
316
|
+
FileUtils.copy_file(path, @tempfile.path)
|
317
|
+
end
|
318
|
+
|
319
|
+
def path #:nodoc:
|
320
|
+
@tempfile.path
|
321
|
+
end
|
322
|
+
|
323
|
+
alias local_path path
|
324
|
+
|
325
|
+
def method_missing(method_name, *args, &block) #:nodoc:
|
326
|
+
@tempfile.send(method_name, *args, &block)
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
module TestProcess
|
331
|
+
def self.included(base)
|
332
|
+
# execute the request simulating a specific http method and set/volley the response
|
333
|
+
%w( get post put delete head ).each do |method|
|
334
|
+
base.class_eval <<-EOV, __FILE__, __LINE__
|
335
|
+
def #{method}(action, parameters = nil, session = nil, flash = nil)
|
336
|
+
@request.env['REQUEST_METHOD'] = "#{method.upcase}" if @request
|
337
|
+
process(action, parameters, session, flash)
|
286
338
|
end
|
339
|
+
EOV
|
340
|
+
end
|
341
|
+
end
|
287
342
|
|
288
|
-
|
343
|
+
# execute the request and set/volley the response
|
344
|
+
def process(action, parameters = nil, session = nil, flash = nil)
|
345
|
+
# Sanity check for required instance variables so we can give an
|
346
|
+
# understandable error message.
|
347
|
+
%w(controller request response).each do |iv_name|
|
348
|
+
raise "@#{iv_name} is nil: make sure you set it in your test's setup method." if instance_variable_get("@#{iv_name}").nil?
|
349
|
+
end
|
289
350
|
|
290
|
-
|
291
|
-
@request.env['REQUEST_METHOD'] ||= "GET"
|
292
|
-
@request.action = action.to_s
|
351
|
+
@request.recycle!
|
293
352
|
|
294
|
-
|
295
|
-
|
353
|
+
@html_document = nil
|
354
|
+
@request.env['REQUEST_METHOD'] ||= "GET"
|
355
|
+
@request.action = action.to_s
|
296
356
|
|
297
|
-
|
298
|
-
|
299
|
-
build_request_uri(action, parameters)
|
300
|
-
@controller.process(@request, @response)
|
301
|
-
end
|
357
|
+
parameters ||= {}
|
358
|
+
@request.assign_parameters(@controller.class.controller_path, action.to_s, parameters)
|
302
359
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
process(action, parameters, session, flash)
|
309
|
-
end
|
310
|
-
EOV
|
311
|
-
end
|
360
|
+
@request.session = ActionController::TestSession.new(session) unless session.nil?
|
361
|
+
@request.session["flash"] = ActionController::Flash::FlashHash.new.update(flash) if flash
|
362
|
+
build_request_uri(action, parameters)
|
363
|
+
@controller.process(@request, @response)
|
364
|
+
end
|
312
365
|
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
366
|
+
def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
|
367
|
+
@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
|
368
|
+
@request.env['HTTP_ACCEPT'] = 'text/javascript, text/html, application/xml, text/xml, */*'
|
369
|
+
returning self.send(request_method, action, parameters, session, flash) do
|
370
|
+
@request.env.delete 'HTTP_X_REQUESTED_WITH'
|
371
|
+
@request.env.delete 'HTTP_ACCEPT'
|
372
|
+
end
|
373
|
+
end
|
374
|
+
alias xhr :xml_http_request
|
320
375
|
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
376
|
+
def follow_redirect
|
377
|
+
if @response.redirected_to[:controller]
|
378
|
+
raise "Can't follow redirects outside of current controller (#{@response.redirected_to[:controller]})"
|
379
|
+
end
|
325
380
|
|
326
|
-
|
327
|
-
|
381
|
+
get(@response.redirected_to.delete(:action), @response.redirected_to.stringify_keys)
|
382
|
+
end
|
328
383
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
384
|
+
def assigns(key = nil)
|
385
|
+
if key.nil?
|
386
|
+
@response.template.assigns
|
387
|
+
else
|
388
|
+
@response.template.assigns[key.to_s]
|
389
|
+
end
|
390
|
+
end
|
336
391
|
|
337
|
-
|
338
|
-
|
339
|
-
|
392
|
+
def session
|
393
|
+
@response.session
|
394
|
+
end
|
340
395
|
|
341
|
-
|
342
|
-
|
343
|
-
|
396
|
+
def flash
|
397
|
+
@response.flash
|
398
|
+
end
|
344
399
|
|
345
|
-
|
346
|
-
|
347
|
-
|
400
|
+
def cookies
|
401
|
+
@response.cookies
|
402
|
+
end
|
348
403
|
|
349
|
-
|
350
|
-
|
351
|
-
|
404
|
+
def redirect_to_url
|
405
|
+
@response.redirect_url
|
406
|
+
end
|
352
407
|
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
408
|
+
def build_request_uri(action, parameters)
|
409
|
+
unless @request.env['REQUEST_URI']
|
410
|
+
options = @controller.send(:rewrite_options, parameters)
|
411
|
+
options.update(:only_path => true, :action => action)
|
357
412
|
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
413
|
+
url = ActionController::UrlRewriter.new(@request, parameters)
|
414
|
+
@request.set_REQUEST_URI(url.rewrite(options))
|
415
|
+
end
|
416
|
+
end
|
362
417
|
|
363
|
-
|
364
|
-
|
365
|
-
|
418
|
+
def html_document
|
419
|
+
@html_document ||= HTML::Document.new(@response.body)
|
420
|
+
end
|
366
421
|
|
367
|
-
|
368
|
-
|
369
|
-
|
422
|
+
def find_tag(conditions)
|
423
|
+
html_document.find(conditions)
|
424
|
+
end
|
370
425
|
|
371
|
-
|
372
|
-
|
373
|
-
|
426
|
+
def find_all_tag(conditions)
|
427
|
+
html_document.find_all(conditions)
|
428
|
+
end
|
374
429
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
430
|
+
def method_missing(selector, *args)
|
431
|
+
return @controller.send(selector, *args) if ActionController::Routing::NamedRoutes::Helpers.include?(selector)
|
432
|
+
return super
|
433
|
+
end
|
434
|
+
|
435
|
+
# Shortcut for ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + path, type). Example:
|
436
|
+
# post :change_avatar, :avatar => fixture_file_upload('/files/spongebob.png', 'image/png')
|
437
|
+
def fixture_file_upload(path, mime_type = nil)
|
438
|
+
ActionController::TestUploadedFile.new(
|
439
|
+
Test::Unit::TestCase.respond_to?(:fixture_path) ? Test::Unit::TestCase.fixture_path + path : path,
|
440
|
+
mime_type
|
441
|
+
)
|
442
|
+
end
|
443
|
+
|
444
|
+
# A helper to make it easier to test different route configurations.
|
445
|
+
# This method temporarily replaces ActionController::Routing::Routes
|
446
|
+
# with a new RouteSet instance.
|
447
|
+
#
|
448
|
+
# The new instance is yielded to the passed block. Typically the block
|
449
|
+
# will create some routes using map.draw { map.connect ... }:
|
450
|
+
#
|
451
|
+
# with_routing do |set|
|
452
|
+
# set.draw { set.connect ':controller/:id/:action' }
|
453
|
+
# assert_equal(
|
454
|
+
# ['/content/10/show', {}],
|
455
|
+
# set.generate(:controller => 'content', :id => 10, :action => 'show')
|
456
|
+
# )
|
457
|
+
# end
|
458
|
+
#
|
459
|
+
def with_routing
|
460
|
+
real_routes = ActionController::Routing::Routes
|
461
|
+
ActionController::Routing.send :remove_const, :Routes
|
462
|
+
|
463
|
+
temporary_routes = ActionController::Routing::RouteSet.new
|
464
|
+
ActionController::Routing.send :const_set, :Routes, temporary_routes
|
465
|
+
|
466
|
+
yield temporary_routes
|
467
|
+
ensure
|
468
|
+
if ActionController::Routing.const_defined? :Routes
|
469
|
+
ActionController::Routing.send(:remove_const, :Routes)
|
470
|
+
end
|
471
|
+
ActionController::Routing.const_set(:Routes, real_routes) if real_routes
|
472
|
+
end
|
473
|
+
end
|
474
|
+
end
|
379
475
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
# The new instance is yielded to the passed block. Typically the block
|
385
|
-
# will create some routes using map.draw { map.connect ... }:
|
386
|
-
#
|
387
|
-
# with_routing do |set|
|
388
|
-
# set.draw { set.connect ':controller/:id/:action' }
|
389
|
-
# assert_equal(
|
390
|
-
# ['/content/10/show', {}],
|
391
|
-
# set.generate(:controller => 'content', :id => 10, :action => 'show')
|
392
|
-
# )
|
393
|
-
# end
|
394
|
-
#
|
395
|
-
def with_routing
|
396
|
-
real_routes = ActionController::Routing::Routes
|
397
|
-
ActionController::Routing.send :remove_const, :Routes
|
398
|
-
|
399
|
-
temporary_routes = ActionController::Routing::RouteSet.new
|
400
|
-
ActionController::Routing.send :const_set, :Routes, temporary_routes
|
401
|
-
|
402
|
-
yield temporary_routes
|
403
|
-
ensure
|
404
|
-
if ActionController::Routing.const_defined? :Routes
|
405
|
-
ActionController::Routing.send(:remove_const, :Routes)
|
406
|
-
end
|
407
|
-
ActionController::Routing.const_set(:Routes, real_routes) if real_routes
|
408
|
-
end
|
476
|
+
module Test
|
477
|
+
module Unit
|
478
|
+
class TestCase #:nodoc:
|
479
|
+
include ActionController::TestProcess
|
409
480
|
end
|
410
481
|
end
|
411
482
|
end
|