actionpack 2.0.5 → 2.1.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 +149 -7
- data/MIT-LICENSE +1 -1
- data/README +1 -1
- data/Rakefile +5 -6
- data/lib/action_controller.rb +2 -2
- data/lib/action_controller/assertions/model_assertions.rb +2 -1
- data/lib/action_controller/assertions/response_assertions.rb +4 -2
- data/lib/action_controller/assertions/routing_assertions.rb +3 -3
- data/lib/action_controller/assertions/selector_assertions.rb +30 -27
- data/lib/action_controller/assertions/tag_assertions.rb +3 -3
- data/lib/action_controller/base.rb +103 -129
- data/lib/action_controller/benchmarking.rb +3 -3
- data/lib/action_controller/caching.rb +41 -652
- data/lib/action_controller/caching/actions.rb +144 -0
- data/lib/action_controller/caching/fragments.rb +138 -0
- data/lib/action_controller/caching/pages.rb +154 -0
- data/lib/action_controller/caching/sql_cache.rb +18 -0
- data/lib/action_controller/caching/sweeping.rb +97 -0
- data/lib/action_controller/cgi_ext/cookie.rb +27 -23
- data/lib/action_controller/cgi_ext/stdinput.rb +1 -0
- data/lib/action_controller/cgi_process.rb +6 -4
- data/lib/action_controller/components.rb +7 -6
- data/lib/action_controller/cookies.rb +31 -19
- data/lib/action_controller/dispatcher.rb +51 -84
- data/lib/action_controller/filters.rb +295 -421
- data/lib/action_controller/flash.rb +1 -6
- data/lib/action_controller/headers.rb +31 -0
- data/lib/action_controller/helpers.rb +26 -9
- data/lib/action_controller/http_authentication.rb +1 -1
- data/lib/action_controller/integration.rb +65 -13
- data/lib/action_controller/layout.rb +24 -39
- data/lib/action_controller/mime_responds.rb +7 -3
- data/lib/action_controller/mime_type.rb +25 -9
- data/lib/action_controller/mime_types.rb +1 -1
- data/lib/action_controller/polymorphic_routes.rb +32 -17
- data/lib/action_controller/record_identifier.rb +10 -4
- data/lib/action_controller/request.rb +46 -30
- data/lib/action_controller/request_forgery_protection.rb +10 -9
- data/lib/action_controller/request_profiler.rb +29 -8
- data/lib/action_controller/rescue.rb +24 -24
- data/lib/action_controller/resources.rb +66 -23
- data/lib/action_controller/response.rb +2 -2
- data/lib/action_controller/routing.rb +113 -1229
- data/lib/action_controller/routing/builder.rb +204 -0
- data/lib/action_controller/{routing_optimisation.rb → routing/optimisations.rb} +13 -12
- data/lib/action_controller/routing/recognition_optimisation.rb +158 -0
- data/lib/action_controller/routing/route.rb +240 -0
- data/lib/action_controller/routing/route_set.rb +435 -0
- data/lib/action_controller/routing/routing_ext.rb +46 -0
- data/lib/action_controller/routing/segments.rb +283 -0
- data/lib/action_controller/session/active_record_store.rb +13 -8
- data/lib/action_controller/session/cookie_store.rb +20 -17
- data/lib/action_controller/session_management.rb +10 -3
- data/lib/action_controller/streaming.rb +45 -31
- data/lib/action_controller/test_case.rb +33 -23
- data/lib/action_controller/test_process.rb +39 -35
- data/lib/action_controller/url_rewriter.rb +18 -12
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +1 -1
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +11 -3
- data/lib/action_view/base.rb +73 -390
- data/lib/action_view/helpers/active_record_helper.rb +83 -62
- data/lib/action_view/helpers/asset_tag_helper.rb +101 -44
- data/lib/action_view/helpers/atom_feed_helper.rb +35 -7
- data/lib/action_view/helpers/benchmark_helper.rb +5 -3
- data/lib/action_view/helpers/cache_helper.rb +3 -2
- data/lib/action_view/helpers/capture_helper.rb +1 -2
- data/lib/action_view/helpers/date_helper.rb +104 -82
- data/lib/action_view/helpers/form_helper.rb +148 -75
- data/lib/action_view/helpers/form_options_helper.rb +44 -23
- data/lib/action_view/helpers/form_tag_helper.rb +22 -13
- data/lib/action_view/helpers/javascripts/controls.js +1 -1
- data/lib/action_view/helpers/javascripts/dragdrop.js +1 -1
- data/lib/action_view/helpers/javascripts/effects.js +1 -1
- data/lib/action_view/helpers/number_helper.rb +10 -3
- data/lib/action_view/helpers/prototype_helper.rb +61 -29
- data/lib/action_view/helpers/record_tag_helper.rb +3 -3
- data/lib/action_view/helpers/sanitize_helper.rb +23 -17
- data/lib/action_view/helpers/scriptaculous_helper.rb +86 -60
- data/lib/action_view/helpers/text_helper.rb +153 -125
- data/lib/action_view/helpers/url_helper.rb +83 -28
- data/lib/action_view/inline_template.rb +20 -0
- data/lib/action_view/partial_template.rb +70 -0
- data/lib/action_view/partials.rb +31 -73
- data/lib/action_view/template.rb +127 -0
- data/lib/action_view/template_error.rb +8 -7
- data/lib/action_view/template_finder.rb +177 -0
- data/lib/action_view/template_handler.rb +18 -1
- data/lib/action_view/template_handlers/builder.rb +10 -2
- data/lib/action_view/template_handlers/compilable.rb +128 -0
- data/lib/action_view/template_handlers/erb.rb +37 -2
- data/lib/action_view/template_handlers/rjs.rb +14 -1
- data/lib/action_view/test_case.rb +58 -0
- data/test/abstract_unit.rb +1 -1
- data/test/active_record_unit.rb +3 -6
- data/test/activerecord/active_record_store_test.rb +1 -2
- data/test/activerecord/render_partial_with_record_identification_test.rb +158 -41
- data/test/adv_attr_test.rb +20 -0
- data/test/controller/action_pack_assertions_test.rb +16 -19
- data/test/controller/addresses_render_test.rb +1 -1
- data/test/controller/assert_select_test.rb +13 -6
- data/test/controller/base_test.rb +48 -2
- data/test/controller/benchmark_test.rb +1 -2
- data/test/controller/caching_test.rb +282 -21
- data/test/controller/capture_test.rb +1 -1
- data/test/controller/cgi_test.rb +1 -1
- data/test/controller/components_test.rb +1 -1
- data/test/controller/content_type_test.rb +2 -2
- data/test/controller/cookie_test.rb +13 -2
- data/test/controller/custom_handler_test.rb +14 -10
- data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -1
- data/test/controller/dispatcher_test.rb +31 -49
- data/test/controller/fake_controllers.rb +17 -0
- data/test/controller/fake_models.rb +6 -0
- data/test/controller/filter_params_test.rb +14 -8
- data/test/controller/filters_test.rb +44 -16
- data/test/controller/flash_test.rb +2 -2
- data/test/controller/header_test.rb +14 -0
- data/test/controller/helper_test.rb +19 -15
- data/test/controller/html-scanner/document_test.rb +1 -2
- data/test/controller/html-scanner/node_test.rb +1 -2
- data/test/controller/html-scanner/sanitizer_test.rb +8 -5
- data/test/controller/html-scanner/tag_node_test.rb +1 -2
- data/test/controller/html-scanner/text_node_test.rb +2 -3
- data/test/controller/html-scanner/tokenizer_test.rb +8 -2
- data/test/controller/http_authentication_test.rb +1 -1
- data/test/controller/integration_test.rb +14 -16
- data/test/controller/integration_upload_test.rb +43 -0
- data/test/controller/layout_test.rb +26 -6
- data/test/controller/mime_responds_test.rb +39 -7
- data/test/controller/mime_type_test.rb +29 -5
- data/test/controller/new_render_test.rb +105 -34
- data/test/controller/polymorphic_routes_test.rb +32 -20
- data/test/controller/record_identifier_test.rb +38 -2
- data/test/controller/redirect_test.rb +21 -1
- data/test/controller/render_test.rb +59 -15
- data/test/controller/request_forgery_protection_test.rb +92 -5
- data/test/controller/request_test.rb +64 -6
- data/test/controller/rescue_test.rb +22 -6
- data/test/controller/resources_test.rb +102 -14
- data/test/controller/routing_test.rb +231 -19
- data/test/controller/selector_test.rb +2 -2
- data/test/controller/send_file_test.rb +14 -3
- data/test/controller/session/cookie_store_test.rb +16 -4
- data/test/controller/session/mem_cache_store_test.rb +3 -4
- data/test/controller/session_fixation_test.rb +1 -1
- data/test/controller/session_management_test.rb +23 -1
- data/test/controller/test_test.rb +39 -18
- data/test/controller/url_rewriter_test.rb +35 -1
- data/test/controller/verification_test.rb +1 -1
- data/test/controller/view_paths_test.rb +15 -12
- data/test/controller/webservice_test.rb +48 -3
- data/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
- data/test/fixtures/company.rb +1 -0
- data/test/fixtures/customers/_customer.html.erb +1 -0
- data/test/fixtures/db_definitions/sqlite.sql +6 -0
- data/test/fixtures/functional_caching/_partial.erb +3 -0
- data/test/fixtures/functional_caching/fragment_cached.html.erb +2 -0
- data/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
- data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
- data/test/fixtures/good_customers/_good_customer.html.erb +1 -0
- data/test/fixtures/mascot.rb +3 -0
- data/test/fixtures/mascots.yml +4 -0
- data/test/fixtures/mascots/_mascot.html.erb +1 -0
- data/test/fixtures/multipart/boundary_problem_file +10 -0
- data/test/fixtures/public/javascripts/application.js +1 -0
- data/test/fixtures/public/javascripts/controls.js +1 -0
- data/test/fixtures/public/javascripts/dragdrop.js +1 -0
- data/test/fixtures/public/javascripts/effects.js +1 -0
- data/test/fixtures/public/javascripts/prototype.js +1 -0
- data/test/fixtures/public/javascripts/version.1.0.js +1 -0
- data/test/fixtures/public/stylesheets/version.1.0.css +1 -0
- data/test/fixtures/reply.rb +1 -0
- data/test/fixtures/shared.html.erb +1 -0
- data/test/fixtures/symlink_parent/symlinked_layout.erb +5 -0
- data/test/fixtures/test/_customer_counter.erb +1 -0
- data/test/fixtures/test/_form.erb +1 -0
- data/test/fixtures/test/_labelling_form.erb +1 -0
- data/test/fixtures/test/_raise.html.erb +1 -0
- data/test/fixtures/test/greeting.js.rjs +1 -0
- data/test/fixtures/topics/_topic.html.erb +1 -0
- data/test/template/active_record_helper_test.rb +25 -8
- data/test/template/asset_tag_helper_test.rb +100 -17
- data/test/template/atom_feed_helper_test.rb +29 -1
- data/test/template/benchmark_helper_test.rb +10 -22
- data/test/template/date_helper_test.rb +455 -153
- data/test/template/erb_util_test.rb +10 -42
- data/test/template/form_helper_test.rb +192 -66
- data/test/template/form_options_helper_test.rb +19 -8
- data/test/template/form_tag_helper_test.rb +11 -8
- data/test/template/javascript_helper_test.rb +3 -9
- data/test/template/number_helper_test.rb +6 -3
- data/test/template/prototype_helper_test.rb +27 -40
- data/test/template/record_tag_helper_test.rb +54 -0
- data/test/template/sanitize_helper_test.rb +5 -6
- data/test/template/scriptaculous_helper_test.rb +7 -13
- data/test/template/tag_helper_test.rb +3 -6
- data/test/template/template_finder_test.rb +73 -0
- data/test/template/template_object_test.rb +95 -0
- data/test/template/test_test.rb +56 -0
- data/test/template/text_helper_test.rb +46 -33
- data/test/template/url_helper_test.rb +8 -10
- metadata +65 -12
- data/lib/action_view/compiled_templates.rb +0 -69
- data/test/action_view_test.rb +0 -44
- data/test/activerecord/fixtures_test.rb +0 -24
- data/test/controller/fragment_store_setting_test.rb +0 -47
- data/test/template/compiled_templates_test.rb +0 -197
- data/test/template/deprecate_ivars_test.rb +0 -51
@@ -3,8 +3,8 @@
|
|
3
3
|
# Under MIT and/or CC By license.
|
4
4
|
#++
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
6
|
+
require 'abstract_unit'
|
7
|
+
require 'controller/fake_controllers'
|
8
8
|
|
9
9
|
|
10
10
|
unless defined?(ActionMailer)
|
@@ -345,10 +345,17 @@ class AssertSelectTest < Test::Unit::TestCase
|
|
345
345
|
page.replace "test", "<div id=\"1\">\343\203\201\343\202\261\343\203\203\343\203\210</div>"
|
346
346
|
end
|
347
347
|
assert_select_rjs do
|
348
|
-
|
349
|
-
assert_select
|
350
|
-
assert_select
|
351
|
-
|
348
|
+
str = "#1"
|
349
|
+
assert_select str, :text => "\343\203\201\343\202\261\343\203\203\343\203\210"
|
350
|
+
assert_select str, "\343\203\201\343\202\261\343\203\203\343\203\210"
|
351
|
+
if str.respond_to?(:force_encoding)
|
352
|
+
str.force_encoding(Encoding::UTF_8)
|
353
|
+
assert_select str, /\343\203\201..\343\203\210/u
|
354
|
+
assert_raises(AssertionFailedError) { assert_select str, /\343\203\201.\343\203\210/u }
|
355
|
+
else
|
356
|
+
assert_select str, Regexp.new("\343\203\201..\343\203\210",0,'U')
|
357
|
+
assert_raises(AssertionFailedError) { assert_select str, Regexp.new("\343\203\201.\343\203\210",0,'U') }
|
358
|
+
end
|
352
359
|
end
|
353
360
|
end
|
354
361
|
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require 'test/unit'
|
1
|
+
require 'abstract_unit'
|
3
2
|
require 'pp' # require 'pp' early to prevent hidden_methods from not picking up the pretty-print methods until too late
|
4
3
|
|
5
4
|
# Provide some controller to run the tests on.
|
@@ -49,6 +48,15 @@ protected
|
|
49
48
|
|
50
49
|
end
|
51
50
|
|
51
|
+
class DefaultUrlOptionsController < ActionController::Base
|
52
|
+
def default_url_options_action
|
53
|
+
end
|
54
|
+
|
55
|
+
def default_url_options(options = nil)
|
56
|
+
{ :host => 'www.override.com', :action => 'new', :bacon => 'chunky' }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
52
60
|
class ControllerClassTests < Test::Unit::TestCase
|
53
61
|
def test_controller_path
|
54
62
|
assert_equal 'empty', EmptyController.controller_path
|
@@ -135,3 +143,41 @@ class PerformActionTest < Test::Unit::TestCase
|
|
135
143
|
assert_response 404
|
136
144
|
end
|
137
145
|
end
|
146
|
+
|
147
|
+
class DefaultUrlOptionsTest < Test::Unit::TestCase
|
148
|
+
def setup
|
149
|
+
@controller = DefaultUrlOptionsController.new
|
150
|
+
|
151
|
+
@request = ActionController::TestRequest.new
|
152
|
+
@response = ActionController::TestResponse.new
|
153
|
+
|
154
|
+
@request.host = 'www.example.com'
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_default_url_options_are_used_if_set
|
158
|
+
ActionController::Routing::Routes.draw do |map|
|
159
|
+
map.default_url_options 'default_url_options', :controller => 'default_url_options'
|
160
|
+
map.connect ':controller/:action/:id'
|
161
|
+
end
|
162
|
+
|
163
|
+
get :default_url_options_action # Make a dummy request so that the controller is initialized properly.
|
164
|
+
|
165
|
+
assert_equal 'http://www.override.com/default_url_options/new?bacon=chunky', @controller.url_for(:controller => 'default_url_options')
|
166
|
+
assert_equal 'http://www.override.com/default_url_options?bacon=chunky', @controller.send(:default_url_options_url)
|
167
|
+
ensure
|
168
|
+
ActionController::Routing::Routes.load!
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
class EnsureNamedRoutesWorksTicket22BugTest < Test::Unit::TestCase
|
173
|
+
def test_named_routes_still_work
|
174
|
+
ActionController::Routing::Routes.draw do |map|
|
175
|
+
map.resources :things
|
176
|
+
end
|
177
|
+
EmptyController.send :include, ActionController::UrlWriter
|
178
|
+
|
179
|
+
assert_equal '/things', EmptyController.new.send(:things_path)
|
180
|
+
ensure
|
181
|
+
ActionController::Routing::Routes.load!
|
182
|
+
end
|
183
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require
|
2
|
+
require 'abstract_unit'
|
3
3
|
|
4
4
|
CACHE_DIR = 'test_cache'
|
5
5
|
# Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
|
6
6
|
FILE_STORE_PATH = File.join(File.dirname(__FILE__), '/../temp/', CACHE_DIR)
|
7
7
|
ActionController::Base.page_cache_directory = FILE_STORE_PATH
|
8
|
-
ActionController::Base.
|
8
|
+
ActionController::Base.cache_store = :file_store, FILE_STORE_PATH
|
9
|
+
ActionController::Base.view_paths = [ File.dirname(__FILE__) + '/../fixtures/' ]
|
9
10
|
|
10
11
|
class PageCachingTestController < ActionController::Base
|
11
|
-
caches_page :ok, :no_content, :
|
12
|
+
caches_page :ok, :no_content, :if => Proc.new { |c| !c.request.format.json? }
|
13
|
+
caches_page :found, :not_found
|
12
14
|
|
13
15
|
def ok
|
14
16
|
head :ok
|
@@ -25,17 +27,17 @@ class PageCachingTestController < ActionController::Base
|
|
25
27
|
def not_found
|
26
28
|
head :not_found
|
27
29
|
end
|
28
|
-
|
30
|
+
|
29
31
|
def custom_path
|
30
32
|
render :text => "Super soaker"
|
31
33
|
cache_page("Super soaker", "/index.html")
|
32
34
|
end
|
33
|
-
|
35
|
+
|
34
36
|
def expire_custom_path
|
35
37
|
expire_page("/index.html")
|
36
38
|
head :ok
|
37
39
|
end
|
38
|
-
|
40
|
+
|
39
41
|
def trailing_slash
|
40
42
|
render :text => "Sneak attack"
|
41
43
|
end
|
@@ -95,7 +97,7 @@ class PageCachingTest < Test::Unit::TestCase
|
|
95
97
|
get :expire_custom_path
|
96
98
|
assert !File.exist?("#{FILE_STORE_PATH}/index.html")
|
97
99
|
end
|
98
|
-
|
100
|
+
|
99
101
|
def test_should_cache_without_trailing_slash_on_url
|
100
102
|
@controller.class.cache_page 'cached content', '/page_caching_test/trailing_slash'
|
101
103
|
assert File.exist?("#{FILE_STORE_PATH}/page_caching_test/trailing_slash.html")
|
@@ -128,6 +130,12 @@ class PageCachingTest < Test::Unit::TestCase
|
|
128
130
|
end
|
129
131
|
end
|
130
132
|
|
133
|
+
def test_page_caching_conditional_options
|
134
|
+
@request.env['HTTP_ACCEPT'] = 'application/json'
|
135
|
+
get :ok
|
136
|
+
assert_page_not_cached :ok
|
137
|
+
end
|
138
|
+
|
131
139
|
private
|
132
140
|
def assert_page_cached(action, message = "#{action} should have been cached")
|
133
141
|
assert page_cached?(action), message
|
@@ -144,12 +152,15 @@ end
|
|
144
152
|
|
145
153
|
|
146
154
|
class ActionCachingTestController < ActionController::Base
|
147
|
-
caches_action :index, :redirected, :forbidden
|
155
|
+
caches_action :index, :redirected, :forbidden, :if => Proc.new { |c| !c.request.format.json? }
|
148
156
|
caches_action :show, :cache_path => 'http://test.host/custom/show'
|
149
157
|
caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" }
|
158
|
+
caches_action :with_layout
|
159
|
+
|
160
|
+
layout 'talk_from_action.erb'
|
150
161
|
|
151
162
|
def index
|
152
|
-
@cache_this =
|
163
|
+
@cache_this = MockTime.now.to_f.to_s
|
153
164
|
render :text => @cache_this
|
154
165
|
end
|
155
166
|
|
@@ -162,14 +173,26 @@ class ActionCachingTestController < ActionController::Base
|
|
162
173
|
headers["Status"] = "403 Forbidden"
|
163
174
|
end
|
164
175
|
|
176
|
+
def with_layout
|
177
|
+
@cache_this = MockTime.now.to_f.to_s
|
178
|
+
render :text => @cache_this, :layout => true
|
179
|
+
end
|
180
|
+
|
165
181
|
alias_method :show, :index
|
166
182
|
alias_method :edit, :index
|
183
|
+
alias_method :destroy, :index
|
167
184
|
|
168
185
|
def expire
|
169
186
|
expire_action :controller => 'action_caching_test', :action => 'index'
|
170
187
|
render :nothing => true
|
171
188
|
end
|
189
|
+
end
|
172
190
|
|
191
|
+
class MockTime < Time
|
192
|
+
# Let Time spicy to assure that Time.now != Time.now
|
193
|
+
def to_f
|
194
|
+
super+rand
|
195
|
+
end
|
173
196
|
end
|
174
197
|
|
175
198
|
class ActionCachingMockController
|
@@ -209,18 +232,48 @@ class ActionCacheTest < Test::Unit::TestCase
|
|
209
232
|
get :index
|
210
233
|
cached_time = content_to_cache
|
211
234
|
assert_equal cached_time, @response.body
|
212
|
-
|
235
|
+
assert fragment_exist?('hostname.com/action_caching_test')
|
213
236
|
reset!
|
214
237
|
|
215
238
|
get :index
|
216
239
|
assert_equal cached_time, @response.body
|
217
240
|
end
|
218
|
-
|
241
|
+
|
242
|
+
def test_simple_action_not_cached
|
243
|
+
get :destroy
|
244
|
+
cached_time = content_to_cache
|
245
|
+
assert_equal cached_time, @response.body
|
246
|
+
assert !fragment_exist?('hostname.com/action_caching_test/destroy')
|
247
|
+
reset!
|
248
|
+
|
249
|
+
get :destroy
|
250
|
+
assert_not_equal cached_time, @response.body
|
251
|
+
end
|
252
|
+
|
253
|
+
def test_action_cache_with_layout
|
254
|
+
get :with_layout
|
255
|
+
cached_time = content_to_cache
|
256
|
+
assert_not_equal cached_time, @response.body
|
257
|
+
assert fragment_exist?('hostname.com/action_caching_test/with_layout')
|
258
|
+
reset!
|
259
|
+
|
260
|
+
get :with_layout
|
261
|
+
assert_not_equal cached_time, @response.body
|
262
|
+
|
263
|
+
assert_equal @response.body, read_fragment('hostname.com/action_caching_test/with_layout')
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_action_cache_conditional_options
|
267
|
+
@request.env['HTTP_ACCEPT'] = 'application/json'
|
268
|
+
get :index
|
269
|
+
assert !fragment_exist?('hostname.com/action_caching_test')
|
270
|
+
end
|
271
|
+
|
219
272
|
def test_action_cache_with_custom_cache_path
|
220
273
|
get :show
|
221
274
|
cached_time = content_to_cache
|
222
275
|
assert_equal cached_time, @response.body
|
223
|
-
|
276
|
+
assert fragment_exist?('test.host/custom/show')
|
224
277
|
reset!
|
225
278
|
|
226
279
|
get :show
|
@@ -229,11 +282,11 @@ class ActionCacheTest < Test::Unit::TestCase
|
|
229
282
|
|
230
283
|
def test_action_cache_with_custom_cache_path_in_block
|
231
284
|
get :edit
|
232
|
-
|
285
|
+
assert fragment_exist?('test.host/edit')
|
233
286
|
reset!
|
234
287
|
|
235
288
|
get :edit, :id => 1
|
236
|
-
|
289
|
+
assert fragment_exist?('test.host/1;edit')
|
237
290
|
end
|
238
291
|
|
239
292
|
def test_cache_expiration
|
@@ -262,9 +315,9 @@ class ActionCacheTest < Test::Unit::TestCase
|
|
262
315
|
@request.host = 'jamis.hostname.com'
|
263
316
|
get :index
|
264
317
|
jamis_cache = content_to_cache
|
265
|
-
|
318
|
+
|
266
319
|
reset!
|
267
|
-
|
320
|
+
|
268
321
|
@request.host = 'david.hostname.com'
|
269
322
|
get :index
|
270
323
|
david_cache = content_to_cache
|
@@ -308,7 +361,7 @@ class ActionCacheTest < Test::Unit::TestCase
|
|
308
361
|
assert_equal 'xml', path_object.extension
|
309
362
|
assert_equal 'example.org/posts/index.xml', path_object.path
|
310
363
|
end
|
311
|
-
|
364
|
+
|
312
365
|
def test_correct_content_type_is_returned_for_cache_hit
|
313
366
|
# run it twice to cache it the first time
|
314
367
|
get :index, :id => 'content-type.xml'
|
@@ -341,9 +394,217 @@ class ActionCacheTest < Test::Unit::TestCase
|
|
341
394
|
@controller = ActionCachingTestController.new
|
342
395
|
@request.host = 'hostname.com'
|
343
396
|
end
|
344
|
-
|
345
|
-
def
|
346
|
-
|
347
|
-
|
397
|
+
|
398
|
+
def fragment_exist?(path)
|
399
|
+
@controller.fragment_exist?(path)
|
400
|
+
end
|
401
|
+
|
402
|
+
def read_fragment(path)
|
403
|
+
@controller.read_fragment(path)
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
class FragmentCachingTestController < ActionController::Base
|
408
|
+
def some_action; end;
|
409
|
+
end
|
410
|
+
|
411
|
+
class FragmentCachingTest < Test::Unit::TestCase
|
412
|
+
def setup
|
413
|
+
ActionController::Base.perform_caching = true
|
414
|
+
@store = ActiveSupport::Cache::MemoryStore.new
|
415
|
+
ActionController::Base.cache_store = @store
|
416
|
+
@controller = FragmentCachingTestController.new
|
417
|
+
@params = {:controller => 'posts', :action => 'index'}
|
418
|
+
@request = ActionController::TestRequest.new
|
419
|
+
@response = ActionController::TestResponse.new
|
420
|
+
@controller.params = @params
|
421
|
+
@controller.request = @request
|
422
|
+
@controller.response = @response
|
423
|
+
@controller.send(:initialize_current_url)
|
424
|
+
end
|
425
|
+
|
426
|
+
def test_fragment_cache_key
|
427
|
+
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'))
|
430
|
+
end
|
431
|
+
|
432
|
+
def test_read_fragment__with_caching_enabled
|
433
|
+
@store.write('views/name', 'value')
|
434
|
+
assert_equal 'value', @controller.read_fragment('name')
|
435
|
+
end
|
436
|
+
|
437
|
+
def test_read_fragment__with_caching_disabled
|
438
|
+
ActionController::Base.perform_caching = false
|
439
|
+
@store.write('views/name', 'value')
|
440
|
+
assert_nil @controller.read_fragment('name')
|
441
|
+
end
|
442
|
+
|
443
|
+
def test_fragment_exist__with_caching_enabled
|
444
|
+
@store.write('views/name', 'value')
|
445
|
+
assert @controller.fragment_exist?('name')
|
446
|
+
assert !@controller.fragment_exist?('other_name')
|
447
|
+
end
|
448
|
+
|
449
|
+
def test_fragment_exist__with_caching_disabled
|
450
|
+
ActionController::Base.perform_caching = false
|
451
|
+
@store.write('views/name', 'value')
|
452
|
+
assert !@controller.fragment_exist?('name')
|
453
|
+
assert !@controller.fragment_exist?('other_name')
|
454
|
+
end
|
455
|
+
|
456
|
+
def test_write_fragment__with_caching_enabled
|
457
|
+
assert_nil @store.read('views/name')
|
458
|
+
assert_equal 'value', @controller.write_fragment('name', 'value')
|
459
|
+
assert_equal 'value', @store.read('views/name')
|
460
|
+
end
|
461
|
+
|
462
|
+
def test_write_fragment__with_caching_disabled
|
463
|
+
assert_nil @store.read('views/name')
|
464
|
+
ActionController::Base.perform_caching = false
|
465
|
+
assert_equal nil, @controller.write_fragment('name', 'value')
|
466
|
+
assert_nil @store.read('views/name')
|
467
|
+
end
|
468
|
+
|
469
|
+
def test_expire_fragment__with_simple_key
|
470
|
+
@store.write('views/name', 'value')
|
471
|
+
@controller.expire_fragment 'name'
|
472
|
+
assert_nil @store.read('views/name')
|
473
|
+
end
|
474
|
+
|
475
|
+
def test_expire_fragment__with__regexp
|
476
|
+
@store.write('views/name', 'value')
|
477
|
+
@store.write('views/another_name', 'another_value')
|
478
|
+
@store.write('views/primalgrasp', 'will not expire ;-)')
|
479
|
+
|
480
|
+
@controller.expire_fragment /name/
|
481
|
+
|
482
|
+
assert_nil @store.read('views/name')
|
483
|
+
assert_nil @store.read('views/another_name')
|
484
|
+
assert_equal 'will not expire ;-)', @store.read('views/primalgrasp')
|
485
|
+
end
|
486
|
+
|
487
|
+
def test_fragment_for__with_disabled_caching
|
488
|
+
ActionController::Base.perform_caching = false
|
489
|
+
|
490
|
+
@store.write('views/expensive', 'fragment content')
|
491
|
+
fragment_computed = false
|
492
|
+
|
493
|
+
buffer = 'generated till now -> '
|
494
|
+
@controller.fragment_for(Proc.new { fragment_computed = true }, 'expensive') { buffer }
|
495
|
+
|
496
|
+
assert fragment_computed
|
497
|
+
assert_equal 'generated till now -> ', buffer
|
498
|
+
end
|
499
|
+
|
500
|
+
def test_fragment_for
|
501
|
+
@store.write('views/expensive', 'fragment content')
|
502
|
+
fragment_computed = false
|
503
|
+
|
504
|
+
buffer = 'generated till now -> '
|
505
|
+
@controller.fragment_for(Proc.new { fragment_computed = true }, 'expensive') { buffer}
|
506
|
+
|
507
|
+
assert !fragment_computed
|
508
|
+
assert_equal 'generated till now -> fragment content', buffer
|
509
|
+
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
|
+
end
|
550
|
+
|
551
|
+
|
552
|
+
class FunctionalCachingController < ActionController::Base
|
553
|
+
def fragment_cached
|
554
|
+
end
|
555
|
+
|
556
|
+
def html_fragment_cached_with_partial
|
557
|
+
respond_to do |format|
|
558
|
+
format.html
|
348
559
|
end
|
560
|
+
end
|
561
|
+
|
562
|
+
def js_fragment_cached_with_partial
|
563
|
+
respond_to do |format|
|
564
|
+
format.js
|
565
|
+
end
|
566
|
+
end
|
567
|
+
|
568
|
+
|
569
|
+
def rescue_action(e)
|
570
|
+
raise e
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
574
|
+
FunctionalCachingController.view_paths = [ File.dirname(__FILE__) + "/../fixtures/" ]
|
575
|
+
|
576
|
+
class FunctionalFragmentCachingTest < Test::Unit::TestCase
|
577
|
+
def setup
|
578
|
+
ActionController::Base.perform_caching = true
|
579
|
+
@store = ActiveSupport::Cache::MemoryStore.new
|
580
|
+
ActionController::Base.cache_store = @store
|
581
|
+
@controller = FunctionalCachingController.new
|
582
|
+
@request = ActionController::TestRequest.new
|
583
|
+
@response = ActionController::TestResponse.new
|
584
|
+
end
|
585
|
+
def test_fragment_caching
|
586
|
+
get :fragment_cached
|
587
|
+
assert_response :success
|
588
|
+
expected_body = <<-CACHED
|
589
|
+
Hello
|
590
|
+
This bit's fragment cached
|
591
|
+
CACHED
|
592
|
+
assert_equal expected_body, @response.body
|
593
|
+
|
594
|
+
assert_equal "This bit's fragment cached", @store.read('views/test.host/functional_caching/fragment_cached')
|
595
|
+
end
|
596
|
+
|
597
|
+
def test_fragment_caching_in_partials
|
598
|
+
get :html_fragment_cached_with_partial
|
599
|
+
assert_response :success
|
600
|
+
assert_match /Fragment caching in a partial/, @response.body
|
601
|
+
assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/html_fragment_cached_with_partial')
|
602
|
+
end
|
603
|
+
|
604
|
+
def test_fragment_caching_in_rjs_partials
|
605
|
+
xhr :get, :js_fragment_cached_with_partial
|
606
|
+
assert_response :success
|
607
|
+
assert_match /Fragment caching in a partial/, @response.body
|
608
|
+
assert_match "Fragment caching in a partial", @store.read('views/test.host/functional_caching/js_fragment_cached_with_partial')
|
609
|
+
end
|
349
610
|
end
|