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
@@ -105,7 +105,7 @@ class ControllerInstanceTests < Test::Unit::TestCase
105
105
  end
106
106
 
107
107
 
108
- class PerformActionTest < Test::Unit::TestCase
108
+ class PerformActionTest < ActionController::TestCase
109
109
  class MockLogger
110
110
  attr_reader :logged
111
111
 
@@ -129,6 +129,8 @@ class PerformActionTest < Test::Unit::TestCase
129
129
  @response = ActionController::TestResponse.new
130
130
 
131
131
  @request.host = "www.nextangle.com"
132
+
133
+ rescue_action_in_public!
132
134
  end
133
135
 
134
136
  def test_get_on_priv_should_show_selector
@@ -164,14 +166,12 @@ class PerformActionTest < Test::Unit::TestCase
164
166
  end
165
167
  end
166
168
 
167
- class DefaultUrlOptionsTest < Test::Unit::TestCase
168
- def setup
169
- @controller = DefaultUrlOptionsController.new
170
-
171
- @request = ActionController::TestRequest.new
172
- @response = ActionController::TestResponse.new
169
+ class DefaultUrlOptionsTest < ActionController::TestCase
170
+ tests DefaultUrlOptionsController
173
171
 
172
+ def setup
174
173
  @request.host = 'www.example.com'
174
+ rescue_action_in_public!
175
175
  end
176
176
 
177
177
  def test_default_url_options_are_used_if_set
@@ -189,14 +189,12 @@ class DefaultUrlOptionsTest < Test::Unit::TestCase
189
189
  end
190
190
  end
191
191
 
192
- class EmptyUrlOptionsTest < Test::Unit::TestCase
193
- def setup
194
- @controller = NonEmptyController.new
195
-
196
- @request = ActionController::TestRequest.new
197
- @response = ActionController::TestResponse.new
192
+ class EmptyUrlOptionsTest < ActionController::TestCase
193
+ tests NonEmptyController
198
194
 
195
+ def setup
199
196
  @request.host = 'www.example.com'
197
+ rescue_action_in_public!
200
198
  end
201
199
 
202
200
  def test_ensure_url_for_works_as_expected_when_called_with_no_options_if_default_url_options_is_not_set
@@ -11,17 +11,17 @@ class BenchmarkedController < ActionController::Base
11
11
  end
12
12
  end
13
13
 
14
- class BenchmarkTest < Test::Unit::TestCase
14
+ class BenchmarkTest < ActionController::TestCase
15
+ tests BenchmarkedController
16
+
15
17
  class MockLogger
16
18
  def method_missing(*args)
17
19
  end
18
20
  end
19
21
 
20
22
  def setup
21
- @controller = BenchmarkedController.new
22
23
  # benchmark doesn't do anything unless a logger is set
23
24
  @controller.logger = MockLogger.new
24
- @request, @response = ActionController::TestRequest.new, ActionController::TestResponse.new
25
25
  @request.host = "test.actioncontroller.i"
26
26
  end
27
27
 
@@ -42,12 +42,13 @@ class PageCachingTestController < ActionController::Base
42
42
  end
43
43
  end
44
44
 
45
- class PageCachingTest < Test::Unit::TestCase
45
+ class PageCachingTest < ActionController::TestCase
46
46
  def setup
47
47
  ActionController::Base.perform_caching = true
48
48
 
49
49
  ActionController::Routing::Routes.draw do |map|
50
50
  map.main '', :controller => 'posts'
51
+ map.formatted_posts 'posts.:format', :controller => 'posts'
51
52
  map.resources :posts
52
53
  map.connect ':controller/:action/:id'
53
54
  end
@@ -67,7 +68,7 @@ class PageCachingTest < Test::Unit::TestCase
67
68
 
68
69
  def teardown
69
70
  FileUtils.rm_rf(File.dirname(FILE_STORE_PATH))
70
-
71
+ ActionController::Routing::Routes.clear!
71
72
  ActionController::Base.perform_caching = false
72
73
  end
73
74
 
@@ -107,21 +108,18 @@ class PageCachingTest < Test::Unit::TestCase
107
108
  assert File.exist?("#{FILE_STORE_PATH}/page_caching_test/trailing_slash.html")
108
109
  end
109
110
 
