actionpack 2.2.3 → 2.3.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 +433 -375
- data/MIT-LICENSE +1 -1
- data/README +21 -75
- data/Rakefile +1 -1
- data/lib/action_controller.rb +80 -43
- data/lib/action_controller/assertions/model_assertions.rb +1 -0
- data/lib/action_controller/assertions/response_assertions.rb +43 -16
- data/lib/action_controller/assertions/routing_assertions.rb +1 -1
- data/lib/action_controller/assertions/selector_assertions.rb +17 -12
- data/lib/action_controller/assertions/tag_assertions.rb +1 -4
- data/lib/action_controller/base.rb +153 -82
- data/lib/action_controller/benchmarking.rb +9 -9
- data/lib/action_controller/caching.rb +9 -11
- data/lib/action_controller/caching/actions.rb +11 -18
- data/lib/action_controller/caching/fragments.rb +28 -20
- data/lib/action_controller/caching/pages.rb +13 -15
- data/lib/action_controller/caching/sweeping.rb +2 -2
- data/lib/action_controller/cgi_ext.rb +0 -1
- data/lib/action_controller/cgi_ext/cookie.rb +2 -0
- data/lib/action_controller/cgi_process.rb +54 -162
- data/lib/action_controller/cookies.rb +13 -25
- data/lib/action_controller/dispatcher.rb +43 -122
- data/lib/action_controller/failsafe.rb +52 -0
- data/lib/action_controller/flash.rb +38 -47
- data/lib/action_controller/helpers.rb +13 -9
- data/lib/action_controller/http_authentication.rb +203 -23
- data/lib/action_controller/integration.rb +126 -70
- data/lib/action_controller/layout.rb +36 -39
- data/lib/action_controller/middleware_stack.rb +119 -0
- data/lib/action_controller/middlewares.rb +13 -0
- data/lib/action_controller/mime_responds.rb +19 -4
- data/lib/action_controller/mime_type.rb +8 -0
- data/lib/action_controller/params_parser.rb +71 -0
- data/lib/action_controller/performance_test.rb +0 -1
- data/lib/action_controller/polymorphic_routes.rb +36 -30
- data/lib/action_controller/reloader.rb +14 -0
- data/lib/action_controller/request.rb +107 -499
- data/lib/action_controller/request_forgery_protection.rb +7 -39
- data/lib/action_controller/rescue.rb +55 -35
- data/lib/action_controller/resources.rb +34 -31
- data/lib/action_controller/response.rb +99 -57
- data/lib/action_controller/rewindable_input.rb +28 -0
- data/lib/action_controller/routing.rb +7 -7
- data/lib/action_controller/routing/builder.rb +4 -1
- data/lib/action_controller/routing/optimisations.rb +1 -1
- data/lib/action_controller/routing/recognition_optimisation.rb +1 -2
- data/lib/action_controller/routing/route.rb +15 -5
- data/lib/action_controller/routing/route_set.rb +82 -35
- data/lib/action_controller/routing/segments.rb +35 -0
- data/lib/action_controller/session/abstract_store.rb +181 -0
- data/lib/action_controller/session/cookie_store.rb +197 -175
- data/lib/action_controller/session/mem_cache_store.rb +36 -83
- data/lib/action_controller/session_management.rb +26 -134
- data/lib/action_controller/streaming.rb +24 -7
- 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 +87 -30
- data/lib/action_controller/test_process.rb +145 -104
- data/lib/action_controller/uploaded_file.rb +44 -0
- data/lib/action_controller/url_rewriter.rb +3 -6
- data/lib/action_controller/vendor/html-scanner.rb +16 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +1 -1
- data/lib/action_controller/vendor/rack-1.0/rack.rb +89 -0
- data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +22 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +37 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +37 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +58 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +124 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +51 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +40 -0
- data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +480 -0
- data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +63 -0
- data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +36 -0
- data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +49 -0
- data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +61 -0
- data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +45 -0
- data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +29 -0
- data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +23 -0
- data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +85 -0
- data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +153 -0
- data/lib/action_controller/vendor/rack-1.0/rack/file.rb +88 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +48 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +61 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +8 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +89 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +84 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +59 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +8 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +18 -0
- data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +67 -0
- data/lib/action_controller/vendor/rack-1.0/rack/head.rb +19 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +462 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +65 -0
- data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +16 -0
- data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +27 -0
- data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +204 -0
- data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +160 -0
- data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +57 -0
- data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +64 -0
- data/lib/action_controller/vendor/rack-1.0/rack/request.rb +241 -0
- data/lib/action_controller/vendor/rack-1.0/rack/response.rb +179 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +142 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +91 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +109 -0
- data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +100 -0
- data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +349 -0
- data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +106 -0
- data/lib/action_controller/vendor/rack-1.0/rack/static.rb +38 -0
- data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +55 -0
- data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +392 -0
- data/lib/action_controller/verification.rb +1 -1
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +2 -2
- data/lib/action_view.rb +22 -17
- data/lib/action_view/base.rb +53 -79
- data/lib/action_view/erb/util.rb +38 -0
- data/lib/action_view/helpers.rb +24 -5
- data/lib/action_view/helpers/active_record_helper.rb +2 -2
- data/lib/action_view/helpers/asset_tag_helper.rb +81 -50
- data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
- data/lib/action_view/helpers/benchmark_helper.rb +26 -5
- data/lib/action_view/helpers/date_helper.rb +82 -7
- data/lib/action_view/helpers/form_helper.rb +295 -64
- data/lib/action_view/helpers/form_options_helper.rb +160 -18
- data/lib/action_view/helpers/form_tag_helper.rb +2 -2
- data/lib/action_view/helpers/number_helper.rb +31 -18
- data/lib/action_view/helpers/prototype_helper.rb +2 -12
- data/lib/action_view/helpers/sanitize_helper.rb +0 -10
- data/lib/action_view/helpers/scriptaculous_helper.rb +1 -0
- data/lib/action_view/helpers/tag_helper.rb +3 -4
- data/lib/action_view/helpers/text_helper.rb +99 -122
- data/lib/action_view/helpers/translation_helper.rb +19 -1
- data/lib/action_view/helpers/url_helper.rb +25 -2
- data/lib/action_view/inline_template.rb +1 -1
- data/lib/action_view/locale/en.yml +19 -1
- data/lib/action_view/partials.rb +46 -9
- data/lib/action_view/paths.rb +28 -84
- data/lib/action_view/reloadable_template.rb +117 -0
- data/lib/action_view/renderable.rb +28 -35
- data/lib/action_view/renderable_partial.rb +3 -4
- data/lib/action_view/template.rb +172 -31
- data/lib/action_view/template_error.rb +8 -9
- data/lib/action_view/template_handler.rb +1 -1
- data/lib/action_view/template_handlers.rb +9 -6
- data/lib/action_view/template_handlers/erb.rb +2 -39
- data/lib/action_view/template_handlers/rjs.rb +1 -0
- data/lib/action_view/test_case.rb +27 -1
- data/test/abstract_unit.rb +23 -17
- data/test/active_record_unit.rb +5 -4
- data/test/activerecord/active_record_store_test.rb +139 -106
- data/test/activerecord/render_partial_with_record_identification_test.rb +5 -21
- data/test/controller/action_pack_assertions_test.rb +25 -23
- data/test/controller/addresses_render_test.rb +3 -6
- data/test/controller/assert_select_test.rb +83 -70
- data/test/controller/base_test.rb +11 -13
- data/test/controller/benchmark_test.rb +3 -3
- data/test/controller/caching_test.rb +34 -24
- data/test/controller/capture_test.rb +3 -6
- data/test/controller/content_type_test.rb +3 -6
- data/test/controller/cookie_test.rb +31 -66
- data/test/controller/deprecation/deprecated_base_methods_test.rb +9 -11
- data/test/controller/dispatcher_test.rb +23 -28
- data/test/controller/fake_models.rb +8 -0
- data/test/controller/filters_test.rb +6 -2
- data/test/controller/flash_test.rb +2 -6
- data/test/controller/helper_test.rb +15 -1
- data/test/controller/html-scanner/document_test.rb +1 -1
- data/test/controller/html-scanner/sanitizer_test.rb +1 -1
- data/test/controller/http_basic_authentication_test.rb +88 -0
- data/test/controller/http_digest_authentication_test.rb +178 -0
- data/test/controller/integration_test.rb +56 -52
- data/test/controller/layout_test.rb +46 -44
- data/test/controller/middleware_stack_test.rb +90 -0
- data/test/controller/mime_responds_test.rb +7 -11
- data/test/controller/mime_type_test.rb +9 -0
- data/test/controller/polymorphic_routes_test.rb +235 -151
- data/test/controller/rack_test.rb +52 -81
- data/test/controller/redirect_test.rb +6 -14
- data/test/controller/render_test.rb +273 -60
- data/test/controller/request/json_params_parsing_test.rb +45 -0
- data/test/controller/request/multipart_params_parsing_test.rb +223 -0
- data/test/controller/request/query_string_parsing_test.rb +120 -0
- data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
- data/test/controller/request/xml_params_parsing_test.rb +88 -0
- data/test/controller/request_forgery_protection_test.rb +17 -98
- data/test/controller/request_test.rb +45 -530
- data/test/controller/rescue_test.rb +45 -22
- data/test/controller/resources_test.rb +112 -37
- data/test/controller/routing_test.rb +1442 -1384
- data/test/controller/selector_test.rb +3 -3
- data/test/controller/send_file_test.rb +30 -3
- data/test/controller/session/cookie_store_test.rb +169 -240
- data/test/controller/session/mem_cache_store_test.rb +94 -148
- data/test/controller/session/test_session_test.rb +58 -0
- data/test/controller/test_test.rb +32 -13
- data/test/controller/url_rewriter_test.rb +54 -4
- data/test/controller/verification_test.rb +1 -1
- data/test/controller/view_paths_test.rb +15 -15
- data/test/controller/webservice_test.rb +178 -147
- data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
- data/test/fixtures/layout_tests/alt/layouts/alt.rhtml +0 -0
- data/test/fixtures/layouts/default_html.html.erb +1 -0
- data/test/fixtures/layouts/xhr.html.erb +2 -0
- data/test/fixtures/multipart/empty +10 -0
- data/test/fixtures/multipart/hello.txt +1 -0
- data/test/fixtures/multipart/none +9 -0
- data/test/fixtures/public/500.da.html +1 -0
- data/test/fixtures/quiz/questions/_question.html.erb +1 -0
- data/test/fixtures/replies.yml +1 -1
- data/test/fixtures/test/_one.html.erb +1 -0
- data/test/fixtures/test/_two.html.erb +1 -0
- data/test/fixtures/test/dont_pick_me +1 -0
- data/test/fixtures/test/hello.builder +1 -1
- data/test/fixtures/test/hello_world.da.html.erb +1 -0
- data/test/fixtures/test/hello_world.erb~ +1 -0
- data/test/fixtures/test/hello_world.pt-BR.html.erb +1 -0
- data/test/fixtures/test/malformed/malformed.en.html.erb~ +1 -0
- data/test/fixtures/test/malformed/malformed.erb~ +1 -0
- data/test/fixtures/test/malformed/malformed.html.erb~ +1 -0
- data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
- data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
- data/test/fixtures/test/render_implicit_html_template_from_xhr_request.da.html.erb +1 -0
- data/test/fixtures/test/render_implicit_html_template_from_xhr_request.html.erb +1 -0
- data/test/fixtures/test/render_implicit_js_template_without_layout.js.erb +1 -0
- data/test/fixtures/test/utf8.html.erb +2 -0
- data/test/template/active_record_helper_i18n_test.rb +31 -33
- data/test/template/active_record_helper_test.rb +34 -0
- data/test/template/asset_tag_helper_test.rb +52 -14
- data/test/template/atom_feed_helper_test.rb +3 -5
- data/test/template/benchmark_helper_test.rb +50 -24
- data/test/template/compiled_templates_test.rb +177 -33
- data/test/template/date_helper_i18n_test.rb +88 -81
- data/test/template/date_helper_test.rb +427 -43
- data/test/template/form_helper_test.rb +243 -44
- data/test/template/form_options_helper_test.rb +631 -565
- data/test/template/form_tag_helper_test.rb +9 -2
- data/test/template/javascript_helper_test.rb +0 -5
- data/test/template/number_helper_i18n_test.rb +60 -48
- data/test/template/number_helper_test.rb +1 -0
- data/test/template/render_test.rb +117 -35
- data/test/template/test_test.rb +4 -6
- data/test/template/text_helper_test.rb +129 -50
- data/test/template/translation_helper_test.rb +23 -19
- data/test/template/url_helper_test.rb +35 -2
- data/test/view/test_case_test.rb +8 -0
- metadata +197 -23
- data/lib/action_controller/assertions.rb +0 -69
- data/lib/action_controller/caching/sql_cache.rb +0 -18
- data/lib/action_controller/cgi_ext/session.rb +0 -53
- data/lib/action_controller/components.rb +0 -169
- data/lib/action_controller/rack_process.rb +0 -297
- data/lib/action_controller/request_profiler.rb +0 -169
- data/lib/action_controller/session/active_record_store.rb +0 -340
- data/lib/action_controller/session/drb_server.rb +0 -32
- data/lib/action_controller/session/drb_store.rb +0 -35
- data/test/controller/cgi_test.rb +0 -269
- data/test/controller/components_test.rb +0 -156
- data/test/controller/http_authentication_test.rb +0 -54
- data/test/controller/integration_upload_test.rb +0 -43
- data/test/controller/session_fixation_test.rb +0 -89
- data/test/controller/session_management_test.rb +0 -178
- data/test/fixtures/test/hello_world.js +0 -1
@@ -1,181 +1,127 @@
|
|
1
1
|
require 'abstract_unit'
|
2
|
-
require 'action_controller/cgi_process'
|
3
|
-
require 'action_controller/cgi_ext'
|
4
2
|
|
3
|
+
# You need to start a memcached server inorder to run these tests
|
4
|
+
class MemCacheStoreTest < ActionController::IntegrationTest
|
5
|
+
class TestController < ActionController::Base
|
6
|
+
def no_session_access
|
7
|
+
head :ok
|
8
|
+
end
|
5
9
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
10
|
+
def set_session_value
|
11
|
+
session[:foo] = "bar"
|
12
|
+
head :ok
|
13
|
+
end
|
11
14
|
|
15
|
+
def get_session_value
|
16
|
+
render :text => "foo: #{session[:foo].inspect}"
|
17
|
+
end
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
begin
|
24
|
-
require 'memcache'
|
25
|
-
cache = MemCache.new('127.0.0.1')
|
26
|
-
# Test availability of the connection
|
27
|
-
cache.set(CONN_TEST_KEY, 1)
|
28
|
-
unless cache.get(CONN_TEST_KEY) == 1
|
29
|
-
puts 'Warning: memcache server available but corrupted.'
|
30
|
-
return nil
|
31
|
-
end
|
32
|
-
rescue LoadError, MemCache::MemCacheError
|
33
|
-
return nil
|
19
|
+
def get_session_id
|
20
|
+
session[:foo]
|
21
|
+
render :text => "#{request.session_options[:id]}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def call_reset_session
|
25
|
+
session[:bar]
|
26
|
+
reset_session
|
27
|
+
session[:bar] = "baz"
|
28
|
+
head :ok
|
34
29
|
end
|
35
|
-
|
30
|
+
|
31
|
+
def rescue_action(e) raise end
|
36
32
|
end
|
37
33
|
|
38
|
-
|
34
|
+
begin
|
35
|
+
DispatcherApp = ActionController::Dispatcher.new
|
36
|
+
MemCacheStoreApp = ActionController::Session::MemCacheStore.new(
|
37
|
+
DispatcherApp, :key => '_session_id')
|
39
38
|
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
new_session do |s|
|
44
|
-
assert_equal Hash.new, s.cache.get('session:' + s.session_id)
|
40
|
+
def setup
|
41
|
+
@integration_session = open_session(MemCacheStoreApp)
|
45
42
|
end
|
46
|
-
end
|
47
43
|
|
44
|
+
def test_setting_and_getting_session_value
|
45
|
+
with_test_route_set do
|
46
|
+
get '/set_session_value'
|
47
|
+
assert_response :success
|
48
|
+
assert cookies['_session_id']
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
session_key = 'session:' + s.session_id
|
53
|
-
unless CACHE
|
54
|
-
s.cache.expects(:get).with(session_key) \
|
55
|
-
.returns(:test => d)
|
56
|
-
s.cache.expects(:set).with(session_key,
|
57
|
-
has_entry(:test, d),
|
58
|
-
0)
|
50
|
+
get '/get_session_value'
|
51
|
+
assert_response :success
|
52
|
+
assert_equal 'foo: "bar"', response.body
|
59
53
|
end
|
60
|
-
s[:test] = d
|
61
|
-
s.close
|
62
|
-
assert_equal d, s.cache.get(session_key)[:test]
|
63
|
-
assert_equal d, s[:test]
|
64
54
|
end
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
s.cache.expects(:delete)
|
72
|
-
s.cache.expects(:get).with(session_key) \
|
73
|
-
.returns(nil)
|
55
|
+
|
56
|
+
def test_getting_nil_session_value
|
57
|
+
with_test_route_set do
|
58
|
+
get '/get_session_value'
|
59
|
+
assert_response :success
|
60
|
+
assert_equal 'foo: nil', response.body
|
74
61
|
end
|
75
|
-
s[:test] = rand(0xffff)
|
76
|
-
s.delete
|
77
|
-
assert_nil s.cache.get(session_key)
|
78
62
|
end
|
79
|
-
end
|
80
63
|
|
64
|
+
def test_setting_session_value_after_session_reset
|
65
|
+
with_test_route_set do
|
66
|
+
get '/set_session_value'
|
67
|
+
assert_response :success
|
68
|
+
assert cookies['_session_id']
|
69
|
+
session_id = cookies['_session_id']
|
81
70
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
sb.cache.expects(:[]).with('session:' + sb.session_id) \
|
94
|
-
.returns(:test => TEST_DATA)
|
95
|
-
end
|
96
|
-
assert_equal(TEST_DATA, sb[:test])
|
71
|
+
get '/call_reset_session'
|
72
|
+
assert_response :success
|
73
|
+
assert_not_equal [], headers['Set-Cookie']
|
74
|
+
|
75
|
+
get '/get_session_value'
|
76
|
+
assert_response :success
|
77
|
+
assert_equal 'foo: nil', response.body
|
78
|
+
|
79
|
+
get '/get_session_id'
|
80
|
+
assert_response :success
|
81
|
+
assert_not_equal session_id, response.body
|
97
82
|
end
|
98
83
|
end
|
99
|
-
end
|
100
84
|
|
85
|
+
def test_getting_session_id
|
86
|
+
with_test_route_set do
|
87
|
+
get '/set_session_value'
|
88
|
+
assert_response :success
|
89
|
+
assert cookies['_session_id']
|
90
|
+
session_id = cookies['_session_id']
|
101
91
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
last_data = nil
|
106
|
-
reads = writes = 0
|
107
|
-
50.times do
|
108
|
-
current = rand(10)
|
109
|
-
s_slots[current] ||= new_session('session_id' => MULTI_TEST_KEY,
|
110
|
-
'new_session' => true)
|
111
|
-
s = s_slots[current]
|
112
|
-
case operation
|
113
|
-
when :write
|
114
|
-
last_data = rand(0xffff)
|
115
|
-
unless CACHE
|
116
|
-
s.cache.expects(:set).with('session:' + MULTI_TEST_KEY,
|
117
|
-
{ :test => last_data },
|
118
|
-
0)
|
119
|
-
end
|
120
|
-
s[:test] = last_data
|
121
|
-
s.close
|
122
|
-
writes += 1
|
123
|
-
when :read
|
124
|
-
# Make CGI::Session#[] think there was no data retrieval yet.
|
125
|
-
# Normally, the session caches the data during its lifetime.
|
126
|
-
s.instance_variable_set(:@data, nil)
|
127
|
-
unless CACHE
|
128
|
-
s.cache.expects(:[]).with('session:' + MULTI_TEST_KEY) \
|
129
|
-
.returns(:test => last_data)
|
130
|
-
end
|
131
|
-
d = s[:test]
|
132
|
-
assert_equal(last_data, d, "OK reads: #{reads}, OK writes: #{writes}")
|
133
|
-
reads += 1
|
92
|
+
get '/get_session_id'
|
93
|
+
assert_response :success
|
94
|
+
assert_equal session_id, response.body
|
134
95
|
end
|
135
|
-
operation = rand(5) == 0 ? :write : :read
|
136
96
|
end
|
137
|
-
end
|
138
97
|
|
98
|
+
def test_prevents_session_fixation
|
99
|
+
with_test_route_set do
|
100
|
+
get '/get_session_value'
|
101
|
+
assert_response :success
|
102
|
+
assert_equal 'foo: nil', response.body
|
103
|
+
session_id = cookies['_session_id']
|
139
104
|
|
105
|
+
reset!
|
140
106
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
}
|
146
|
-
# if don't have running memcache server we use mock instead
|
147
|
-
unless CACHE
|
148
|
-
options['cache'] = c = mock
|
149
|
-
c.stubs(:[]).with(regexp_matches(SESSION_KEY_RE))
|
150
|
-
c.stubs(:get).with(regexp_matches(SESSION_KEY_RE)) \
|
151
|
-
.returns(Hash.new)
|
152
|
-
c.stubs(:add).with(regexp_matches(SESSION_KEY_RE),
|
153
|
-
instance_of(Hash),
|
154
|
-
0)
|
107
|
+
get '/set_session_value', :_session_id => session_id
|
108
|
+
assert_response :success
|
109
|
+
assert_equal nil, cookies['_session_id']
|
110
|
+
end
|
155
111
|
end
|
156
|
-
|
112
|
+
rescue LoadError, RuntimeError
|
113
|
+
$stderr.puts "Skipping MemCacheStoreTest tests. Start memcached and try again."
|
157
114
|
end
|
158
115
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
116
|
+
private
|
117
|
+
def with_test_route_set
|
118
|
+
with_routing do |set|
|
119
|
+
set.draw do |map|
|
120
|
+
map.with_options :controller => "mem_cache_store_test/test" do |c|
|
121
|
+
c.connect "/:action"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
yield
|
125
|
+
end
|
166
126
|
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def with_cgi
|
170
|
-
ENV['REQUEST_METHOD'] = 'GET'
|
171
|
-
ENV['HTTP_HOST'] = 'example.com'
|
172
|
-
ENV['QUERY_STRING'] = ''
|
173
|
-
|
174
|
-
cgi = CGI.new('query', StringIO.new(''))
|
175
|
-
yield cgi if block_given?
|
176
|
-
cgi
|
177
|
-
end
|
178
127
|
end
|
179
|
-
|
180
|
-
end # defined? MemCache
|
181
|
-
end # uses_mocha
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'abstract_unit'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
class ActionController::TestSessionTest < ActiveSupport::TestCase
|
5
|
+
|
6
|
+
def test_calling_delete_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session
|
7
|
+
assert_deprecated(/use clear instead/){ ActionController::TestSession.new.delete }
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_calling_update_without_parameters_raises_deprecation_warning_and_calls_to_clear_test_session
|
11
|
+
assert_deprecated(/use replace instead/){ ActionController::TestSession.new.update }
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_calling_close_raises_deprecation_warning
|
15
|
+
assert_deprecated(/sessions should no longer be closed/){ ActionController::TestSession.new.close }
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_defaults
|
19
|
+
session = ActionController::TestSession.new
|
20
|
+
assert_equal({}, session.data)
|
21
|
+
assert_equal('', session.session_id)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_ctor_allows_setting
|
25
|
+
session = ActionController::TestSession.new({:one => 'one', :two => 'two'})
|
26
|
+
assert_equal('one', session[:one])
|
27
|
+
assert_equal('two', session[:two])
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_setting_session_item_sets_item
|
31
|
+
session = ActionController::TestSession.new
|
32
|
+
session[:key] = 'value'
|
33
|
+
assert_equal('value', session[:key])
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_calling_delete_removes_item
|
37
|
+
session = ActionController::TestSession.new
|
38
|
+
session[:key] = 'value'
|
39
|
+
assert_equal('value', session[:key])
|
40
|
+
session.delete(:key)
|
41
|
+
assert_nil(session[:key])
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_calling_update_with_params_passes_to_attributes
|
45
|
+
session = ActionController::TestSession.new()
|
46
|
+
session.update('key' => 'value')
|
47
|
+
assert_equal('value', session[:key])
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_clear_emptys_session
|
51
|
+
params = {:one => 'one', :two => 'two'}
|
52
|
+
session = ActionController::TestSession.new({:one => 'one', :two => 'two'})
|
53
|
+
session.clear
|
54
|
+
assert_nil(session[:one])
|
55
|
+
assert_nil(session[:two])
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'abstract_unit'
|
2
2
|
require 'controller/fake_controllers'
|
3
3
|
|
4
|
-
class TestTest <
|
4
|
+
class TestTest < ActionController::TestCase
|
5
5
|
class TestController < ActionController::Base
|
6
6
|
def no_op
|
7
7
|
render :text => 'dummy'
|
@@ -23,8 +23,13 @@ class TestTest < Test::Unit::TestCase
|
|
23
23
|
render :text => 'Success'
|
24
24
|
end
|
25
25
|
|
26
|
+
def reset_the_session
|
27
|
+
reset_session
|
28
|
+
render :text => 'ignore me'
|
29
|
+
end
|
30
|
+
|
26
31
|
def render_raw_post
|
27
|
-
raise
|
32
|
+
raise ActiveSupport::TestCase::Assertion, "#raw_post is blank" if request.raw_post.blank?
|
28
33
|
render :text => request.raw_post
|
29
34
|
end
|
30
35
|
|
@@ -171,6 +176,24 @@ XML
|
|
171
176
|
assert_equal 'value2', session[:symbol]
|
172
177
|
end
|
173
178
|
|
179
|
+
def test_session_is_cleared_from_controller_after_reset_session
|
180
|
+
process :set_session
|
181
|
+
process :reset_the_session
|
182
|
+
assert_equal Hash.new, @controller.session.to_hash
|
183
|
+
end
|
184
|
+
|
185
|
+
def test_session_is_cleared_from_response_after_reset_session
|
186
|
+
process :set_session
|
187
|
+
process :reset_the_session
|
188
|
+
assert_equal Hash.new, @response.session.to_hash
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_session_is_cleared_from_request_after_reset_session
|
192
|
+
process :set_session
|
193
|
+
process :reset_the_session
|
194
|
+
assert_equal Hash.new, @request.session.to_hash
|
195
|
+
end
|
196
|
+
|
174
197
|
def test_process_with_request_uri_with_no_params
|
175
198
|
process :test_uri
|
176
199
|
assert_equal "/test_test/test/test_uri", @response.body
|
@@ -580,7 +603,7 @@ XML
|
|
580
603
|
assert_equal @response.redirect_url, redirect_to_url
|
581
604
|
|
582
605
|
# Must be a :redirect response.
|
583
|
-
assert_raise(
|
606
|
+
assert_raise(ActiveSupport::TestCase::Assertion) do
|
584
607
|
assert_redirected_to 'created resource'
|
585
608
|
end
|
586
609
|
end
|
@@ -602,9 +625,9 @@ XML
|
|
602
625
|
end
|
603
626
|
end
|
604
627
|
|
605
|
-
class CleanBacktraceTest <
|
628
|
+
class CleanBacktraceTest < ActionController::TestCase
|
606
629
|
def test_should_reraise_the_same_object
|
607
|
-
exception =
|
630
|
+
exception = ActiveSupport::TestCase::Assertion.new('message')
|
608
631
|
clean_backtrace { raise exception }
|
609
632
|
rescue Exception => caught
|
610
633
|
assert_equal exception.object_id, caught.object_id
|
@@ -613,7 +636,7 @@ class CleanBacktraceTest < Test::Unit::TestCase
|
|
613
636
|
|
614
637
|
def test_should_clean_assertion_lines_from_backtrace
|
615
638
|
path = File.expand_path("#{File.dirname(__FILE__)}/../../lib/action_controller")
|
616
|
-
exception =
|
639
|
+
exception = ActiveSupport::TestCase::Assertion.new('message')
|
617
640
|
exception.set_backtrace ["#{path}/abc", "#{path}/assertions/def"]
|
618
641
|
clean_backtrace { raise exception }
|
619
642
|
rescue Exception => caught
|
@@ -629,21 +652,17 @@ class CleanBacktraceTest < Test::Unit::TestCase
|
|
629
652
|
end
|
630
653
|
end
|
631
654
|
|
632
|
-
class InferringClassNameTest <
|
655
|
+
class InferringClassNameTest < ActionController::TestCase
|
633
656
|
def test_determine_controller_class
|
634
657
|
assert_equal ContentController, determine_class("ContentControllerTest")
|
635
658
|
end
|
636
659
|
|
637
660
|
def test_determine_controller_class_with_nonsense_name
|
638
|
-
|
639
|
-
determine_class("HelloGoodBye")
|
640
|
-
end
|
661
|
+
assert_nil determine_class("HelloGoodBye")
|
641
662
|
end
|
642
663
|
|
643
664
|
def test_determine_controller_class_with_sensible_name_where_no_controller_exists
|
644
|
-
|
645
|
-
determine_class("NoControllerWithThisNameTest")
|
646
|
-
end
|
665
|
+
assert_nil determine_class("NoControllerWithThisNameTest")
|
647
666
|
end
|
648
667
|
|
649
668
|
private
|
@@ -2,7 +2,7 @@ require 'abstract_unit'
|
|
2
2
|
|
3
3
|
ActionController::UrlRewriter
|
4
4
|
|
5
|
-
class UrlRewriterTests <
|
5
|
+
class UrlRewriterTests < ActionController::TestCase
|
6
6
|
def setup
|
7
7
|
@request = ActionController::TestRequest.new
|
8
8
|
@params = {}
|
@@ -85,8 +85,7 @@ class UrlRewriterTests < Test::Unit::TestCase
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
class UrlWriterTests <
|
89
|
-
|
88
|
+
class UrlWriterTests < ActionController::TestCase
|
90
89
|
class W
|
91
90
|
include ActionController::UrlWriter
|
92
91
|
end
|
@@ -100,7 +99,7 @@ class UrlWriterTests < Test::Unit::TestCase
|
|
100
99
|
end
|
101
100
|
|
102
101
|
def test_exception_is_thrown_without_host
|
103
|
-
|
102
|
+
assert_raise RuntimeError do
|
104
103
|
W.new.url_for :controller => 'c', :action => 'a', :id => 'i'
|
105
104
|
end
|
106
105
|
end
|
@@ -302,6 +301,57 @@ class UrlWriterTests < Test::Unit::TestCase
|
|
302
301
|
assert_generates("/image", :controller=> :image)
|
303
302
|
end
|
304
303
|
|
304
|
+
def test_named_routes_with_nil_keys
|
305
|
+
ActionController::Routing::Routes.clear!
|
306
|
+
ActionController::Routing::Routes.draw do |map|
|
307
|
+
map.main '', :controller => 'posts'
|
308
|
+
map.resources :posts
|
309
|
+
map.connect ':controller/:action/:id'
|
310
|
+
end
|
311
|
+
# We need to create a new class in order to install the new named route.
|
312
|
+
kls = Class.new { include ActionController::UrlWriter }
|
313
|
+
kls.default_url_options[:host] = 'www.basecamphq.com'
|
314
|
+
|
315
|
+
controller = kls.new
|
316
|
+
params = {:action => :index, :controller => :posts, :format => :xml}
|
317
|
+
assert_equal("http://www.basecamphq.com/posts.xml", controller.send(:url_for, params))
|
318
|
+
params[:format] = nil
|
319
|
+
assert_equal("http://www.basecamphq.com/", controller.send(:url_for, params))
|
320
|
+
ensure
|
321
|
+
ActionController::Routing::Routes.load!
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_formatted_url_methods_are_deprecated
|
325
|
+
ActionController::Routing::Routes.draw do |map|
|
326
|
+
map.resources :posts
|
327
|
+
end
|
328
|
+
# We need to create a new class in order to install the new named route.
|
329
|
+
kls = Class.new { include ActionController::UrlWriter }
|
330
|
+
controller = kls.new
|
331
|
+
params = {:id => 1, :format => :xml}
|
332
|
+
assert_deprecated do
|
333
|
+
assert_equal("/posts/1.xml", controller.send(:formatted_post_path, params))
|
334
|
+
end
|
335
|
+
assert_deprecated do
|
336
|
+
assert_equal("/posts/1.xml", controller.send(:formatted_post_path, 1, :xml))
|
337
|
+
end
|
338
|
+
ensure
|
339
|
+
ActionController::Routing::Routes.load!
|
340
|
+
end
|
341
|
+
|
342
|
+
def test_multiple_includes_maintain_distinct_options
|
343
|
+
first_class = Class.new { include ActionController::UrlWriter }
|
344
|
+
second_class = Class.new { include ActionController::UrlWriter }
|
345
|
+
|
346
|
+
first_host, second_host = 'firsthost.com', 'secondhost.com'
|
347
|
+
|
348
|
+
first_class.default_url_options[:host] = first_host
|
349
|
+
second_class.default_url_options[:host] = second_host
|
350
|
+
|
351
|
+
assert_equal first_class.default_url_options[:host], first_host
|
352
|
+
assert_equal second_class.default_url_options[:host], second_host
|
353
|
+
end
|
354
|
+
|
305
355
|
private
|
306
356
|
def extract_params(url)
|
307
357
|
url.split('?', 2).last.split('&')
|