actionpack 2.1.2 → 2.2.2

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 (200) hide show
  1. data/CHANGELOG +223 -7
  2. data/README +6 -12
  3. data/Rakefile +11 -11
  4. data/lib/action_controller.rb +9 -9
  5. data/lib/action_controller/assertions/response_assertions.rb +29 -78
  6. data/lib/action_controller/assertions/routing_assertions.rb +33 -33
  7. data/lib/action_controller/assertions/selector_assertions.rb +9 -5
  8. data/lib/action_controller/base.rb +227 -161
  9. data/lib/action_controller/benchmarking.rb +37 -24
  10. data/lib/action_controller/caching/actions.rb +53 -21
  11. data/lib/action_controller/caching/fragments.rb +10 -36
  12. data/lib/action_controller/caching/sweeping.rb +3 -3
  13. data/lib/action_controller/cgi_ext/session.rb +2 -22
  14. data/lib/action_controller/cgi_process.rb +8 -46
  15. data/lib/action_controller/components.rb +4 -1
  16. data/lib/action_controller/cookies.rb +10 -0
  17. data/lib/action_controller/dispatcher.rb +49 -15
  18. data/lib/action_controller/filters.rb +48 -10
  19. data/lib/action_controller/headers.rb +16 -14
  20. data/lib/action_controller/helpers.rb +2 -2
  21. data/lib/action_controller/http_authentication.rb +1 -1
  22. data/lib/action_controller/integration.rb +57 -60
  23. data/lib/action_controller/layout.rb +27 -53
  24. data/lib/action_controller/mime_responds.rb +5 -1
  25. data/lib/action_controller/mime_type.rb +64 -42
  26. data/lib/action_controller/mime_types.rb +2 -1
  27. data/lib/action_controller/performance_test.rb +16 -0
  28. data/lib/action_controller/polymorphic_routes.rb +16 -9
  29. data/lib/action_controller/rack_process.rb +303 -0
  30. data/lib/action_controller/request.rb +205 -97
  31. data/lib/action_controller/request_forgery_protection.rb +2 -2
  32. data/lib/action_controller/request_profiler.rb +0 -0
  33. data/lib/action_controller/rescue.rb +20 -115
  34. data/lib/action_controller/resources.rb +186 -83
  35. data/lib/action_controller/response.rb +140 -26
  36. data/lib/action_controller/routing.rb +28 -30
  37. data/lib/action_controller/routing/builder.rb +45 -54
  38. data/lib/action_controller/routing/optimisations.rb +31 -21
  39. data/lib/action_controller/routing/recognition_optimisation.rb +33 -27
  40. data/lib/action_controller/routing/route.rb +162 -147
  41. data/lib/action_controller/routing/route_set.rb +8 -7
  42. data/lib/action_controller/routing/routing_ext.rb +4 -1
  43. data/lib/action_controller/routing/segments.rb +50 -21
  44. data/lib/action_controller/session/cookie_store.rb +3 -2
  45. data/lib/action_controller/session/drb_server.rb +7 -7
  46. data/lib/action_controller/session_management.rb +6 -2
  47. data/lib/action_controller/streaming.rb +15 -8
  48. data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
  49. data/lib/action_controller/templates/rescues/template_error.erb +2 -2
  50. data/lib/action_controller/test_case.rb +66 -2
  51. data/lib/action_controller/test_process.rb +71 -66
  52. data/lib/action_controller/translation.rb +13 -0
  53. data/lib/action_controller/url_rewriter.rb +90 -13
  54. data/lib/action_controller/vendor/html-scanner/html/node.rb +9 -2
  55. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +1 -1
  56. data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -2
  57. data/lib/action_controller/verification.rb +2 -2
  58. data/lib/action_pack/version.rb +1 -1
  59. data/lib/action_view.rb +19 -11
  60. data/lib/action_view/base.rb +184 -150
  61. data/lib/action_view/helpers.rb +38 -0
  62. data/lib/action_view/helpers/active_record_helper.rb +56 -27
  63. data/lib/action_view/helpers/asset_tag_helper.rb +356 -153
  64. data/lib/action_view/helpers/atom_feed_helper.rb +74 -19
  65. data/lib/action_view/helpers/benchmark_helper.rb +3 -3
  66. data/lib/action_view/helpers/cache_helper.rb +1 -2
  67. data/lib/action_view/helpers/capture_helper.rb +19 -44
  68. data/lib/action_view/helpers/date_helper.rb +486 -296
  69. data/lib/action_view/helpers/debug_helper.rb +20 -13
  70. data/lib/action_view/helpers/form_helper.rb +71 -30
  71. data/lib/action_view/helpers/form_options_helper.rb +15 -85
  72. data/lib/action_view/helpers/form_tag_helper.rb +61 -38
  73. data/lib/action_view/helpers/javascript_helper.rb +80 -89
  74. data/lib/action_view/helpers/number_helper.rb +179 -74
  75. data/lib/action_view/helpers/prototype_helper.rb +216 -201
  76. data/lib/action_view/helpers/record_tag_helper.rb +4 -5
  77. data/lib/action_view/helpers/sanitize_helper.rb +65 -33
  78. data/lib/action_view/helpers/scriptaculous_helper.rb +2 -2
  79. data/lib/action_view/helpers/tag_helper.rb +39 -22
  80. data/lib/action_view/helpers/text_helper.rb +212 -118
  81. data/lib/action_view/helpers/translation_helper.rb +21 -0
  82. data/lib/action_view/helpers/url_helper.rb +100 -58
  83. data/lib/action_view/inline_template.rb +13 -14
  84. data/lib/action_view/locale/en.yml +91 -0
  85. data/lib/action_view/partials.rb +100 -55
  86. data/lib/action_view/paths.rb +125 -0
  87. data/lib/action_view/renderable.rb +102 -0
  88. data/lib/action_view/renderable_partial.rb +48 -0
  89. data/lib/action_view/template.rb +90 -101
  90. data/lib/action_view/template_error.rb +11 -21
  91. data/lib/action_view/template_handler.rb +8 -28
  92. data/lib/action_view/template_handlers.rb +45 -0
  93. data/lib/action_view/template_handlers/builder.rb +5 -15
  94. data/lib/action_view/template_handlers/erb.rb +9 -6
  95. data/lib/action_view/template_handlers/rjs.rb +2 -17
  96. data/lib/action_view/test_case.rb +7 -4
  97. data/test/abstract_unit.rb +4 -1
  98. data/test/active_record_unit.rb +28 -30
  99. data/test/activerecord/render_partial_with_record_identification_test.rb +25 -12
  100. data/test/controller/action_pack_assertions_test.rb +8 -37
  101. data/test/controller/addresses_render_test.rb +0 -3
  102. data/test/controller/assert_select_test.rb +51 -24
  103. data/test/controller/base_test.rb +4 -4
  104. data/test/controller/caching_test.rb +136 -66
  105. data/test/controller/capture_test.rb +1 -21
  106. data/test/controller/cgi_test.rb +157 -10
  107. data/test/controller/components_test.rb +41 -25
  108. data/test/controller/content_type_test.rb +49 -17
  109. data/test/controller/cookie_test.rb +1 -1
  110. data/test/controller/deprecation/deprecated_base_methods_test.rb +0 -3
  111. data/test/controller/dispatcher_test.rb +9 -1
  112. data/test/controller/filter_params_test.rb +2 -2
  113. data/test/controller/filters_test.rb +13 -13
  114. data/test/controller/html-scanner/cdata_node_test.rb +15 -0
  115. data/test/controller/html-scanner/node_test.rb +21 -0
  116. data/test/controller/html-scanner/sanitizer_test.rb +14 -0
  117. data/test/controller/integration_test.rb +167 -6
  118. data/test/controller/layout_test.rb +11 -68
  119. data/test/controller/logging_test.rb +46 -0
  120. data/test/controller/mime_responds_test.rb +61 -59
  121. data/test/controller/mime_type_test.rb +6 -6
  122. data/test/controller/polymorphic_routes_test.rb +37 -2
  123. data/test/controller/rack_test.rb +323 -0
  124. data/test/controller/redirect_test.rb +72 -71
  125. data/test/controller/render_test.rb +1120 -108
  126. data/test/controller/request_forgery_protection_test.rb +66 -52
  127. data/test/controller/request_test.rb +103 -146
  128. data/test/controller/rescue_test.rb +20 -24
  129. data/test/controller/resources_test.rb +408 -25
  130. data/test/controller/routing_test.rb +1774 -1774
  131. data/test/controller/send_file_test.rb +0 -4
  132. data/test/controller/session/cookie_store_test.rb +53 -1
  133. data/test/controller/test_test.rb +15 -37
  134. data/test/controller/translation_test.rb +26 -0
  135. data/test/controller/url_rewriter_test.rb +27 -28
  136. data/test/controller/view_paths_test.rb +48 -47
  137. data/test/fixtures/_top_level_partial.html.erb +1 -0
  138. data/test/fixtures/_top_level_partial_only.erb +1 -0
  139. data/test/fixtures/developers/_developer.erb +1 -0
  140. data/test/fixtures/fun/games/_game.erb +1 -0
  141. data/test/fixtures/fun/serious/games/_game.erb +1 -0
  142. data/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
  143. data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
  144. data/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
  145. data/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
  146. data/test/fixtures/layouts/_column.html.erb +2 -0
  147. data/test/fixtures/projects/_project.erb +1 -0
  148. data/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
  149. data/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
  150. data/test/fixtures/replies/_reply.erb +1 -0
  151. data/test/fixtures/test/_counter.html.erb +1 -0
  152. data/test/fixtures/test/_customer.erb +1 -1
  153. data/test/fixtures/test/_customer_with_var.erb +1 -0
  154. data/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
  155. data/test/fixtures/test/_local_inspector.html.erb +1 -0
  156. data/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
  157. data/test/fixtures/test/hello.builder +1 -1
  158. data/test/fixtures/test/hyphen-ated.erb +1 -0
  159. data/test/fixtures/test/implicit_content_type.atom.builder +2 -0
  160. data/test/fixtures/test/nested_layout.erb +3 -0
  161. data/test/fixtures/test/non_erb_block_content_for.builder +1 -1
  162. data/test/fixtures/test/sub_template_raise.html.erb +1 -0
  163. data/test/fixtures/test/template.erb +1 -0
  164. data/test/fixtures/test/using_layout_around_block_with_args.html.erb +1 -0
  165. data/test/template/active_record_helper_i18n_test.rb +46 -0
  166. data/test/template/active_record_helper_test.rb +24 -24
  167. data/test/template/asset_tag_helper_test.rb +161 -29
  168. data/test/template/atom_feed_helper_test.rb +114 -5
  169. data/test/template/compiled_templates_test.rb +59 -0
  170. data/test/template/date_helper_i18n_test.rb +113 -0
  171. data/test/template/date_helper_test.rb +403 -109
  172. data/test/template/form_helper_test.rb +213 -154
  173. data/test/template/form_options_helper_test.rb +249 -897
  174. data/test/template/form_tag_helper_test.rb +80 -32
  175. data/test/template/javascript_helper_test.rb +17 -18
  176. data/test/template/number_helper_i18n_test.rb +54 -0
  177. data/test/template/number_helper_test.rb +43 -13
  178. data/test/template/prototype_helper_test.rb +101 -84
  179. data/test/template/record_tag_helper_test.rb +24 -20
  180. data/test/template/render_test.rb +193 -0
  181. data/test/template/sanitize_helper_test.rb +3 -3
  182. data/test/template/tag_helper_test.rb +34 -14
  183. data/test/template/text_helper_test.rb +83 -9
  184. data/test/template/translation_helper_test.rb +28 -0
  185. data/test/template/url_helper_test.rb +55 -18
  186. metadata +57 -18
  187. data/lib/action_view/helpers/javascripts/controls.js +0 -963
  188. data/lib/action_view/helpers/javascripts/dragdrop.js +0 -972
  189. data/lib/action_view/helpers/javascripts/effects.js +0 -1120
  190. data/lib/action_view/helpers/javascripts/prototype.js +0 -4225
  191. data/lib/action_view/partial_template.rb +0 -70
  192. data/lib/action_view/template_finder.rb +0 -177
  193. data/lib/action_view/template_handlers/compilable.rb +0 -128
  194. data/test/controller/custom_handler_test.rb +0 -45
  195. data/test/controller/new_render_test.rb +0 -945
  196. data/test/fixtures/test/block_content_for.erb +0 -2
  197. data/test/fixtures/test/erb_content_for.erb +0 -2
  198. data/test/template/deprecated_erb_variable_test.rb +0 -9
  199. data/test/template/template_finder_test.rb +0 -73
  200. data/test/template/template_object_test.rb +0 -95