110
- uses_mocha("should_cache_ok_at_custom_path") do
111
- def test_should_cache_ok_at_custom_path
112
- @request.stubs(:path).returns("/index.html")
113
- get :ok
114
- assert_response :ok
115
- assert File.exist?("#{FILE_STORE_PATH}/index.html")
116
- end
111
+ def test_should_cache_ok_at_custom_path
112
+ @request.stubs(:path).returns("/index.html")
113
+ get :ok
114
+ assert_response :ok
115
+ assert File.exist?("#{FILE_STORE_PATH}/index.html")
117
116
  end
118
117
 
119
118
  [:ok, :no_content, :found, :not_found].each do |status|
120
119
  [:get, :post, :put, :delete].each do |method|
121
120
  unless method == :get and status == :ok
122
121
  define_method "test_shouldnt_cache_#{method}_with_#{status}_status" do
123
- @request.env['REQUEST_METHOD'] = method.to_s.upcase
124
- process status
122
+ send(method, status)
125
123
  assert_response status
126
124
  assert_page_not_cached status, "#{method} with #{status} status shouldn't have been cached"
127
125
  end
@@ -168,7 +166,7 @@ class ActionCachingTestController < ActionController::Base
168
166
 
169
167
  def forbidden
170
168
  render :text => "Forbidden"
171
- headers["Status"] = "403 Forbidden"
169
+ response.status = "403 Forbidden"
172
170
  end
173
171
 
174
172
  def with_layout
@@ -222,7 +220,7 @@ class ActionCachingMockController
222
220
  end
223
221
  end
224
222
 
225
- class ActionCacheTest < Test::Unit::TestCase
223
+ class ActionCacheTest < ActionController::TestCase
226
224
  def setup
227
225
  reset!
228
226
  FileUtils.mkdir_p(FILE_STORE_PATH)
@@ -291,13 +289,11 @@ class ActionCacheTest < Test::Unit::TestCase
291
289
  ActionController::Base.use_accept_header = old_use_accept_header
292
290
  end
293
291
 
294
- uses_mocha 'test action cache' do
295
- def test_action_cache_with_store_options
296
- MockTime.expects(:now).returns(12345).once
297
- @controller.expects(:read_fragment).with('hostname.com/action_caching_test', :expires_in => 1.hour).once
298
- @controller.expects(:write_fragment).with('hostname.com/action_caching_test', '12345.0', :expires_in => 1.hour).once
299
- get :index
300
- end
292
+ def test_action_cache_with_store_options
293
+ MockTime.expects(:now).returns(12345).once
294
+ @controller.expects(:read_fragment).with('hostname.com/action_caching_test', :expires_in => 1.hour).once
295
+ @controller.expects(:write_fragment).with('hostname.com/action_caching_test', '12345.0', :expires_in => 1.hour).once
296
+ get :index
301
297
  end
302
298
 
303
299
  def test_action_cache_with_custom_cache_path
@@ -401,7 +397,7 @@ class ActionCacheTest < Test::Unit::TestCase
401
397
 
402
398
  def test_xml_version_of_resource_is_treated_as_different_cache
403
399
  with_routing do |set|
404
- ActionController::Routing::Routes.draw do |map|
400
+ set.draw do |map|
405
401
  map.connect ':controller/:action.:format'
406
402
  map.connect ':controller/:action'
407
403
  end
@@ -432,6 +428,20 @@ class ActionCacheTest < Test::Unit::TestCase
432
428
  assert_equal 'application/xml', @response.content_type
433
429
  end
434
430
 
431
+ def test_correct_content_type_is_returned_for_cache_hit_on_action_with_string_key
432
+ # run it twice to cache it the first time
433
+ get :show, :format => 'xml'
434
+ get :show, :format => 'xml'
435
+ assert_equal 'application/xml', @response.content_type
436
+ end
437
+
438
+ def test_correct_content_type_is_returned_for_cache_hit_on_action_with_string_key_from_proc
439
+ # run it twice to cache it the first time
440
+ get :edit, :id => 1, :format => 'xml'
441
+ get :edit, :id => 1, :format => 'xml'
442
+ assert_equal 'application/xml', @response.content_type
443
+ end
444
+
435
445
  def test_empty_path_is_normalized
436
446
  @mock_controller.mock_url_for = 'http://example.org/'
437
447
  @mock_controller.mock_path = '/'
