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.
- data/CHANGELOG +223 -7
- data/README +6 -12
- data/Rakefile +11 -11
- data/lib/action_controller.rb +9 -9
- data/lib/action_controller/assertions/response_assertions.rb +29 -78
- data/lib/action_controller/assertions/routing_assertions.rb +33 -33
- data/lib/action_controller/assertions/selector_assertions.rb +9 -5
- data/lib/action_controller/base.rb +227 -161
- data/lib/action_controller/benchmarking.rb +37 -24
- data/lib/action_controller/caching/actions.rb +53 -21
- data/lib/action_controller/caching/fragments.rb +10 -36
- data/lib/action_controller/caching/sweeping.rb +3 -3
- data/lib/action_controller/cgi_ext/session.rb +2 -22
- data/lib/action_controller/cgi_process.rb +8 -46
- data/lib/action_controller/components.rb +4 -1
- data/lib/action_controller/cookies.rb +10 -0
- data/lib/action_controller/dispatcher.rb +49 -15
- data/lib/action_controller/filters.rb +48 -10
- data/lib/action_controller/headers.rb +16 -14
- data/lib/action_controller/helpers.rb +2 -2
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +57 -60
- data/lib/action_controller/layout.rb +27 -53
- data/lib/action_controller/mime_responds.rb +5 -1
- data/lib/action_controller/mime_type.rb +64 -42
- data/lib/action_controller/mime_types.rb +2 -1
- data/lib/action_controller/performance_test.rb +16 -0
- data/lib/action_controller/polymorphic_routes.rb +16 -9
- data/lib/action_controller/rack_process.rb +303 -0
- data/lib/action_controller/request.rb +205 -97
- data/lib/action_controller/request_forgery_protection.rb +2 -2
- data/lib/action_controller/request_profiler.rb +0 -0
- data/lib/action_controller/rescue.rb +20 -115
- data/lib/action_controller/resources.rb +186 -83
- data/lib/action_controller/response.rb +140 -26
- data/lib/action_controller/routing.rb +28 -30
- data/lib/action_controller/routing/builder.rb +45 -54
- data/lib/action_controller/routing/optimisations.rb +31 -21
- data/lib/action_controller/routing/recognition_optimisation.rb +33 -27
- data/lib/action_controller/routing/route.rb +162 -147
- data/lib/action_controller/routing/route_set.rb +8 -7
- data/lib/action_controller/routing/routing_ext.rb +4 -1
- data/lib/action_controller/routing/segments.rb +50 -21
- data/lib/action_controller/session/cookie_store.rb +3 -2
- data/lib/action_controller/session/drb_server.rb +7 -7
- data/lib/action_controller/session_management.rb +6 -2
- data/lib/action_controller/streaming.rb +15 -8
- data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
- data/lib/action_controller/templates/rescues/template_error.erb +2 -2
- data/lib/action_controller/test_case.rb +66 -2
- data/lib/action_controller/test_process.rb +71 -66
- data/lib/action_controller/translation.rb +13 -0
- data/lib/action_controller/url_rewriter.rb +90 -13
- data/lib/action_controller/vendor/html-scanner/html/node.rb +9 -2
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +1 -1
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +2 -2
- data/lib/action_controller/verification.rb +2 -2
- data/lib/action_pack/version.rb +1 -1
- data/lib/action_view.rb +19 -11
- data/lib/action_view/base.rb +184 -150
- data/lib/action_view/helpers.rb +38 -0
- data/lib/action_view/helpers/active_record_helper.rb +56 -27
- data/lib/action_view/helpers/asset_tag_helper.rb +356 -153
- data/lib/action_view/helpers/atom_feed_helper.rb +74 -19
- data/lib/action_view/helpers/benchmark_helper.rb +3 -3
- data/lib/action_view/helpers/cache_helper.rb +1 -2
- data/lib/action_view/helpers/capture_helper.rb +19 -44
- data/lib/action_view/helpers/date_helper.rb +486 -296
- data/lib/action_view/helpers/debug_helper.rb +20 -13
- data/lib/action_view/helpers/form_helper.rb +71 -30
- data/lib/action_view/helpers/form_options_helper.rb +15 -85
- data/lib/action_view/helpers/form_tag_helper.rb +61 -38
- data/lib/action_view/helpers/javascript_helper.rb +80 -89
- data/lib/action_view/helpers/number_helper.rb +179 -74
- data/lib/action_view/helpers/prototype_helper.rb +216 -201
- data/lib/action_view/helpers/record_tag_helper.rb +4 -5
- data/lib/action_view/helpers/sanitize_helper.rb +65 -33
- data/lib/action_view/helpers/scriptaculous_helper.rb +2 -2
- data/lib/action_view/helpers/tag_helper.rb +39 -22
- data/lib/action_view/helpers/text_helper.rb +212 -118
- data/lib/action_view/helpers/translation_helper.rb +21 -0
- data/lib/action_view/helpers/url_helper.rb +100 -58
- data/lib/action_view/inline_template.rb +13 -14
- data/lib/action_view/locale/en.yml +91 -0
- data/lib/action_view/partials.rb +100 -55
- data/lib/action_view/paths.rb +125 -0
- data/lib/action_view/renderable.rb +102 -0
- data/lib/action_view/renderable_partial.rb +48 -0
- data/lib/action_view/template.rb +90 -101
- data/lib/action_view/template_error.rb +11 -21
- data/lib/action_view/template_handler.rb +8 -28
- data/lib/action_view/template_handlers.rb +45 -0
- data/lib/action_view/template_handlers/builder.rb +5 -15
- data/lib/action_view/template_handlers/erb.rb +9 -6
- data/lib/action_view/template_handlers/rjs.rb +2 -17
- data/lib/action_view/test_case.rb +7 -4
- data/test/abstract_unit.rb +4 -1
- data/test/active_record_unit.rb +28 -30
- data/test/activerecord/render_partial_with_record_identification_test.rb +25 -12
- data/test/controller/action_pack_assertions_test.rb +8 -37
- data/test/controller/addresses_render_test.rb +0 -3
- data/test/controller/assert_select_test.rb +51 -24
- data/test/controller/base_test.rb +4 -4
- data/test/controller/caching_test.rb +136 -66
- data/test/controller/capture_test.rb +1 -21
- data/test/controller/cgi_test.rb +157 -10
- data/test/controller/components_test.rb +41 -25
- data/test/controller/content_type_test.rb +49 -17
- data/test/controller/cookie_test.rb +1 -1
- data/test/controller/deprecation/deprecated_base_methods_test.rb +0 -3
- data/test/controller/dispatcher_test.rb +9 -1
- data/test/controller/filter_params_test.rb +2 -2
- data/test/controller/filters_test.rb +13 -13
- data/test/controller/html-scanner/cdata_node_test.rb +15 -0
- data/test/controller/html-scanner/node_test.rb +21 -0
- data/test/controller/html-scanner/sanitizer_test.rb +14 -0
- data/test/controller/integration_test.rb +167 -6
- data/test/controller/layout_test.rb +11 -68
- data/test/controller/logging_test.rb +46 -0
- data/test/controller/mime_responds_test.rb +61 -59
- data/test/controller/mime_type_test.rb +6 -6
- data/test/controller/polymorphic_routes_test.rb +37 -2
- data/test/controller/rack_test.rb +323 -0
- data/test/controller/redirect_test.rb +72 -71
- data/test/controller/render_test.rb +1120 -108
- data/test/controller/request_forgery_protection_test.rb +66 -52
- data/test/controller/request_test.rb +103 -146
- data/test/controller/rescue_test.rb +20 -24
- data/test/controller/resources_test.rb +408 -25
- data/test/controller/routing_test.rb +1774 -1774
- data/test/controller/send_file_test.rb +0 -4
- data/test/controller/session/cookie_store_test.rb +53 -1
- data/test/controller/test_test.rb +15 -37
- data/test/controller/translation_test.rb +26 -0
- data/test/controller/url_rewriter_test.rb +27 -28
- data/test/controller/view_paths_test.rb +48 -47
- data/test/fixtures/_top_level_partial.html.erb +1 -0
- data/test/fixtures/_top_level_partial_only.erb +1 -0
- data/test/fixtures/developers/_developer.erb +1 -0
- data/test/fixtures/fun/games/_game.erb +1 -0
- data/test/fixtures/fun/serious/games/_game.erb +1 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.html.erb +3 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.js.rjs +6 -0
- data/test/fixtures/functional_caching/formatted_fragment_cached.xml.builder +5 -0
- data/test/fixtures/functional_caching/inline_fragment_cached.html.erb +2 -0
- data/test/fixtures/layouts/_column.html.erb +2 -0
- data/test/fixtures/projects/_project.erb +1 -0
- data/test/fixtures/public/javascripts/subdir/subdir.js +1 -0
- data/test/fixtures/public/stylesheets/subdir/subdir.css +1 -0
- data/test/fixtures/replies/_reply.erb +1 -0
- data/test/fixtures/test/_counter.html.erb +1 -0
- data/test/fixtures/test/_customer.erb +1 -1
- data/test/fixtures/test/_customer_with_var.erb +1 -0
- data/test/fixtures/test/_layout_for_block_with_args.html.erb +3 -0
- data/test/fixtures/test/_local_inspector.html.erb +1 -0
- data/test/fixtures/test/_partial_with_only_html_version.html.erb +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hyphen-ated.erb +1 -0
- data/test/fixtures/test/implicit_content_type.atom.builder +2 -0
- data/test/fixtures/test/nested_layout.erb +3 -0
- data/test/fixtures/test/non_erb_block_content_for.builder +1 -1
- data/test/fixtures/test/sub_template_raise.html.erb +1 -0
- data/test/fixtures/test/template.erb +1 -0
- data/test/fixtures/test/using_layout_around_block_with_args.html.erb +1 -0
- data/test/template/active_record_helper_i18n_test.rb +46 -0
- data/test/template/active_record_helper_test.rb +24 -24
- data/test/template/asset_tag_helper_test.rb +161 -29
- data/test/template/atom_feed_helper_test.rb +114 -5
- data/test/template/compiled_templates_test.rb +59 -0
- data/test/template/date_helper_i18n_test.rb +113 -0
- data/test/template/date_helper_test.rb +403 -109
- data/test/template/form_helper_test.rb +213 -154
- data/test/template/form_options_helper_test.rb +249 -897
- data/test/template/form_tag_helper_test.rb +80 -32
- data/test/template/javascript_helper_test.rb +17 -18
- data/test/template/number_helper_i18n_test.rb +54 -0
- data/test/template/number_helper_test.rb +43 -13
- data/test/template/prototype_helper_test.rb +101 -84
- data/test/template/record_tag_helper_test.rb +24 -20
- data/test/template/render_test.rb +193 -0
- data/test/template/sanitize_helper_test.rb +3 -3
- data/test/template/tag_helper_test.rb +34 -14
- data/test/template/text_helper_test.rb +83 -9
- data/test/template/translation_helper_test.rb +28 -0
- data/test/template/url_helper_test.rb +55 -18
- metadata +57 -18
- data/lib/action_view/helpers/javascripts/controls.js +0 -963
- data/lib/action_view/helpers/javascripts/dragdrop.js +0 -972
- data/lib/action_view/helpers/javascripts/effects.js +0 -1120
- data/lib/action_view/helpers/javascripts/prototype.js +0 -4225
- data/lib/action_view/partial_template.rb +0 -70
- data/lib/action_view/template_finder.rb +0 -177
- data/lib/action_view/template_handlers/compilable.rb +0 -128
- data/test/controller/custom_handler_test.rb +0 -45
- data/test/controller/new_render_test.rb +0 -945
- data/test/fixtures/test/block_content_for.erb +0 -2
- data/test/fixtures/test/erb_content_for.erb +0 -2
- data/test/template/deprecated_erb_variable_test.rb +0 -9
- data/test/template/template_finder_test.rb +0 -73
- 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.
|
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.
|
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.
|
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.
|
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.
|
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
|
-
|
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
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
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(
|
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(
|
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
|
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
|