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.

Files changed (264) hide show
  1. data/CHANGELOG +433 -375
  2. data/MIT-LICENSE +1 -1
  3. data/README +21 -75
  4. data/Rakefile +1 -1
  5. data/lib/action_controller.rb +80 -43
  6. data/lib/action_controller/assertions/model_assertions.rb +1 -0
  7. data/lib/action_controller/assertions/response_assertions.rb +43 -16
  8. data/lib/action_controller/assertions/routing_assertions.rb +1 -1
  9. data/lib/action_controller/assertions/selector_assertions.rb +17 -12
  10. data/lib/action_controller/assertions/tag_assertions.rb +1 -4
  11. data/lib/action_controller/base.rb +153 -82
  12. data/lib/action_controller/benchmarking.rb +9 -9
  13. data/lib/action_controller/caching.rb +9 -11
  14. data/lib/action_controller/caching/actions.rb +11 -18
  15. data/lib/action_controller/caching/fragments.rb +28 -20
  16. data/lib/action_controller/caching/pages.rb +13 -15
  17. data/lib/action_controller/caching/sweeping.rb +2 -2
  18. data/lib/action_controller/cgi_ext.rb +0 -1
  19. data/lib/action_controller/cgi_ext/cookie.rb +2 -0
  20. data/lib/action_controller/cgi_process.rb +54 -162
  21. data/lib/action_controller/cookies.rb +13 -25
  22. data/lib/action_controller/dispatcher.rb +43 -122
  23. data/lib/action_controller/failsafe.rb +52 -0
  24. data/lib/action_controller/flash.rb +38 -47
  25. data/lib/action_controller/helpers.rb +13 -9
  26. data/lib/action_controller/http_authentication.rb +203 -23
  27. data/lib/action_controller/integration.rb +126 -70
  28. data/lib/action_controller/layout.rb +36 -39
  29. data/lib/action_controller/middleware_stack.rb +119 -0
  30. data/lib/action_controller/middlewares.rb +13 -0
  31. data/lib/action_controller/mime_responds.rb +19 -4
  32. data/lib/action_controller/mime_type.rb +8 -0
  33. data/lib/action_controller/params_parser.rb +71 -0
  34. data/lib/action_controller/performance_test.rb +0 -1
  35. data/lib/action_controller/polymorphic_routes.rb +36 -30
  36. data/lib/action_controller/reloader.rb +14 -0
  37. data/lib/action_controller/request.rb +107 -499
  38. data/lib/action_controller/request_forgery_protection.rb +7 -39
  39. data/lib/action_controller/rescue.rb +55 -35
  40. data/lib/action_controller/resources.rb +34 -31
  41. data/lib/action_controller/response.rb +99 -57
  42. data/lib/action_controller/rewindable_input.rb +28 -0
  43. data/lib/action_controller/routing.rb +7 -7
  44. data/lib/action_controller/routing/builder.rb +4 -1
  45. data/lib/action_controller/routing/optimisations.rb +1 -1
  46. data/lib/action_controller/routing/recognition_optimisation.rb +1 -2
  47. data/lib/action_controller/routing/route.rb +15 -5
  48. data/lib/action_controller/routing/route_set.rb +82 -35
  49. data/lib/action_controller/routing/segments.rb +35 -0
  50. data/lib/action_controller/session/abstract_store.rb +181 -0
  51. data/lib/action_controller/session/cookie_store.rb +197 -175
  52. data/lib/action_controller/session/mem_cache_store.rb +36 -83
  53. data/lib/action_controller/session_management.rb +26 -134
  54. data/lib/action_controller/streaming.rb +24 -7
  55. data/lib/action_controller/templates/rescues/diagnostics.erb +2 -2
  56. data/lib/action_controller/templates/rescues/template_error.erb +2 -2
  57. data/lib/action_controller/test_case.rb +87 -30
  58. data/lib/action_controller/test_process.rb +145 -104
  59. data/lib/action_controller/uploaded_file.rb +44 -0
  60. data/lib/action_controller/url_rewriter.rb +3 -6
  61. data/lib/action_controller/vendor/html-scanner.rb +16 -0
  62. data/lib/action_controller/vendor/html-scanner/html/selector.rb +1 -1
  63. data/lib/action_controller/vendor/rack-1.0/rack.rb +89 -0
  64. data/lib/action_controller/vendor/rack-1.0/rack/adapter/camping.rb +22 -0
  65. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/handler.rb +37 -0
  66. data/lib/action_controller/vendor/rack-1.0/rack/auth/abstract/request.rb +37 -0
  67. data/lib/action_controller/vendor/rack-1.0/rack/auth/basic.rb +58 -0
  68. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/md5.rb +124 -0
  69. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/nonce.rb +51 -0
  70. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/params.rb +55 -0
  71. data/lib/action_controller/vendor/rack-1.0/rack/auth/digest/request.rb +40 -0
  72. data/lib/action_controller/vendor/rack-1.0/rack/auth/openid.rb +480 -0
  73. data/lib/action_controller/vendor/rack-1.0/rack/builder.rb +63 -0
  74. data/lib/action_controller/vendor/rack-1.0/rack/cascade.rb +36 -0
  75. data/lib/action_controller/vendor/rack-1.0/rack/chunked.rb +49 -0
  76. data/lib/action_controller/vendor/rack-1.0/rack/commonlogger.rb +61 -0
  77. data/lib/action_controller/vendor/rack-1.0/rack/conditionalget.rb +45 -0
  78. data/lib/action_controller/vendor/rack-1.0/rack/content_length.rb +29 -0
  79. data/lib/action_controller/vendor/rack-1.0/rack/content_type.rb +23 -0
  80. data/lib/action_controller/vendor/rack-1.0/rack/deflater.rb +85 -0
  81. data/lib/action_controller/vendor/rack-1.0/rack/directory.rb +153 -0
  82. data/lib/action_controller/vendor/rack-1.0/rack/file.rb +88 -0
  83. data/lib/action_controller/vendor/rack-1.0/rack/handler.rb +48 -0
  84. data/lib/action_controller/vendor/rack-1.0/rack/handler/cgi.rb +61 -0
  85. data/lib/action_controller/vendor/rack-1.0/rack/handler/evented_mongrel.rb +8 -0
  86. data/lib/action_controller/vendor/rack-1.0/rack/handler/fastcgi.rb +89 -0
  87. data/lib/action_controller/vendor/rack-1.0/rack/handler/lsws.rb +55 -0
  88. data/lib/action_controller/vendor/rack-1.0/rack/handler/mongrel.rb +84 -0
  89. data/lib/action_controller/vendor/rack-1.0/rack/handler/scgi.rb +59 -0
  90. data/lib/action_controller/vendor/rack-1.0/rack/handler/swiftiplied_mongrel.rb +8 -0
  91. data/lib/action_controller/vendor/rack-1.0/rack/handler/thin.rb +18 -0
  92. data/lib/action_controller/vendor/rack-1.0/rack/handler/webrick.rb +67 -0
  93. data/lib/action_controller/vendor/rack-1.0/rack/head.rb +19 -0
  94. data/lib/action_controller/vendor/rack-1.0/rack/lint.rb +462 -0
  95. data/lib/action_controller/vendor/rack-1.0/rack/lobster.rb +65 -0
  96. data/lib/action_controller/vendor/rack-1.0/rack/lock.rb +16 -0
  97. data/lib/action_controller/vendor/rack-1.0/rack/methodoverride.rb +27 -0
  98. data/lib/action_controller/vendor/rack-1.0/rack/mime.rb +204 -0
  99. data/lib/action_controller/vendor/rack-1.0/rack/mock.rb +160 -0
  100. data/lib/action_controller/vendor/rack-1.0/rack/recursive.rb +57 -0
  101. data/lib/action_controller/vendor/rack-1.0/rack/reloader.rb +64 -0
  102. data/lib/action_controller/vendor/rack-1.0/rack/request.rb +241 -0
  103. data/lib/action_controller/vendor/rack-1.0/rack/response.rb +179 -0
  104. data/lib/action_controller/vendor/rack-1.0/rack/session/abstract/id.rb +142 -0
  105. data/lib/action_controller/vendor/rack-1.0/rack/session/cookie.rb +91 -0
  106. data/lib/action_controller/vendor/rack-1.0/rack/session/memcache.rb +109 -0
  107. data/lib/action_controller/vendor/rack-1.0/rack/session/pool.rb +100 -0
  108. data/lib/action_controller/vendor/rack-1.0/rack/showexceptions.rb +349 -0
  109. data/lib/action_controller/vendor/rack-1.0/rack/showstatus.rb +106 -0
  110. data/lib/action_controller/vendor/rack-1.0/rack/static.rb +38 -0
  111. data/lib/action_controller/vendor/rack-1.0/rack/urlmap.rb +55 -0
  112. data/lib/action_controller/vendor/rack-1.0/rack/utils.rb +392 -0
  113. data/lib/action_controller/verification.rb +1 -1
  114. data/lib/action_pack.rb +1 -1
  115. data/lib/action_pack/version.rb +2 -2
  116. data/lib/action_view.rb +22 -17
  117. data/lib/action_view/base.rb +53 -79
  118. data/lib/action_view/erb/util.rb +38 -0
  119. data/lib/action_view/helpers.rb +24 -5
  120. data/lib/action_view/helpers/active_record_helper.rb +2 -2
  121. data/lib/action_view/helpers/asset_tag_helper.rb +81 -50
  122. data/lib/action_view/helpers/atom_feed_helper.rb +1 -1
  123. data/lib/action_view/helpers/benchmark_helper.rb +26 -5
  124. data/lib/action_view/helpers/date_helper.rb +82 -7
  125. data/lib/action_view/helpers/form_helper.rb +295 -64
  126. data/lib/action_view/helpers/form_options_helper.rb +160 -18
  127. data/lib/action_view/helpers/form_tag_helper.rb +2 -2
  128. data/lib/action_view/helpers/number_helper.rb +31 -18
  129. data/lib/action_view/helpers/prototype_helper.rb +2 -12
  130. data/lib/action_view/helpers/sanitize_helper.rb +0 -10
  131. data/lib/action_view/helpers/scriptaculous_helper.rb +1 -0
  132. data/lib/action_view/helpers/tag_helper.rb +3 -4
  133. data/lib/action_view/helpers/text_helper.rb +99 -122
  134. data/lib/action_view/helpers/translation_helper.rb +19 -1
  135. data/lib/action_view/helpers/url_helper.rb +25 -2
  136. data/lib/action_view/inline_template.rb +1 -1
  137. data/lib/action_view/locale/en.yml +19 -1
  138. data/lib/action_view/partials.rb +46 -9
  139. data/lib/action_view/paths.rb +28 -84
  140. data/lib/action_view/reloadable_template.rb +117 -0
  141. data/lib/action_view/renderable.rb +28 -35
  142. data/lib/action_view/renderable_partial.rb +3 -4
  143. data/lib/action_view/template.rb +172 -31
  144. data/lib/action_view/template_error.rb +8 -9
  145. data/lib/action_view/template_handler.rb +1 -1
  146. data/lib/action_view/template_handlers.rb +9 -6
  147. data/lib/action_view/template_handlers/erb.rb +2 -39
  148. data/lib/action_view/template_handlers/rjs.rb +1 -0
  149. data/lib/action_view/test_case.rb +27 -1
  150. data/test/abstract_unit.rb +23 -17
  151. data/test/active_record_unit.rb +5 -4
  152. data/test/activerecord/active_record_store_test.rb +139 -106
  153. data/test/activerecord/render_partial_with_record_identification_test.rb +5 -21
  154. data/test/controller/action_pack_assertions_test.rb +25 -23
  155. data/test/controller/addresses_render_test.rb +3 -6
  156. data/test/controller/assert_select_test.rb +83 -70
  157. data/test/controller/base_test.rb +11 -13
  158. data/test/controller/benchmark_test.rb +3 -3
  159. data/test/controller/caching_test.rb +34 -24
  160. data/test/controller/capture_test.rb +3 -6
  161. data/test/controller/content_type_test.rb +3 -6
  162. data/test/controller/cookie_test.rb +31 -66
  163. data/test/controller/deprecation/deprecated_base_methods_test.rb +9 -11
  164. data/test/controller/dispatcher_test.rb +23 -28
  165. data/test/controller/fake_models.rb +8 -0
  166. data/test/controller/filters_test.rb +6 -2
  167. data/test/controller/flash_test.rb +2 -6
  168. data/test/controller/helper_test.rb +15 -1
  169. data/test/controller/html-scanner/document_test.rb +1 -1
  170. data/test/controller/html-scanner/sanitizer_test.rb +1 -1
  171. data/test/controller/http_basic_authentication_test.rb +88 -0
  172. data/test/controller/http_digest_authentication_test.rb +178 -0
  173. data/test/controller/integration_test.rb +56 -52
  174. data/test/controller/layout_test.rb +46 -44
  175. data/test/controller/middleware_stack_test.rb +90 -0
  176. data/test/controller/mime_responds_test.rb +7 -11
  177. data/test/controller/mime_type_test.rb +9 -0
  178. data/test/controller/polymorphic_routes_test.rb +235 -151
  179. data/test/controller/rack_test.rb +52 -81
  180. data/test/controller/redirect_test.rb +6 -14
  181. data/test/controller/render_test.rb +273 -60
  182. data/test/controller/request/json_params_parsing_test.rb +45 -0
  183. data/test/controller/request/multipart_params_parsing_test.rb +223 -0
  184. data/test/controller/request/query_string_parsing_test.rb +120 -0
  185. data/test/controller/request/url_encoded_params_parsing_test.rb +184 -0
  186. data/test/controller/request/xml_params_parsing_test.rb +88 -0
  187. data/test/controller/request_forgery_protection_test.rb +17 -98
  188. data/test/controller/request_test.rb +45 -530
  189. data/test/controller/rescue_test.rb +45 -22
  190. data/test/controller/resources_test.rb +112 -37
  191. data/test/controller/routing_test.rb +1442 -1384
  192. data/test/controller/selector_test.rb +3 -3
  193. data/test/controller/send_file_test.rb +30 -3
  194. data/test/controller/session/cookie_store_test.rb +169 -240
  195. data/test/controller/session/mem_cache_store_test.rb +94 -148
  196. data/test/controller/session/test_session_test.rb +58 -0
  197. data/test/controller/test_test.rb +32 -13
  198. data/test/controller/url_rewriter_test.rb +54 -4
  199. data/test/controller/verification_test.rb +1 -1
  200. data/test/controller/view_paths_test.rb +15 -15
  201. data/test/controller/webservice_test.rb +178 -147
  202. data/test/fixtures/alternate_helpers/foo_helper.rb +3 -0
  203. data/test/fixtures/layout_tests/alt/layouts/alt.rhtml +0 -0
  204. data/test/fixtures/layouts/default_html.html.erb +1 -0
  205. data/test/fixtures/layouts/xhr.html.erb +2 -0
  206. data/test/fixtures/multipart/empty +10 -0
  207. data/test/fixtures/multipart/hello.txt +1 -0
  208. data/test/fixtures/multipart/none +9 -0
  209. data/test/fixtures/public/500.da.html +1 -0
  210. data/test/fixtures/quiz/questions/_question.html.erb +1 -0
  211. data/test/fixtures/replies.yml +1 -1
  212. data/test/fixtures/test/_one.html.erb +1 -0
  213. data/test/fixtures/test/_two.html.erb +1 -0
  214. data/test/fixtures/test/dont_pick_me +1 -0
  215. data/test/fixtures/test/hello.builder +1 -1
  216. data/test/fixtures/test/hello_world.da.html.erb +1 -0
  217. data/test/fixtures/test/hello_world.erb~ +1 -0
  218. data/test/fixtures/test/hello_world.pt-BR.html.erb +1 -0
  219. data/test/fixtures/test/malformed/malformed.en.html.erb~ +1 -0
  220. data/test/fixtures/test/malformed/malformed.erb~ +1 -0
  221. data/test/fixtures/test/malformed/malformed.html.erb~ +1 -0
  222. data/test/fixtures/test/render_explicit_html_template.js.rjs +1 -0
  223. data/test/fixtures/test/render_implicit_html_template.js.rjs +1 -0
  224. data/test/fixtures/test/render_implicit_html_template_from_xhr_request.da.html.erb +1 -0
  225. data/test/fixtures/test/render_implicit_html_template_from_xhr_request.html.erb +1 -0
  226. data/test/fixtures/test/render_implicit_js_template_without_layout.js.erb +1 -0
  227. data/test/fixtures/test/utf8.html.erb +2 -0
  228. data/test/template/active_record_helper_i18n_test.rb +31 -33
  229. data/test/template/active_record_helper_test.rb +34 -0
  230. data/test/template/asset_tag_helper_test.rb +52 -14
  231. data/test/template/atom_feed_helper_test.rb +3 -5
  232. data/test/template/benchmark_helper_test.rb +50 -24
  233. data/test/template/compiled_templates_test.rb +177 -33
  234. data/test/template/date_helper_i18n_test.rb +88 -81
  235. data/test/template/date_helper_test.rb +427 -43
  236. data/test/template/form_helper_test.rb +243 -44
  237. data/test/template/form_options_helper_test.rb +631 -565
  238. data/test/template/form_tag_helper_test.rb +9 -2
  239. data/test/template/javascript_helper_test.rb +0 -5
  240. data/test/template/number_helper_i18n_test.rb +60 -48
  241. data/test/template/number_helper_test.rb +1 -0
  242. data/test/template/render_test.rb +117 -35
  243. data/test/template/test_test.rb +4 -6
  244. data/test/template/text_helper_test.rb +129 -50
  245. data/test/template/translation_helper_test.rb +23 -19
  246. data/test/template/url_helper_test.rb +35 -2
  247. data/test/view/test_case_test.rb +8 -0
  248. metadata +197 -23
  249. data/lib/action_controller/assertions.rb +0 -69
  250. data/lib/action_controller/caching/sql_cache.rb +0 -18
  251. data/lib/action_controller/cgi_ext/session.rb +0 -53
  252. data/lib/action_controller/components.rb +0 -169
  253. data/lib/action_controller/rack_process.rb +0 -297
  254. data/lib/action_controller/request_profiler.rb +0 -169
  255. data/lib/action_controller/session/active_record_store.rb +0 -340
  256. data/lib/action_controller/session/drb_server.rb +0 -32
  257. data/lib/action_controller/session/drb_store.rb +0 -35
  258. data/test/controller/cgi_test.rb +0 -269
  259. data/test/controller/components_test.rb +0 -156
  260. data/test/controller/http_authentication_test.rb +0 -54
  261. data/test/controller/integration_upload_test.rb +0 -43
  262. data/test/controller/session_fixation_test.rb +0 -89
  263. data/test/controller/session_management_test.rb +0 -178
  264. 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