@@ -471,7 +481,7 @@ class FragmentCachingTestController < ActionController::Base
471
481
  def some_action; end;
472
482
  end
473
483
 
474
- class FragmentCachingTest < Test::Unit::TestCase
484
+ class FragmentCachingTest < ActionController::TestCase
475
485
  def setup
476
486
  ActionController::Base.perform_caching = true
477
487
  @store = ActiveSupport::Cache::MemoryStore.new
@@ -527,7 +537,7 @@ class FragmentCachingTest < Test::Unit::TestCase
527
537
  def test_write_fragment_with_caching_disabled
528
538
  assert_nil @store.read('views/name')
529
539
  ActionController::Base.perform_caching = false
530
- assert_equal nil, @controller.write_fragment('name', 'value')
540
+ assert_equal 'value', @controller.write_fragment('name', 'value')
531
541
  assert_nil @store.read('views/name')
532
542
  end
533
543
 
@@ -603,7 +613,7 @@ class FunctionalCachingController < ActionController::Base
603
613
  end
604
614
  end
605
615
 
606
- class FunctionalFragmentCachingTest < Test::Unit::TestCase
616
+ class FunctionalFragmentCachingTest < ActionController::TestCase
607
617
  def setup
608
618
  ActionController::Base.perform_caching = true
609
619
  @store = ActiveSupport::Cache::MemoryStore.new
@@ -23,17 +23,14 @@ class CaptureController < ActionController::Base
23
23
  def rescue_action(e) raise end
24
24
  end
25
25
 
26
- class CaptureTest < Test::Unit::TestCase
27
- def setup
28
- @controller = CaptureController.new
26
+ class CaptureTest < ActionController::TestCase
27
+ tests CaptureController
29
28
 
29
+ def setup
30
30
  # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
31
31
  # a more accurate simulation of what happens in "real life".
32
32
  @controller.logger = Logger.new(nil)
33
33
 
34
- @request = ActionController::TestRequest.new
35
- @response = ActionController::TestResponse.new
36
-
37
34
  @request.host = "www.nextangle.com"
38
35
  end
39
36
 
@@ -50,16 +50,13 @@ class ContentTypeController < ActionController::Base
50
50
  def rescue_action(e) raise end
51
51
  end
52
52
 
53
- class ContentTypeTest < Test::Unit::TestCase
54
- def setup
55
- @controller = ContentTypeController.new
53
+ class ContentTypeTest < ActionController::TestCase
54
+ tests ContentTypeController
56
55
 
56
+ def setup
57
57
  # enable a logger so that (e.g.) the benchmarking stuff runs, so we can get
58
58
  # a more accurate simulation of what happens in "real life".
59
59
  @controller.logger = Logger.new(nil)
60
-
61
- @request = ActionController::TestRequest.new
62
- @response = ActionController::TestResponse.new
63
60
  end
64
61
 
65
62
  def test_render_defaults
@@ -1,24 +1,24 @@
1
1
  require 'abstract_unit'
2
2
 
3
- class CookieTest < Test::Unit::TestCase
3
+ class CookieTest < ActionController::TestCase
4
4
  class TestController < ActionController::Base
5
5
  def authenticate
6
6
  cookies["user_name"] = "david"
7
7
  end
8
8
 
9
9
  def authenticate_for_fourteen_days
10
- cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) }
10
+ cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) }
11
11
  end
12
12
 
13
13
  def authenticate_for_fourteen_days_with_symbols
14
- cookies[:user_name] = { :value => "david", :expires => Time.local(2005, 10, 10) }
14
+ cookies[:user_name] = { :value => "david", :expires => Time.utc(2005, 10, 10,5) }
15
15
  end
16
16
 
17
17
  def set_multiple_cookies
18
- cookies["user_name"] = { "value" => "david", "expires" => Time.local(2005, 10, 10) }
18
+ cookies["user_name"] = { "value" => "david", "expires" => Time.utc(2005, 10, 10,5) }
19
19
  cookies["login"] = "XJ-122"
20
20
  end
21
-
21
+
22
22
  def access_frozen_cookies
23
23
  cookies["will"] = "work"
24
24
  end
@@ -33,60 +33,64 @@ class CookieTest < Test::Unit::TestCase
33
33
  end
34
34
 
35
35
  def authenticate_with_http_only