@@ -84,11 +84,11 @@ class ControllerInstanceTests < Test::Unit::TestCase
84
84
  def test_action_methods
85
85
  @empty_controllers.each do |c|
86
86
  hide_mocha_methods_from_controller(c)
87
- assert_equal Set.new, c.send!(:action_methods), "#{c.controller_path} should be empty!"
87
+ assert_equal Set.new, c.__send__(:action_methods), "#{c.controller_path} should be empty!"
88
88
  end
89
89
  @non_empty_controllers.each do |c|
90
90
  hide_mocha_methods_from_controller(c)
91
- assert_equal Set.new(%w(public_action)), c.send!(:action_methods), "#{c.controller_path} should not be empty!"
91
+ assert_equal Set.new(%w(public_action)), c.__send__(:action_methods), "#{c.controller_path} should not be empty!"
92
92
  end
93
93
  end
94
94
 
@@ -100,7 +100,7 @@ class ControllerInstanceTests < Test::Unit::TestCase
100
100
  :expects, :mocha, :mocha_inspect, :reset_mocha, :stubba_object,
101
101
  :stubba_method, :stubs, :verify, :__metaclass__, :__is_a__, :to_matcher,
102
102
  ]
103
- controller.class.send!(:hide_action, *mocha_methods)
103
+ controller.class.__send__(:hide_action, *mocha_methods)
104
104
  end