- original_exception.clean_backtrace
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\n#{self.class} (#{message}) #{source_location}:\n" +
70
- "#{source_extract}\n #{clean_backtrace.join("\n ")}\n\n"
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
@@ -18,7 +18,7 @@ module ActionView
18
18
  end
19
19
  end
20
20
 
21
- class TemplateHandler #:nodoc:
21
+ class TemplateHandler
22
22
  def self.call(template)
23
23
  "#{name}.new(self).render(template, local_assigns)"
24
24
  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 && @@template_handlers[extension.to_sym]) || @@default_template_handlers
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 = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;' }
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 &gt; 0 &amp; a &lt; 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
@@ -4,6 +4,7 @@ module ActionView
4
4
  include Compilable
5
5
 
6
6
  def compile(template)
7
+ "@template_format = :html;" +
7
8
  "controller.response.content_type ||= Mime::JS;" +
8
9
  "update_page do |page|;#{template.source}\nend"
9
10
  end
@@ -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
 
@@ -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
- require 'action_controller'
9
- require 'action_controller/cgi_ext'
10
- require 'action_controller/test_process'
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::PathSet::Path.eager_load_templates!
41
+ ActionView::Base.cache_template_loading = true
27
42
  ActionController::Base.view_paths = FIXTURE_LOAD_PATH
