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.

Files changed (149) hide show
  1. data/CHANGELOG +392 -5
  2. data/lib/action_controller.rb +8 -4
  3. data/lib/action_controller/assertions.rb +9 -10
  4. data/lib/action_controller/base.rb +177 -88
  5. data/lib/action_controller/benchmarking.rb +5 -5
  6. data/lib/action_controller/caching.rb +44 -36
  7. data/lib/action_controller/cgi_ext/cgi_methods.rb +71 -6
  8. data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +1 -1
  9. data/lib/action_controller/cgi_process.rb +36 -24
  10. data/lib/action_controller/components.rb +152 -52
  11. data/lib/action_controller/dependencies.rb +1 -1
  12. data/lib/action_controller/deprecated_redirects.rb +2 -2
  13. data/lib/action_controller/deprecated_request_methods.rb +34 -0
  14. data/lib/action_controller/filters.rb +59 -19
  15. data/lib/action_controller/flash.rb +53 -47
  16. data/lib/action_controller/helpers.rb +2 -2
  17. data/lib/action_controller/integration.rb +524 -0
  18. data/lib/action_controller/layout.rb +58 -23
  19. data/lib/action_controller/mime_responds.rb +163 -0
  20. data/lib/action_controller/mime_type.rb +142 -0
  21. data/lib/action_controller/pagination.rb +13 -7
  22. data/lib/action_controller/request.rb +59 -56
  23. data/lib/action_controller/rescue.rb +1 -1
  24. data/lib/action_controller/routing.rb +29 -10
  25. data/lib/action_controller/scaffolding.rb +8 -0
  26. data/lib/action_controller/session/active_record_store.rb +21 -10
  27. data/lib/action_controller/session/mem_cache_store.rb +18 -12
  28. data/lib/action_controller/session_management.rb +30 -11
  29. data/lib/action_controller/templates/rescues/_trace.rhtml +1 -1
  30. data/lib/action_controller/templates/scaffolds/layout.rhtml +4 -4
  31. data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
  32. data/lib/action_controller/test_process.rb +189 -118
  33. data/lib/action_controller/vendor/html-scanner/html/node.rb +20 -1
  34. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +3 -0
  35. data/lib/action_controller/vendor/html-scanner/html/version.rb +1 -1
  36. data/lib/action_controller/vendor/xml_node.rb +97 -0
  37. data/lib/action_controller/verification.rb +2 -0
  38. data/lib/action_pack/version.rb +3 -3
  39. data/lib/action_view.rb +0 -2
  40. data/lib/action_view/base.rb +109 -36
  41. data/lib/action_view/compiled_templates.rb +1 -1
  42. data/lib/action_view/helpers/active_record_helper.rb +4 -2
  43. data/lib/action_view/helpers/asset_tag_helper.rb +6 -7
  44. data/lib/action_view/helpers/capture_helper.rb +49 -12
  45. data/lib/action_view/helpers/date_helper.rb +14 -4
  46. data/lib/action_view/helpers/form_helper.rb +136 -20
  47. data/lib/action_view/helpers/form_options_helper.rb +29 -7
  48. data/lib/action_view/helpers/form_tag_helper.rb +22 -20
  49. data/lib/action_view/helpers/java_script_macros_helper.rb +29 -9
  50. data/lib/action_view/helpers/javascript_helper.rb +50 -446
  51. data/lib/action_view/helpers/javascripts/controls.js +95 -30
  52. data/lib/action_view/helpers/javascripts/dragdrop.js +161 -21
  53. data/lib/action_view/helpers/javascripts/effects.js +310 -211
  54. data/lib/action_view/helpers/javascripts/prototype.js +228 -28
  55. data/lib/action_view/helpers/number_helper.rb +9 -9
  56. data/lib/action_view/helpers/pagination_helper.rb +1 -1
  57. data/lib/action_view/helpers/prototype_helper.rb +900 -0
  58. data/lib/action_view/helpers/scriptaculous_helper.rb +135 -0
  59. data/lib/action_view/helpers/text_helper.rb +7 -6
  60. data/lib/action_view/helpers/url_helper.rb +23 -14
  61. data/lib/action_view/partials.rb +12 -4
  62. data/rakefile +13 -5
  63. data/test/abstract_unit.rb +4 -3
  64. data/test/active_record_unit.rb +88 -0
  65. data/test/{controller → activerecord}/active_record_assertions_test.rb +7 -50
  66. data/test/{controller → activerecord}/active_record_store_test.rb +27 -4
  67. data/test/activerecord/pagination_test.rb +161 -0
  68. data/test/controller/action_pack_assertions_test.rb +18 -15
  69. data/test/controller/base_test.rb +31 -42
  70. data/test/controller/benchmark_test.rb +8 -11
  71. data/test/controller/capture_test.rb +33 -1
  72. data/test/controller/cgi_test.rb +33 -0
  73. data/test/controller/custom_handler_test.rb +8 -0
  74. data/test/controller/fake_controllers.rb +9 -17
  75. data/test/controller/filters_test.rb +32 -3
  76. data/test/controller/flash_test.rb +26 -41
  77. data/test/controller/fragment_store_setting_test.rb +1 -1
  78. data/test/controller/layout_test.rb +73 -0
  79. data/test/controller/mime_responds_test.rb +257 -0
  80. data/test/controller/mime_type_test.rb +24 -0
  81. data/test/controller/new_render_test.rb +157 -1
  82. data/test/controller/redirect_test.rb +23 -0
  83. data/test/controller/render_test.rb +54 -56
  84. data/test/controller/request_test.rb +25 -0
  85. data/test/controller/routing_test.rb +74 -66
  86. data/test/controller/test_test.rb +66 -1
  87. data/test/controller/verification_test.rb +3 -1
  88. data/test/controller/webservice_test.rb +255 -0
  89. data/test/fixtures/companies.yml +24 -0
  90. data/test/fixtures/company.rb +9 -0
  91. data/test/fixtures/db_definitions/sqlite.sql +42 -0
  92. data/test/fixtures/developer.rb +7 -0
  93. data/test/fixtures/developers.yml +21 -0
  94. data/test/fixtures/developers_projects.yml +13 -0
  95. data/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml +1 -0
  96. data/test/fixtures/layout_tests/layouts/item.rhtml +1 -0
  97. data/test/fixtures/layout_tests/layouts/layout_test.rhtml +1 -0
  98. data/test/fixtures/layout_tests/layouts/third_party_template_library.mab +1 -0
  99. data/test/fixtures/layout_tests/views/hello.rhtml +1 -0
  100. data/test/fixtures/multipart/mona_lisa.jpg +0 -0
  101. data/test/fixtures/project.rb +3 -0
  102. data/test/fixtures/projects.yml +7 -0
  103. data/test/fixtures/replies.yml +13 -0
  104. data/test/fixtures/reply.rb +5 -0
  105. data/test/fixtures/respond_to/all_types_with_layout.rhtml +1 -0
  106. data/test/fixtures/respond_to/all_types_with_layout.rjs +1 -0
  107. data/test/fixtures/respond_to/layouts/standard.rhtml +1 -0
  108. data/test/fixtures/respond_to/using_defaults.rhtml +1 -0
  109. data/test/fixtures/respond_to/using_defaults.rjs +1 -0
  110. data/test/fixtures/respond_to/using_defaults.rxml +1 -0
  111. data/test/fixtures/respond_to/using_defaults_with_type_list.rhtml +1 -0
  112. data/test/fixtures/respond_to/using_defaults_with_type_list.rjs +1 -0
  113. data/test/fixtures/respond_to/using_defaults_with_type_list.rxml +1 -0
  114. data/test/fixtures/test/block_content_for.rhtml +2 -0
  115. data/test/fixtures/test/delete_with_js.rjs +2 -0
  116. data/test/fixtures/test/dot.directory/render_file_with_ivar.rhtml +1 -0
  117. data/test/fixtures/test/enum_rjs_test.rjs +6 -0
  118. data/test/fixtures/test/erb_content_for.rhtml +2 -0
  119. data/test/fixtures/test/hello_world.rxml +3 -0
  120. data/test/fixtures/test/hello_world_with_layout_false.rhtml +1 -0
  121. data/test/fixtures/test/non_erb_block_content_for.rxml +4 -0
  122. data/test/fixtures/topic.rb +3 -0
  123. data/test/fixtures/topics.yml +22 -0
  124. data/test/template/active_record_helper_test.rb +4 -0
  125. data/test/template/asset_tag_helper_test.rb +7 -2
  126. data/test/template/date_helper_test.rb +39 -2
  127. data/test/template/form_helper_test.rb +238 -5
  128. data/test/template/form_options_helper_test.rb +78 -0
  129. data/test/template/form_tag_helper_test.rb +11 -0
  130. data/test/template/java_script_macros_helper_test.rb +51 -6
  131. data/test/template/javascript_helper_test.rb +7 -153
  132. data/test/template/number_helper_test.rb +14 -13
  133. data/test/template/prototype_helper_test.rb +423 -0
  134. data/test/template/scriptaculous_helper_test.rb +90 -0
  135. data/test/template/text_helper_test.rb +12 -9
  136. data/test/template/url_helper_test.rb +31 -15
  137. metadata +291 -246
  138. data/lib/action_controller/cgi_ext/multipart_progress.rb +0 -169
  139. data/lib/action_controller/upload_progress.rb +0 -473
  140. data/lib/action_controller/vendor/html-scanner/html/node.rb.rej +0 -17
  141. data/lib/action_view/helpers/upload_progress_helper.rb +0 -433
  142. data/lib/action_view/vendor/builder.rb +0 -13
  143. data/lib/action_view/vendor/builder/blankslate.rb +0 -53
  144. data/lib/action_view/vendor/builder/xmlbase.rb +0 -143
  145. data/lib/action_view/vendor/builder/xmlevents.rb +0 -63
  146. data/lib/action_view/vendor/builder/xmlmarkup.rb +0 -308
  147. data/test/controller/multipart_progress_testx.rb +0 -365
  148. data/test/controller/upload_progress_testx.rb +0 -89
  149. 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.append_features(base)