105
105
  end
106
106
 
@@ -140,7 +140,7 @@ class PerformActionTest < Test::Unit::TestCase
140
140
 
141
141
  def test_method_missing_is_not_an_action_name
142
142
  use_controller MethodMissingController
143
- assert ! @controller.send!(:action_methods).include?('method_missing')
143
+ assert ! @controller.__send__(:action_methods).include?('method_missing')
144
144
 
145
145
  get :method_missing
146
146
  assert_response :success
@@ -6,7 +6,6 @@ CACHE_DIR = 'test_cache'
6
6
  FILE_STORE_PATH = File.join(File.dirname(__FILE__), '/../temp/', CACHE_DIR)
7
7
  ActionController::Base.page_cache_directory = FILE_STORE_PATH
8
8
  ActionController::Base.cache_store = :file_store, FILE_STORE_PATH
9
- ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/' ]
10
9
 
11
10
  class PageCachingTestController < ActionController::Base
12
11
  caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? }
@@ -110,7 +109,7 @@ class PageCachingTest < Test::Unit::TestCase
110
109
 
111
110
  uses_mocha("should_cache_ok_at_custom_path") do
112
111
  def test_should_cache_ok_at_custom_path
113
- @request.expects(:path).returns("/index.html")
112
+ @request.stubs(:path).returns("/index.html")
114
113
  get :ok