28
-
29
- # Wrap tests that use Mocha and skip if unavailable.
30
- def uses_mocha(test_name)
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)}
@@ -51,7 +51,8 @@ class ActiveRecordTestConnector
51
51
  if Object.const_defined?(:ActiveRecord)
52
52
  defaults = { :database => ':memory:' }
53
53
  begin
54
- options = defaults.merge :adapter => 'sqlite3', :timeout => 500
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 < ActiveSupport::TestCase
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
- def test_reload_same_session
19
- @new_session.update
20
- reloaded = CGI::Session.new(CGI.new, 'session_id' => @new_session.session_id, 'database_manager' => CGI::Session::ActiveRecordStore)
21
- assert_equal 'bar', reloaded['foo']
22
- end
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
- def test_tolerates_close_close
25
- assert_nothing_raised do
26
- @new_session.close
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
- def session_class
36
- CGI::Session::ActiveRecordStore::Session
37
- end
15
+ def set_session_value
16
+ session[:foo] = params[:foo] || "bar"
17
+ head :ok
18
+ end
38
19
 
39
- def session_id_column
40
- "session_id"
41
- end
20
+ def get_session_value
21
+ render :text => "foo: #{session[:foo].inspect}"
22
+ end
42
23
 
43
- def setup
44
- session_class.create_table!
24
+ def get_session_id
25
+ session[:foo]
26
+ render :text => "#{request.session_options[:id]}"
27
+ end
45
28
 