10
- super
9
+ def self.included(base)
11
10
  base.extend(ClassMethods)
12
- base.send(:alias_method, :process_without_session_management_support, :process)
13
- base.send(:alias_method, :process, :process_with_session_management_support)
14
- base.after_filter(:clear_persistant_model_associations)
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
- action = request.parameters["action"] || "index"
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 clear_persistant_model_associations #:doc:
121
- if session = @session.instance_variable_get("@data")
122
- session.each { |key, obj| obj.clear_association_cache if obj.respond_to?(:clear_association_cache) }
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
@@ -7,7 +7,7 @@
7
7
  names = traces.collect {|name, trace| name}
8
8
  %>
9
9
 
10
- <p><code>RAILS_ROOT: <%= RAILS_ROOT %></code></p>
10
+ <p><code>RAILS_ROOT: <%= defined?(RAILS_ROOT) ? RAILS_ROOT : "unset" %></code></p>
11
11
 
12
12
  <div id="traces">
13
13
  <% names.each do |name| -%>
@@ -28,7 +28,7 @@
28
28
  display: table;
29
29
  }
30
30
 
31
- #ErrorExplanation {
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
- #ErrorExplanation h2 {
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
- #ErrorExplanation p {
50
+ #errorExplanation p {
51
51
  color: #333;