115
114
  assert_response :ok
116
115
  assert File.exist?("#{FILE_STORE_PATH}/index.html")
@@ -131,8 +130,7 @@ class PageCachingTest < Test::Unit::TestCase
131
130
  end
132
131
 
133
132
  def test_page_caching_conditional_options
134
- @request.env['HTTP_ACCEPT'] = 'application/json'
135
- get :ok
133
+ get :ok, :format=>'json'
136
134
  assert_page_not_cached :ok
137
135
  end
138
136
 
@@ -150,12 +148,12 @@ class PageCachingTest < Test::Unit::TestCase
150
148
  end
151
149
  end
152
150
 
153
-
154
151
  class ActionCachingTestController < ActionController::Base
155
- caches_action :index, :redirected, :forbidden, :if => Proc.new { |c| !c.request.format.json? }
152
+ caches_action :index, :redirected, :forbidden, :if => Proc.new { |c| !c.request.format.json? }, :expires_in => 1.hour
156
153
  caches_action :show, :cache_path => 'http://test.host/custom/show'
157
154
  caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" }
158
155
  caches_action :with_layout
156
+ caches_action :layout_false, :layout => false
159
157
 
160
158
  layout 'talk_from_action.erb'
161
159
 
@@ -181,11 +179,17 @@ class ActionCachingTestController < ActionController::Base
181
179
  alias_method :show, :index