36
- cookies["user_name"] = { :value => "david", :http_only => true }
36
+ cookies["user_name"] = { :value => "david", :httponly => true }
37
37
  end
38
38
 
39
- def rescue_action(e)
40
- raise unless ActionView::MissingTemplate # No templates here, and we don't care about the output
39
+ def rescue_action(e)
40
+ raise unless ActionView::MissingTemplate # No templates here, and we don't care about the output
41
41
  end
42
42
  end
43
43
 
44
- def setup
45
- @request = ActionController::TestRequest.new
46
- @response = ActionController::TestResponse.new
44
+ tests TestController
47
45
 
48
- @controller = TestController.new
46
+ def setup
49
47
  @request.host = "www.nextangle.com"
50
48
  end
51
49
 
52
50
  def test_setting_cookie
53
51
  get :authenticate
54
- assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david") ], @response.headers["cookie"]
52
+ assert_equal ["user_name=david; path=/"], @response.headers["Set-Cookie"]
53
+ assert_equal({"user_name" => "david"}, @response.cookies)
55
54
  end
56
55
 
57
56
  def test_setting_cookie_for_fourteen_days
58
57
  get :authenticate_for_fourteen_days
59
- assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], @response.headers["cookie"]
58
+ assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"]
59
+ assert_equal({"user_name" => "david"}, @response.cookies)
60
60
  end
61
61
 
62
62
  def test_setting_cookie_for_fourteen_days_with_symbols
63
63
  get :authenticate_for_fourteen_days_with_symbols
64
- assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "expires" => Time.local(2005, 10, 10)) ], @response.headers["cookie"]
64
+ assert_equal ["user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT"], @response.headers["Set-Cookie"]
65
+ assert_equal({"user_name" => "david"}, @response.cookies)
65
66
  end
66
67
 
67
68
  def test_setting_cookie_with_http_only
68
69
  get :authenticate_with_http_only
69
- assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "david", "http_only" => true) ], @response.headers["cookie"]
70
- assert_equal CGI::Cookie::new("name" => "user_name", "value" => "david", "path" => "/", "http_only" => true).to_s, @response.headers["cookie"][0].to_s
70
+ assert_equal ["user_name=david; path=/; HttpOnly"], @response.headers["Set-Cookie"]
71
+ assert_equal({"user_name" => "david"}, @response.cookies)
71
72
  end
72
73
 
73
74
  def test_multiple_cookies
74
75
  get :set_multiple_cookies
75
76
  assert_equal 2, @response.cookies.size
77
+ assert_equal "user_name=david; path=/; expires=Mon, 10-Oct-2005 05:00:00 GMT", @response.headers["Set-Cookie"][0]
78
+ assert_equal "login=XJ-122; path=/", @response.headers["Set-Cookie"][1]
79
+ assert_equal({"login" => "XJ-122", "user_name" => "david"}, @response.cookies)
76
80
  end
77
81
 
78
82
  def test_setting_test_cookie
79
83
  assert_nothing_raised { get :access_frozen_cookies }
80
84
  end
81
-
85
+
82
86
  def test_expiring_cookie
83
87
  get :logout
84
- assert_equal [ CGI::Cookie::new("name" => "user_name", "value" => "", "expires" => Time.at(0)) ], @response.headers["cookie"]
85
- assert_equal CGI::Cookie::new("name" => "user_name", "value" => "", "expires" => Time.at(0)).value, []
86
- end
87
-
88
+ assert_equal ["user_name=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT"], @response.headers["Set-Cookie"]
89
+ assert_equal({"user_name" => nil}, @response.cookies)
90
+ end
91
+
88
92
  def test_cookiejar_accessor
89
- @request.cookies["user_name"] = CGI::Cookie.new("name" => "user_name", "value" => "david", "expires" => Time.local(2025, 10, 10))
93
+ @request.cookies["user_name"] = "david"
90
94
  @controller.request = @request
91
95
  jar = ActionController::CookieJar.new(@controller)
92
96
  assert_equal "david", jar["user_name"]
@@ -94,53 +98,14 @@ class CookieTest < Test::Unit::TestCase
94
98
  end
95
99
 
96
100
  def test_cookiejar_accessor_with_array_value