52
52
  margin-bottom: 0;
53
53
  padding: 5px;
54
54
  }
55
55
 
56
- #ErrorExplanation ul li {
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
- class TestResponse < AbstractResponse #:nodoc:
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
- end
275
-
276
- module Test
277
- module Unit
278
- class TestCase #:nodoc:
279
- private
280
- # execute the request and set/volley the response
281
- def process(action, parameters = nil, session = nil, flash = nil)
282
- # Sanity check for required instance variables so we can give an
283
- # understandable error message.
284
- %w(controller request response).each do |iv_name|
285
- raise "@#{iv_name} is nil: make sure you set it in your test's setup method." if instance_variable_get("@#{iv_name}").nil?
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
- @request.recycle!
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
- @html_document = nil
291
- @request.env['REQUEST_METHOD'] ||= "GET"
292
- @request.action = action.to_s
351
+ @request.recycle!
293
352
 
294
- parameters ||= {}
295
- @request.assign_parameters(@controller.class.controller_path, action.to_s, parameters)
353
+ @html_document = nil
354
+ @request.env['REQUEST_METHOD'] ||= "GET"
355
+ @request.action = action.to_s
296
356
 
297
- @request.session = ActionController::TestSession.new(session) unless session.nil?
298
- @request.session["flash"] = ActionController::Flash::FlashHash.new.update(flash) if flash
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
- # execute the request simulating a specific http method and set/volley the response
304
- %w( get post put delete head ).each do |method|
305
- class_eval <<-EOV, __FILE__, __LINE__
306
- def #{method}(action, parameters = nil, session = nil, flash = nil)
307
- @request.env['REQUEST_METHOD'] = "#{method.upcase}" if @request
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
- def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
314
- @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
315
- returning self.send(request_method, action, parameters, session, flash) do
316
- @request.env.delete 'HTTP_X_REQUESTED_WITH'
317
- end
318
- end
319
- alias xhr :xml_http_request
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
- def follow_redirect
322
- if @response.redirected_to[:controller]
323
- raise "Can't follow redirects outside of current controller (#{@response.redirected_to[:controller]})"
324
- end
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
- get(@response.redirected_to.delete(:action), @response.redirected_to.stringify_keys)
327
- end
381
+ get(@response.redirected_to.delete(:action), @response.redirected_to.stringify_keys)
382
+ end
328
383
 