182
180
  alias_method :edit, :index
183
181
  alias_method :destroy, :index
182
+ alias_method :layout_false, :with_layout
184
183
 
185
184
  def expire
186
185
  expire_action :controller => 'action_caching_test', :action => 'index'
187
186
  render :nothing => true
188
187
  end
188
+
189
+ def expire_xml
190
+ expire_action :controller => 'action_caching_test', :action => 'index', :format => 'xml'
191
+ render :nothing => true
192
+ end
189
193
  end
190
194
 
191
195
  class MockTime < Time
@@ -211,6 +215,8 @@ class ActionCachingMockController
211
215
  mocked_path = @mock_path
212
216
  Object.new.instance_eval(<<-EVAL)
213
217
  def path; '#{@mock_path}' end
218
+ def format; 'all' end
219
+ def cache_format; nil end
214
220
  self
215
221
  EVAL
216
222
  end
@@ -263,10 +269,35 @@ class ActionCacheTest < Test::Unit::TestCase
263
269
  assert_equal @response.body, read_fragment('hostname.com/action_caching_test/with_layout')
264
270
  end
265
271
 
272
+ def test_action_cache_with_layout_and_layout_cache_false
273
+ get :layout_false
274
+ cached_time = content_to_cache
275
+ assert_not_equal cached_time, @response.body
276
+ assert fragment_exist?('hostname.com/action_caching_test/layout_false')
277
+ reset!
278
+
279
+ get :layout_false
280
+ assert_not_equal cached_time, @response.body
281
+
282
+ assert_equal cached_time, read_fragment('hostname.com/action_caching_test/layout_false')
283
+ end
284
+
266
285
  def test_action_cache_conditional_options
286
+ old_use_accept_header = ActionController::Base.use_accept_header
287
+ ActionController::Base.use_accept_header = true
267
288
  @request.env['HTTP_ACCEPT'] = 'application/json'
268
289
  get :index
269
290
  assert !fragment_exist?('hostname.com/action_caching_test')
291
+ ActionController::Base.use_accept_header = old_use_accept_header
292
+ end
293
+
294
+ uses_mocha 'test action cache' do
295
+ def test_action_cache_with_store_options
296
+ MockTime.expects(:now).returns(12345).once
297
+ @controller.expects(:read_fragment).with('hostname.com/action_caching_test', :expires_in => 1.hour).once
298
+ @controller.expects(:write_fragment).with('hostname.com/action_caching_test', '12345.0', :expires_in => 1.hour).once
299
+ get :index
300
+ end
270
301
  end
271
302
 
272
303
  def test_action_cache_with_custom_cache_path
@@ -311,6 +342,20 @@ class ActionCacheTest < Test::Unit::TestCase
311
342
  assert_equal new_cached_time, @response.body
312
343
  end
313
344
 
345
+ def test_cache_expiration_isnt_affected_by_request_format
346
+ get :index
347
+ cached_time = content_to_cache
348
+ reset!
349
+
350
+ @request.set_REQUEST_URI "/action_caching_test/expire.xml"
351
+ get :expire, :format => :xml
352
+ reset!
353
+
354
+ get :index
355
+ new_cached_time = content_to_cache
356
+ assert_not_equal cached_time, @response.body
357
+ end
358
+
314
359
  def test_cache_is_scoped_by_subdomain
315
360
  @request.host = 'jamis.hostname.com'
316
361
  get :index
@@ -355,11 +400,29 @@ class ActionCacheTest < Test::Unit::TestCase
355
400
  end
356
401
 
357
402
  def test_xml_version_of_resource_is_treated_as_different_cache
