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
@@ -20,7 +20,11 @@ module ActionView
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def clean_backtrace
|
23
|
-
|
23
|
+
if defined?(Rails) && Rails.respond_to?(:backtrace_cleaner)
|
24
|
+
Rails.backtrace_cleaner.clean(original_exception.backtrace)
|
25
|
+
else
|
26
|
+
original_exception.backtrace
|
27
|
+
end
|
24
28
|
end
|
25
29
|
|
26
30
|
def sub_template_message
|
@@ -66,8 +70,8 @@ module ActionView
|
|
66
70
|
end
|
67
71
|
|
68
72
|
def to_s
|
69
|
-
"\n
|
70
|
-
|
73
|
+
"\n#{self.class} (#{message}) #{source_location}:\n" +
|
74
|
+
"#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n"
|
71
75
|
end
|
72
76
|
|
73
77
|
# don't do anything nontrivial here. Any raised exception from here becomes fatal
|
@@ -92,9 +96,4 @@ module ActionView
|
|
92
96
|
end + file_name
|
93
97
|
end
|
94
98
|
end
|
95
|
-
end
|
96
|
-
|
97
|
-
if defined?(Exception::TraceSubstitutions)
|
98
|
-
Exception::TraceSubstitutions << [/:in\s+`_run_.*'\s*$/, '']
|
99
|
-
Exception::TraceSubstitutions << [%r{^\s*#{Regexp.escape RAILS_ROOT}/}, ''] if defined?(RAILS_ROOT)
|
100
|
-
end
|
99
|
+
end
|
@@ -1,10 +1,9 @@
|
|
1
|
-
require 'action_view/template_handler'
|
2
|
-
require 'action_view/template_handlers/builder'
|
3
|
-
require 'action_view/template_handlers/erb'
|
4
|
-
require 'action_view/template_handlers/rjs'
|
5
|
-
|
6
1
|
module ActionView #:nodoc:
|
7
2
|
module TemplateHandlers #:nodoc:
|
3
|
+
autoload :ERB, 'action_view/template_handlers/erb'
|
4
|
+
autoload :RJS, 'action_view/template_handlers/rjs'
|
5
|
+
autoload :Builder, 'action_view/template_handlers/builder'
|
6
|
+
|
8
7
|
def self.extended(base)
|
9
8
|
base.register_default_template_handler :erb, TemplateHandlers::ERB
|
10
9
|
base.register_template_handler :rjs, TemplateHandlers::RJS
|
@@ -33,13 +32,17 @@ module ActionView #:nodoc:
|
|
33
32
|
@@template_handlers.keys.map(&:to_s).sort
|
34
33
|
end
|
35
34
|
|
35
|
+
def registered_template_handler(extension)
|
36
|
+
extension && @@template_handlers[extension.to_sym]
|
37
|
+
end
|
38
|
+
|
36
39
|
def register_default_template_handler(extension, klass)
|
37
40
|
register_template_handler(extension, klass)
|
38
41
|
@@default_template_handlers = klass
|
39
42
|
end
|
40
43
|
|
41
44
|
def handler_class_for_extension(extension)
|
42
|
-
(extension
|
45
|
+
registered_template_handler(extension) || @@default_template_handlers
|
43
46
|
end
|
44
47
|
end
|
45
48
|
end
|
@@ -1,47 +1,10 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
class ERB
|
4
|
-
module Util
|
5
|
-
HTML_ESCAPE = { '&' => '&', '>' => '>', '<' => '<', '"' => '"' }
|
6
|
-
JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' }
|
7
|
-
|
8
|
-
# A utility method for escaping HTML tag characters.
|
9
|
-
# This method is also aliased as <tt>h</tt>.
|
10
|
-
#
|
11
|
-
# In your ERb templates, use this method to escape any unsafe content. For example:
|
12
|
-
# <%=h @person.name %>
|
13
|
-
#
|
14
|
-
# ==== Example:
|
15
|
-
# puts html_escape("is a > 0 & a < 10?")
|
16
|
-
# # => is a > 0 & a < 10?
|
17
|
-
def html_escape(s)
|
18
|
-
s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] }
|
19
|
-
end
|
20
|
-
|
21
|
-
# A utility method for escaping HTML entities in JSON strings.
|
22
|
-
# This method is also aliased as <tt>j</tt>.
|
23
|
-
#
|
24
|
-
# In your ERb templates, use this method to escape any HTML entities:
|
25
|
-
# <%=j @person.to_json %>
|
26
|
-
#
|
27
|
-
# ==== Example:
|
28
|
-
# puts json_escape("is a > 0 & a < 10?")
|
29
|
-
# # => is a \u003E 0 \u0026 a \u003C 10?
|
30
|
-
def json_escape(s)
|
31
|
-
s.to_s.gsub(/[&"><]/) { |special| JSON_ESCAPE[special] }
|
32
|
-
end
|
33
|
-
|
34
|
-
alias j json_escape
|
35
|
-
module_function :j
|
36
|
-
module_function :json_escape
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
1
|
module ActionView
|
41
2
|
module TemplateHandlers
|
42
3
|
class ERB < TemplateHandler
|
43
4
|
include Compilable
|
44
5
|
|
6
|
+
##
|
7
|
+
# :singleton-method:
|
45
8
|
# Specify trim mode for the ERB compiler. Defaults to '-'.
|
46
9
|
# See ERb documentation for suitable values.
|
47
10
|
cattr_accessor :erb_trim_mode
|
@@ -1,7 +1,30 @@
|
|
1
1
|
require 'active_support/test_case'
|
2
2
|
|
3
3
|
module ActionView
|
4
|
+
class Base
|
5
|
+
alias_method :initialize_without_template_tracking, :initialize
|
6
|
+
def initialize(*args)
|
7
|
+
@_rendered = { :template => nil, :partials => Hash.new(0) }
|
8
|
+
initialize_without_template_tracking(*args)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module Renderable
|
13
|
+
alias_method :render_without_template_tracking, :render
|
14
|
+
def render(view, local_assigns = {})
|
15
|
+
if respond_to?(:path) && !is_a?(InlineTemplate)
|
16
|
+
rendered = view.instance_variable_get(:@_rendered)
|
17
|
+
rendered[:partials][self] += 1 if is_a?(RenderablePartial)
|
18
|
+
rendered[:template] ||= self
|
19
|
+
end
|
20
|
+
render_without_template_tracking(view, local_assigns)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
4
24
|
class TestCase < ActiveSupport::TestCase
|
25
|
+
include ActionController::TestCase::Assertions
|
26
|
+
include ActionController::TestProcess
|
27
|
+
|
5
28
|
class_inheritable_accessor :helper_class
|
6
29
|
@@helper_class = nil
|
7
30
|
|
@@ -40,11 +63,14 @@ module ActionView
|
|
40
63
|
end
|
41
64
|
|
42
65
|
class TestController < ActionController::Base
|
43
|
-
attr_accessor :request, :response
|
66
|
+
attr_accessor :request, :response, :params
|
44
67
|
|
45
68
|
def initialize
|
46
69
|
@request = ActionController::TestRequest.new
|
47
70
|
@response = ActionController::TestResponse.new
|
71
|
+
|
72
|
+
@params = {}
|
73
|
+
send(:initialize_current_url)
|
48
74
|
end
|
49
75
|
end
|
50
76
|
|
data/test/abstract_unit.rb
CHANGED
@@ -1,39 +1,45 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
2
2
|
$:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
|
3
3
|
$:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
|
4
|
+
$:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers')
|
4
5
|
|
6
|
+
require 'rubygems'
|
5
7
|
require 'yaml'
|
6
8
|
require 'stringio'
|
7
9
|
require 'test/unit'
|
8
|
-
|
9
|
-
|
10
|
-
require '
|
11
|
-
require 'action_view/test_case'
|
10
|
+
|
11
|
+
gem 'mocha', '>= 0.9.5'
|
12
|
+
require 'mocha'
|
12
13
|
|
13
14
|
begin
|
14
15
|
require 'ruby-debug'
|
16
|
+
Debugger.settings[:autoeval] = true
|
17
|
+
Debugger.start
|
15
18
|
rescue LoadError
|
16
19
|
# Debugging disabled. `gem install ruby-debug` to enable.
|
17
20
|
end
|
18
21
|
|
22
|
+
require 'action_controller'
|
23
|
+
require 'action_controller/cgi_ext'
|
24
|
+
require 'action_controller/test_process'
|
25
|
+
require 'action_view/test_case'
|
26
|
+
|
19
27
|
# Show backtraces for deprecated behavior for quicker cleanup.
|
20
28
|
ActiveSupport::Deprecation.debug = true
|
21
29
|
|
22
30
|
ActionController::Base.logger = nil
|
23
31
|
ActionController::Routing::Routes.reload rescue nil
|
24
32
|
|
33
|
+
ActionController::Base.session_store = nil
|
34
|
+
|
35
|
+
# Register danish language for testing
|
36
|
+
I18n.backend.store_translations 'da', {}
|
37
|
+
I18n.backend.store_translations 'pt-BR', {}
|
38
|
+
ORIGINAL_LOCALES = I18n.available_locales.map(&:to_s).sort
|
39
|
+
|
25
40
|
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
|
26
|
-
ActionView::
|
41
|
+
ActionView::Base.cache_template_loading = true
|
27
42
|
ActionController::Base.view_paths = FIXTURE_LOAD_PATH
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
unless Object.const_defined?(:Mocha)
|
32
|
-
require 'mocha'
|
33
|
-
require 'stubba'
|
34
|
-
end
|
35
|
-
yield
|
36
|
-
rescue LoadError => load_error
|
37
|
-
raise unless load_error.message =~ /mocha/i
|
38
|
-
$stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again."
|
39
|
-
end
|
43
|
+
CACHED_VIEW_PATHS = ActionView::Base.cache_template_loading? ?
|
44
|
+
ActionController::Base.view_paths :
|
45
|
+
ActionController::Base.view_paths.map {|path| ActionView::Template::EagerPath.new(path.to_s)}
|
data/test/active_record_unit.rb
CHANGED
@@ -51,7 +51,8 @@ class ActiveRecordTestConnector
|
|
51
51
|
if Object.const_defined?(:ActiveRecord)
|
52
52
|
defaults = { :database => ':memory:' }
|
53
53
|
begin
|
54
|
-
|
54
|
+
adapter = defined?(JRUBY_VERSION) ? 'jdbcsqlite3' : 'sqlite3'
|
55
|
+
options = defaults.merge :adapter => adapter, :timeout => 500
|
55
56
|
ActiveRecord::Base.establish_connection(options)
|
56
57
|
ActiveRecord::Base.configurations = { 'sqlite3_ar_integration' => options }
|
57
58
|
ActiveRecord::Base.connection
|
@@ -82,7 +83,9 @@ class ActiveRecordTestConnector
|
|
82
83
|
end
|
83
84
|
end
|
84
85
|
|
85
|
-
class ActiveRecordTestCase <
|
86
|
+
class ActiveRecordTestCase < ActionController::TestCase
|
87
|
+
include ActiveRecord::TestFixtures
|
88
|
+
|
86
89
|
# Set our fixture path
|
87
90
|
if ActiveRecordTestConnector.able_to_connect
|
88
91
|
self.fixture_path = [FIXTURE_LOAD_PATH]
|
@@ -96,8 +99,6 @@ class ActiveRecordTestCase < ActiveSupport::TestCase
|
|
96
99
|
def run(*args)
|
97
100
|
super if ActiveRecordTestConnector.connected
|
98
101
|
end
|
99
|
-
|
100
|
-
def default_test; end
|
101
102
|
end
|
102
103
|
|
103
104
|
ActiveRecordTestConnector.setup
|
@@ -1,141 +1,174 @@
|
|
1
|
-
# These tests exercise CGI::Session::ActiveRecordStore, so you're going to
|
2
|
-
# need AR in a sibling directory to AP and have SQLite installed.
|
3
1
|
require 'active_record_unit'
|
4
|
-
require 'action_controller/session/active_record_store'
|
5
|
-
|
6
|
-
module CommonActiveRecordStoreTests
|
7
|
-
def test_basics
|
8
|
-
s = session_class.new(:session_id => '1234', :data => { 'foo' => 'bar' })
|
9
|
-
assert_equal 'bar', s.data['foo']
|
10
|
-
assert s.save
|
11
|
-
assert_equal 'bar', s.data['foo']
|
12
|
-
|
13
|
-
assert_not_nil t = session_class.find_by_session_id('1234')
|
14
|
-
assert_not_nil t.data
|
15
|
-
assert_equal 'bar', t.data['foo']
|
16
|
-
end
|
17
2
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
3
|
+
class ActiveRecordStoreTest < ActionController::IntegrationTest
|
4
|
+
DispatcherApp = ActionController::Dispatcher.new
|
5
|
+
SessionApp = ActiveRecord::SessionStore.new(DispatcherApp,
|
6
|
+
:key => '_session_id')
|
7
|
+
SessionAppWithFixation = ActiveRecord::SessionStore.new(DispatcherApp,
|
8
|
+
:key => '_session_id', :cookie_only => false)
|
23
9
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@new_session.close
|
10
|
+
class TestController < ActionController::Base
|
11
|
+
def no_session_access
|
12
|
+
head :ok
|
28
13
|
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
class ActiveRecordStoreTest < ActiveRecordTestCase
|
33
|
-
include CommonActiveRecordStoreTests
|
34
14
|
|
35
|
-
|
36
|
-
|
37
|
-
|
15
|
+
def set_session_value
|
16
|
+
session[:foo] = params[:foo] || "bar"
|
17
|
+
head :ok
|
18
|
+
end
|
38
19
|
|
39
|
-
|
40
|
-
|
41
|
-
|
20
|
+
def get_session_value
|
21
|
+
render :text => "foo: #{session[:foo].inspect}"
|
22
|
+
end
|
42
23
|
|
43
|
-
|
44
|
-
|
24
|
+
def get_session_id
|
25
|
+
session[:foo]
|
26
|
+
render :text => "#{request.session_options[:id]}"
|
27
|
+
end
|
45
28
|
|
46
|
-
|
47
|
-
|
48
|
-
|
29
|
+
def call_reset_session
|
30
|
+
session[:bar]
|
31
|
+
reset_session
|
32
|
+
session[:bar] = "baz"
|
33
|
+
head :ok
|
34
|
+
end
|
49
35
|
|
50
|
-
|
51
|
-
@new_session = CGI::Session.new(@cgi, 'database_manager' => CGI::Session::ActiveRecordStore, 'new_session' => true)
|
52
|
-
@new_session['foo'] = 'bar'
|
36
|
+
def rescue_action(e) raise end
|
53
37
|
end
|
54
38
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
# end
|
39
|
+
def setup
|
40
|
+
ActiveRecord::SessionStore.session_class.create_table!
|
41
|
+
@integration_session = open_session(SessionApp)
|
42
|
+
end
|
60
43
|
|
61
|
-
def
|
62
|
-
|
63
|
-
assert_equal({ 'foo' => 'bar' }, @new_session.model.data)
|
44
|
+
def teardown
|
45
|
+
ActiveRecord::SessionStore.session_class.drop_table!
|
64
46
|
end
|
65
47
|
|
66
|
-
def
|
67
|
-
|
68
|
-
|
69
|
-
|
48
|
+
def test_setting_and_getting_session_value
|
49
|
+
with_test_route_set do
|
50
|
+
get '/set_session_value'
|
51
|
+
assert_response :success
|
52
|
+
assert cookies['_session_id']
|
70
53
|
|
71
|
-
|
72
|
-
|
73
|
-
|
54
|
+
get '/get_session_value'
|
55
|
+
assert_response :success
|
56
|
+
assert_equal 'foo: "bar"', response.body
|
74
57
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
58
|
+
get '/set_session_value', :foo => "baz"
|
59
|
+
assert_response :success
|
60
|
+
assert cookies['_session_id']
|
79
61
|
|
80
|
-
|
81
|
-
|
62
|
+
get '/get_session_value'
|
63
|
+
assert_response :success
|
64
|
+
assert_equal 'foo: "baz"', response.body
|
65
|
+
end
|
82
66
|
end
|
83
|
-
end
|
84
67
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
68
|
+
def test_getting_nil_session_value
|
69
|
+
with_test_route_set do
|
70
|
+
get '/get_session_value'
|
71
|
+
assert_response :success
|
72
|
+
assert_equal 'foo: nil', response.body
|
73
|
+
end
|
89
74
|
end
|
90
75
|
|
91
|
-
def
|
92
|
-
|
93
|
-
|
76
|
+
def test_setting_session_value_after_session_reset
|
77
|
+
with_test_route_set do
|
78
|
+
get '/set_session_value'
|
79
|
+
assert_response :success
|
80
|
+
assert cookies['_session_id']
|
81
|
+
session_id = cookies['_session_id']
|
82
|
+
|
83
|
+
get '/call_reset_session'
|
84
|
+
assert_response :success
|
85
|
+
assert_not_equal [], headers['Set-Cookie']
|
94
86
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
87
|
+
get '/get_session_value'
|
88
|
+
assert_response :success
|
89
|
+
assert_equal 'foo: nil', response.body
|
90
|
+
|
91
|
+
get '/get_session_id'
|
92
|
+
assert_response :success
|
93
|
+
assert_not_equal session_id, response.body
|
94
|
+
end
|
102
95
|
end
|
103
|
-
end
|
104
96
|
|
105
|
-
|
106
|
-
|
107
|
-
|
97
|
+
def test_getting_session_id
|
98
|
+
with_test_route_set do
|
99
|
+
get '/set_session_value'
|
100
|
+
assert_response :success
|
101
|
+
assert cookies['_session_id']
|
102
|
+
session_id = cookies['_session_id']
|
103
|
+
|
104
|
+
get '/get_session_id'
|
105
|
+
assert_response :success
|
106
|
+
assert_equal session_id, response.body
|
107
|
+
end
|
108
108
|
end
|
109
109
|
|
110
|
-
def
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
def test_prevents_session_fixation
|
111
|
+
with_test_route_set do
|
112
|
+
get '/set_session_value'
|
113
|
+
assert_response :success
|
114
|
+
assert cookies['_session_id']
|
114
115
|
|
115
|
-
|
116
|
-
|
116
|
+
get '/get_session_value'
|
117
|
+
assert_response :success
|
118
|
+
assert_equal 'foo: "bar"', response.body
|
119
|
+
session_id = cookies['_session_id']
|
120
|
+
assert session_id
|
117
121
|
|
118
|
-
|
119
|
-
@new_session['foo'] = 'bar'
|
120
|
-
end
|
122
|
+
reset!
|
121
123
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
end
|
126
|
-
end
|
124
|
+
get '/set_session_value', :_session_id => session_id, :foo => "baz"
|
125
|
+
assert_response :success
|
126
|
+
assert_equal nil, cookies['_session_id']
|
127
127
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
@session_class.connection = CGI::Session::ActiveRecordStore::Session.connection
|
128
|
+
get '/get_session_value', :_session_id => session_id
|
129
|
+
assert_response :success
|
130
|
+
assert_equal 'foo: nil', response.body
|
131
|
+
assert_equal nil, cookies['_session_id']
|
133
132
|
end
|
134
|
-
@session_class
|
135
133
|
end
|
136
134
|
|
137
|
-
def
|
138
|
-
|
139
|
-
|
135
|
+
def test_allows_session_fixation
|
136
|
+
@integration_session = open_session(SessionAppWithFixation)
|
137
|
+
|
138
|
+
with_test_route_set do
|
139
|
+
get '/set_session_value'
|
140
|
+
assert_response :success
|
141
|
+
assert cookies['_session_id']
|
142
|
+
|
143
|
+
get '/get_session_value'
|
144
|
+
assert_response :success
|
145
|
+
assert_equal 'foo: "bar"', response.body
|
146
|
+
session_id = cookies['_session_id']
|
147
|
+
assert session_id
|
148
|
+
|
149
|
+
reset!
|
150
|
+
@integration_session = open_session(SessionAppWithFixation)
|
151
|
+
|
152
|
+
get '/set_session_value', :_session_id => session_id, :foo => "baz"
|
153
|
+
assert_response :success
|
154
|
+
assert_equal session_id, cookies['_session_id']
|
155
|
+
|
156
|
+
get '/get_session_value', :_session_id => session_id
|
157
|
+
assert_response :success
|
158
|
+
assert_equal 'foo: "baz"', response.body
|
159
|
+
assert_equal session_id, cookies['_session_id']
|
160
|
+
end
|
140
161
|
end
|
162
|
+
|
163
|
+
private
|
164
|
+
def with_test_route_set
|
165
|
+
with_routing do |set|
|
166
|
+
set.draw do |map|
|
167
|
+
map.with_options :controller => "active_record_store_test/test" do |c|
|
168
|
+
c.connect "/:action"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
yield
|
172
|
+
end
|
173
|
+
end
|
141
174
|
end
|