46
- ENV['REQUEST_METHOD'] = 'GET'
47
- ENV['REQUEST_URI'] = '/'
48
- CGI::Session::ActiveRecordStore.session_class = session_class
29
+ def call_reset_session
30
+ session[:bar]
31
+ reset_session
32
+ session[:bar] = "baz"
33
+ head :ok
34
+ end
49
35
 
50
- @cgi = CGI.new
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
- # this test only applies for eager session saving
56
- # def test_another_instance
57
- # @another = CGI::Session.new(@cgi, 'session_id' => @new_session.session_id, 'database_manager' => CGI::Session::ActiveRecordStore)
58
- # assert_equal @new_session.session_id, @another.session_id
59
- # end
39
+ def setup
40
+ ActiveRecord::SessionStore.session_class.create_table!
41
+ @integration_session = open_session(SessionApp)
42
+ end
60
43
 
61
- def test_model_attribute
62
- assert_kind_of CGI::Session::ActiveRecordStore::Session, @new_session.model
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 test_save_unloaded_session
67
- c = session_class.connection
68
- bogus_class = c.quote(ActiveSupport::Base64.encode64("\004\010o:\vBlammo\000"))
69
- c.insert("INSERT INTO #{session_class.table_name} ('#{session_id_column}', 'data') VALUES ('abcdefghijklmnop', #{bogus_class})")
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
- sess = session_class.find_by_session_id('abcdefghijklmnop')
72
- assert_not_nil sess
73
- assert !sess.loaded?
54
+ get '/get_session_value'
55
+ assert_response :success
56
+ assert_equal 'foo: "bar"', response.body
74
57
 