358
- @mock_controller.mock_url_for = 'http://example.org/posts/'
359
- @mock_controller.mock_path = '/posts/index.xml'
360
- path_object = @path_class.new(@mock_controller, {})
361
- assert_equal 'xml', path_object.extension
362
- assert_equal 'example.org/posts/index.xml', path_object.path
403
+ with_routing do |set|
404
+ ActionController::Routing::Routes.draw do |map|
405
+ map.connect ':controller/:action.:format'
406
+ map.connect ':controller/:action'
407
+ end
408
+
409
+ get :index, :format => 'xml'
410
+ cached_time = content_to_cache
411
+ assert_equal cached_time, @response.body
412
+ assert fragment_exist?('hostname.com/action_caching_test/index.xml')
413
+ reset!
414
+
415
+ get :index, :format => 'xml'
416
+ assert_equal cached_time, @response.body
417
+ assert_equal 'application/xml', @response.content_type
418
+ reset!
419
+
420
+ get :expire_xml
421
+ reset!
422
+
423
+ get :index, :format => 'xml'
424
+ assert_not_equal cached_time, @response.body
425
+ end
363
426
  end
364
427
 
365
428
  def test_correct_content_type_is_returned_for_cache_hit
@@ -421,58 +484,60 @@ class FragmentCachingTest < Test::Unit::TestCase
421
484
  @controller.request = @request
422
485
  @controller.response = @response
423
486
  @controller.send(:initialize_current_url)
487
+ @controller.send(:initialize_template_class, @response)
488
+ @controller.send(:assign_shortcuts, @request, @response)
424
489
  end
425
490
 
426
491
  def test_fragment_cache_key
427
492
  assert_equal 'views/what a key', @controller.fragment_cache_key('what a key')
428
- assert_equal( "views/test.host/fragment_caching_test/some_action",
429
- @controller.fragment_cache_key(:controller => 'fragment_caching_test',:action => 'some_action'))
493
+ assert_equal "views/test.host/fragment_caching_test/some_action",
494
+ @controller.fragment_cache_key(:controller => 'fragment_caching_test',:action => 'some_action')
430
495
  end
431
496
 
432
- def test_read_fragment__with_caching_enabled
497
+ def test_read_fragment_with_caching_enabled
433
498
  @store.write('views/name', 'value')
434
499
  assert_equal 'value', @controller.read_fragment('name')
435
500
  end
436
501
 
437
- def test_read_fragment__with_caching_disabled
502
+ def test_read_fragment_with_caching_disabled
438
503
  ActionController::Base.perform_caching = false
439
504
  @store.write('views/name', 'value')
440
505
  assert_nil @controller.read_fragment('name')
441
506
  end
442
507
 
443
- def test_fragment_exist__with_caching_enabled
508
+ def test_fragment_exist_with_caching_enabled
444
509
  @store.write('views/name', 'value')
445
510
  assert @controller.fragment_exist?('name')
446
511
  assert !@controller.fragment_exist?('other_name')
447
512
  end
448
513
 
449
- def test_fragment_exist__with_caching_disabled
514
+ def test_fragment_exist_with_caching_disabled
450
515
  ActionController::Base.perform_caching = false
451
516
  @store.write('views/name', 'value')
452
517
  assert !@controller.fragment_exist?('name')
453
518
  assert !@controller.fragment_exist?('other_name')
454
519
  end
455
520
 
456
- def test_write_fragment__with_caching_enabled
521
+ def test_write_fragment_with_caching_enabled
457
522
  assert_nil @store.read('views/name')
458
523
  assert_equal 'value', @controller.write_fragment('name', 'value')
459
524
  assert_equal 'value', @store.read('views/name')
460
525
  end
461
526
 
462
- def test_write_fragment__with_caching_disabled
527
+ def test_write_fragment_with_caching_disabled
463
528
  assert_nil @store.read('views/name')
464
529
  ActionController::Base.perform_caching = false
465
530
  assert_equal nil, @controller.write_fragment('name', 'value')
466
531
  assert_nil @store.read('views/name')
467
532
  end
468
533
 
469
- def test_expire_fragment__with_simple_key
534
+ def test_expire_fragment_with_simple_key
470
535
  @store.write('views/name', 'value')
471
536
  @controller.expire_fragment 'name'
472
537
  assert_nil @store.read('views/name')
473
538
  end
474
539
 
475
- def test_expire_fragment__with__regexp
540
+ def test_expire_fragment_with_regexp
476
541
  @store.write('views/name', 'value')