329
- def assigns(key = nil)
330
- if key.nil?
331
- @response.template.assigns
332
- else
333
- @response.template.assigns[key.to_s]
334
- end
335
- end
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
- def session
338
- @response.session
339
- end
392
+ def session
393
+ @response.session
394
+ end
340
395
 
341
- def flash
342
- @response.flash
343
- end
396
+ def flash
397
+ @response.flash
398
+ end
344
399
 
345
- def cookies
346
- @response.cookies
347
- end
400
+ def cookies
401
+ @response.cookies
402
+ end
348
403
 
349
- def redirect_to_url
350
- @response.redirect_url
351
- end
404
+ def redirect_to_url
405
+ @response.redirect_url
406
+ end
352
407
 
353
- def build_request_uri(action, parameters)
354
- unless @request.env['REQUEST_URI']
355
- options = @controller.send(:rewrite_options, parameters)
356
- options.update(:only_path => true, :action => action)
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
- url = ActionController::UrlRewriter.new(@request, parameters)
359
- @request.set_REQUEST_URI(url.rewrite(options))
360
- end
361
- end
413
+ url = ActionController::UrlRewriter.new(@request, parameters)
414
+ @request.set_REQUEST_URI(url.rewrite(options))
415
+ end
416
+ end
362
417
 
363
- def html_document
364
- @html_document ||= HTML::Document.new(@response.body)
365
- end
418
+ def html_document
419
+ @html_document ||= HTML::Document.new(@response.body)
420
+ end
366
421
 
367
- def find_tag(conditions)
368
- html_document.find(conditions)
369
- end
422
+ def find_tag(conditions)
423
+ html_document.find(conditions)
424
+ end
370
425
 
371
- def find_all_tag(conditions)
372
- html_document.find_all(conditions)
373
- end
426
+ def find_all_tag(conditions)
427
+ html_document.find_all(conditions)
428
+ end
374
429
 
375
- def method_missing(selector, *args)
376
- return @controller.send(selector, *args) if ActionController::Routing::NamedRoutes::Helpers.include?(selector)
377
- return super
378
- end
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
- # A helper to make it easier to test different route configurations.
381
- # This method temporarily replaces ActionController::Routing::Routes
382
- # with a new RouteSet instance.
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