75
- # because the session is not loaded, the save should be a no-op. If it
76
- # isn't, this'll try and unmarshall the bogus class, and should get an error.
77
- assert_nothing_raised { sess.save }
78
- end
58
+ get '/set_session_value', :foo => "baz"
59
+ assert_response :success
60
+ assert cookies['_session_id']
79
61
 
80
- def teardown
81
- session_class.drop_table!
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
- class ColumnLimitTest < ActiveRecordTestCase
86
- def setup
87
- @session_class = CGI::Session::ActiveRecordStore::Session
88
- @session_class.create_table!
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 teardown
92
- @session_class.drop_table!
93
- end
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
- def test_protection_from_data_larger_than_column
96
- # Can't test this unless there is a limit
97
- return unless limit = @session_class.data_column_size_limit
98
- too_big = ':(' * limit
99
- s = @session_class.new(:session_id => '666', :data => {'foo' => too_big})
100
- s.data
101
- assert_raise(ActionController::SessionOverflowError) { s.save }
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
- class DeprecatedActiveRecordStoreTest < ActiveRecordStoreTest
106
- def session_id_column
107
- "sessid"
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 setup
111
- session_class.connection.execute 'create table old_sessions (id integer primary key, sessid text unique, data text)'
112
- session_class.table_name = 'old_sessions'
113
- session_class.send :setup_sessid_compatibility!
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
- ENV['REQUEST_METHOD'] = 'GET'
116
- CGI::Session::ActiveRecordStore.session_class = session_class
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
- @new_session = CGI::Session.new(CGI.new, 'database_manager' => CGI::Session::ActiveRecordStore, 'new_session' => true)
119
- @new_session['foo'] = 'bar'
120
- end
122
+ reset!
121
123
 
122
- def teardown
123
- session_class.connection.execute 'drop table old_sessions'
124
- session_class.table_name = 'sessions'
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
- class SqlBypassActiveRecordStoreTest < ActiveRecordStoreTest
129
- def session_class
130
- unless defined? @session_class
131
- @session_class = CGI::Session::ActiveRecordStore::SqlBypass
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 test_model_attribute
138
- assert_kind_of CGI::Session::ActiveRecordStore::SqlBypass, @new_session.model
139
- assert_equal({ 'foo' => 'bar' }, @new_session.model.data)
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