477
542
  @store.write('views/another_name', 'another_value')
478
543
  @store.write('views/primalgrasp', 'will not expire ;-)')
@@ -484,14 +549,14 @@ class FragmentCachingTest < Test::Unit::TestCase
484
549
  assert_equal 'will not expire ;-)', @store.read('views/primalgrasp')
485
550
  end
486
551
 
487
- def test_fragment_for__with_disabled_caching
552
+ def test_fragment_for_with_disabled_caching
488
553
  ActionController::Base.perform_caching = false
489
554
 
490
555
  @store.write('views/expensive', 'fragment content')
491
556
  fragment_computed = false
492
557
 
493
558
  buffer = 'generated till now -> '
494
- @controller.fragment_for(Proc.new { fragment_computed = true }, 'expensive') { buffer }
559
+ @controller.fragment_for(buffer, 'expensive') { fragment_computed = true }
495
560
 
496
561
  assert fragment_computed
497
562
  assert_equal 'generated till now -> ', buffer
@@ -502,53 +567,13 @@ class FragmentCachingTest < Test::Unit::TestCase
502
567
  fragment_computed = false
503
568
 
504
569
  buffer = 'generated till now -> '
505
- @controller.fragment_for(Proc.new { fragment_computed = true }, 'expensive') { buffer}
570
+ @controller.fragment_for(buffer, 'expensive') { fragment_computed = true }
506
571
 
507
572
  assert !fragment_computed
508
573
  assert_equal 'generated till now -> fragment content', buffer
509
574
  end
510
-
511
- def test_cache_erb_fragment
512
- @store.write('views/expensive', 'fragment content')
513
- _erbout = 'generated till now -> '
514
-
515
- assert_equal( 'generated till now -> fragment content',
516
- ActionView::TemplateHandlers::ERB.new(@controller).cache_fragment(Proc.new{ }, 'expensive'))
517
- end
518
-
519
- def test_cache_rxml_fragment
520
- @store.write('views/expensive', 'fragment content')
521
- xml = 'generated till now -> '
522
- class << xml; def target!; to_s; end; end
523
-
524
- assert_equal( 'generated till now -> fragment content',
525
- ActionView::TemplateHandlers::Builder.new(@controller).cache_fragment(Proc.new{ }, 'expensive'))
526
- end
527
-
528
- def test_cache_rjs_fragment
529
- @store.write('views/expensive', 'fragment content')
530
- page = 'generated till now -> '
531
-
532
- assert_equal( 'generated till now -> fragment content',
533
- ActionView::TemplateHandlers::RJS.new(@controller).cache_fragment(Proc.new{ }, 'expensive'))
534
- end
535
-
536
- def test_cache_rjs_fragment_debug_mode_does_not_interfere
537
- @store.write('views/expensive', 'fragment content')
538
- page = 'generated till now -> '
539
-
540
- begin
541
- debug_mode, ActionView::Base.debug_rjs = ActionView::Base.debug_rjs, true
542
- assert_equal( 'generated till now -> fragment content',
543
- ActionView::TemplateHandlers::RJS.new(@controller).cache_fragment(Proc.new{ }, 'expensive'))
544
- assert ActionView::Base.debug_rjs
545
- ensure
546
- ActionView::Base.debug_rjs = debug_mode
547
- end
548
- end
549
575
  end
550
576
 
551
-
552
577
  class FunctionalCachingController < ActionController::Base
553
578
  def fragment_cached
554
579
  end
@@ -565,14 +590,19 @@ class FunctionalCachingController < ActionController::Base
565
590
  end
566
591
  end
567
592
 
593
+ def formatted_fragment_cached
594
+ respond_to do |format|
595
+ format.html
596
+ format.xml
597
+ format.js
598
+ end
599
+ end
568
600
 
569
601
  def rescue_action(e)
570
602
  raise e
571
603
  end
572
604
  end
573
605
 
574
- FunctionalCachingController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
575
-
576
606
  class FunctionalFragmentCachingTest < Test::Unit::TestCase
577
607
  def setup
578
608
  ActionController::Base.perform_caching = true