97
- a = %w{1 2 3}
98
- @request.cookies["pages"] = CGI::Cookie.new("name" => "pages", "value" => a, "expires" => Time.local(2025, 10, 10))
101
+ @request.cookies["pages"] = %w{1 2 3}
99
102
  @controller.request = @request
100
103
  jar = ActionController::CookieJar.new(@controller)
101
- assert_equal a, jar["pages"]
104
+ assert_equal %w{1 2 3}, jar["pages"]
102
105
  end
103
-
106
+
104
107
  def test_delete_cookie_with_path
105
108
  get :delete_cookie_with_path
106
- assert_equal "/beaten", @response.headers["cookie"].first.path
107
- assert_not_equal "/", @response.headers["cookie"].first.path
108
- end
109
-
110
- def test_cookie_to_s_simple_values
111
- assert_equal 'myname=myvalue; path=', CGI::Cookie.new('myname', 'myvalue').to_s
112
- end
113
-
114
- def test_cookie_to_s_hash
115
- cookie_str = CGI::Cookie.new(
116
- 'name' => 'myname',
117
- 'value' => 'myvalue',
118
- 'domain' => 'mydomain',
119
- 'path' => 'mypath',
120
- 'expires' => Time.utc(2007, 10, 20),
121
- 'secure' => true,
122
- 'http_only' => true).to_s
123
- assert_equal 'myname=myvalue; domain=mydomain; path=mypath; expires=Sat, 20 Oct 2007 00:00:00 GMT; secure; HttpOnly', cookie_str
124
- end
125
-
126
- def test_cookie_to_s_hash_default_not_secure_not_http_only
127
- cookie_str = CGI::Cookie.new(
128
- 'name' => 'myname',
129
- 'value' => 'myvalue',
130
- 'domain' => 'mydomain',
131
- 'path' => 'mypath',
132
- 'expires' => Time.utc(2007, 10, 20))
133
- assert cookie_str !~ /secure/
134
- assert cookie_str !~ /HttpOnly/
135
- end
136
-
137
- def test_cookies_should_not_be_split_on_ampersand_values
138
- cookies = CGI::Cookie.parse('return_to=http://rubyonrails.org/search?term=api&scope=all&global=true')
139
- assert_equal({"return_to" => ["http://rubyonrails.org/search?term=api&scope=all&global=true"]}, cookies)
140
- end
141
-
142
- def test_cookies_should_not_be_split_on_values_with_newlines
143
- cookies = CGI::Cookie.new("name" => "val", "value" => "this\nis\na\ntest")
144
- assert cookies.size == 1
109
+ assert_equal ["user_name=; path=/beaten; expires=Thu, 01-Jan-1970 00:00:00 GMT"], @response.headers["Set-Cookie"]
145
110
  end
146
111
  end
@@ -1,6 +1,6 @@
1
1
  require 'abstract_unit'
2
2
 
3
- class DeprecatedBaseMethodsTest < Test::Unit::TestCase
3
+ class DeprecatedBaseMethodsTest < ActionController::TestCase
4
4
  class Target < ActionController::Base
5
5
  def home_url(greeting)
6
6
  "http://example.com/#{greeting}"
@@ -13,11 +13,7 @@ class DeprecatedBaseMethodsTest < Test::Unit::TestCase
13
13
  def rescue_action(e) raise e end
14
14
  end
15
15
 
16
- def setup
17
- @request = ActionController::TestRequest.new
18
- @response = ActionController::TestResponse.new
19
- @controller = Target.new
20
- end
16
+ tests Target
21
17
 
22
18
  def test_log_error_silences_deprecation_warnings
23
19
  get :raises_name_error
@@ -25,10 +21,12 @@ class DeprecatedBaseMethodsTest < Test::Unit::TestCase
25
21
  assert_not_deprecated { @controller.send :log_error, e }
26
22
  end
27
23
 
28
- def test_assertion_failed_error_silences_deprecation_warnings
29
- get :raises_name_error
30
- rescue => e
31
- error = Test::Unit::Error.new('testing ur doodz', e)
32
- assert_not_deprecated { error.message }
24
+ if defined? Test::Unit::Error
25
+ def test_assertion_failed_error_silences_deprecation_warnings
26
+ get :raises_name_error
27
+ rescue => e
28
+ error = Test::Unit::Error.new('testing ur doodz', e)
29
+ assert_not_deprecated { error.message }
30
+ end
33
31
  end
34
32
  end