@@ -582,6 +612,7 @@ class FunctionalFragmentCachingTest < Test::Unit::TestCase
582
612
  @request = ActionController::TestRequest.new
583
613
  @response = ActionController::TestResponse.new
584
614
  end
615
+
585
616
  def test_fragment_caching
586
617
  get :fragment_cached
587
618
  assert_response :success
@@ -601,10 +632,49 @@ CACHED
601
632
  assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial')
602
633
  end
603
634
 
635
+ def test_render_inline_before_fragment_caching
636
+ get :inline_fragment_cached
637
+ assert_response :success
638
+ assert_match /Some inline content/, @response.body
639
+ assert_match /Some cached content/, @response.body
640
+ assert_match "Some cached content", @store.read('views/test.host/functional_caching/inline_fragment_cached')
641
+ end
642
+
604
643
  def test_fragment_caching_in_rjs_partials
605
644
  xhr :get, :js_fragment_cached_with_partial
606
645
  assert_response :success
607
646
  assert_match /Fragment caching in a partial/, @response.body
608
647
  assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial')
609
648
  end
649
+
650
+ def test_html_formatted_fragment_caching
651
+ get :formatted_fragment_cached, :format => "html"
652
+ assert_response :success
653
+ expected_body = "<body>\n<p>ERB</p>\n</body>"
654
+
655
+ assert_equal expected_body, @response.body
656
+
657
+ assert_equal "<p>ERB</p>", @store.read('views/test.host/functional_caching/formatted_fragment_cached')
658
+ end
659
+
660
+ def test_xml_formatted_fragment_caching
661
+ get :formatted_fragment_cached, :format => "xml"
662
+ assert_response :success
663
+ expected_body = "<body>\n <p>Builder</p>\n</body>\n"
664
+
665
+ assert_equal expected_body, @response.body
666
+
667
+ assert_equal " <p>Builder</p>\n", @store.read('views/test.host/functional_caching/formatted_fragment_cached')
668
+ end
669
+
670
+ def test_js_formatted_fragment_caching
671
+ get :formatted_fragment_cached, :format => "js"
672
+ assert_response :success
673
+ expected_body = %(title = "Hey";\n$("element_1").visualEffect("highlight");\n) +
674
+ %($("element_2").visualEffect("highlight");\nfooter = "Bye";)
675
+ assert_equal expected_body, @response.body
676
+
677
+ assert_equal ['$("element_1").visualEffect("highlight");', '$("element_2").visualEffect("highlight");'],
678
+ @store.read('views/test.host/functional_caching/formatted_fragment_cached')
679
+ end
610
680
  end
@@ -11,16 +11,8 @@ class CaptureController < ActionController::Base
11
11
  def content_for_with_parameter
12
12
  render :layout => "talk_from_action"
13
13
  end
14
-
15
- def content_for_concatenated
16
- render :layout => "talk_from_action"
17
- end
18
14
 
19
- def erb_content_for
20
- render :layout => "talk_from_action"
21
- end
22
-
23
- def block_content_for
15
+ def content_for_concatenated
24
16
  render :layout => "talk_from_action"
25
17
  end
26
18
 
@@ -31,8 +23,6 @@ class CaptureController < ActionController::Base
31
23
  def rescue_action(e) raise end
32
24
  end
33
25
 
34
- CaptureController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
35
-
36
26
  class CaptureTest < Test::Unit::TestCase
37
27
  def setup
38
28
  @controller = CaptureController.new
@@ -62,21 +52,11 @@ class CaptureTest < Test::Unit::TestCase
62
52
  assert_equal expected_content_for_output, @response.body
63
53
  end
64
54
 
65
- def test_erb_content_for
66
- get :erb_content_for
67
- assert_equal expected_content_for_output, @response.body
68
- end
69
-
70
55
  def test_should_set_content_for_with_parameter
71
56
  get :content_for_with_parameter
72
57
  assert_equal expected_content_for_output, @response.body
73
58
  end
74
59
 
75
- def test_block_content_for
76
- get :block_content_for
77
- assert_equal expected_content_for_output, @response.body
78
- end
79
-
80
60
  def test_non_erb_block_content_for
81
61
  get :non_erb_block_content_for
82
62
  assert_equal expected_content_for_output, @response.body