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
@@ -1,6 +1,6 @@
1
1
  require 'abstract_unit'
2
2
 
3
- class VerificationTest < Test::Unit::TestCase
3
+ class VerificationTest < ActionController::TestCase
4
4
  class TestController < ActionController::Base
5
5
  verify :only => :guarded_one, :params => "one",
6
6
  :add_flash => { :error => 'unguarded' },
@@ -1,6 +1,6 @@
1
1
  require 'abstract_unit'
2
2
 
3
- class ViewLoadPathsTest < Test::Unit::TestCase
3
+ class ViewLoadPathsTest < ActionController::TestCase
4
4
  class TestController < ActionController::Base
5
5
  def self.controller_path() "test" end
6
6
  def rescue_action(e) raise end
@@ -41,31 +41,31 @@ class ViewLoadPathsTest < Test::Unit::TestCase
41
41
  def teardown
42
42
  ActiveSupport::Deprecation.behavior = @old_behavior
43
43
  end
44
-
44
+
45
45
  def test_template_load_path_was_set_correctly
46
- assert_equal [FIXTURE_LOAD_PATH], @controller.view_paths
46
+ assert_equal [FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
47
47
  end
48
48
 
49
49
  def test_controller_appends_view_path_correctly
50
50
  @controller.append_view_path 'foo'
51
- assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths
51
+ assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths.map(&:to_s)
52
52
 
53
53
  @controller.append_view_path(%w(bar baz))
54
- assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths
54
+ assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s)
55
55
 
56
56
  @controller.append_view_path(FIXTURE_LOAD_PATH)
57
- assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
57
+ assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
58
58
  end
59
59
 
60
60
  def test_controller_prepends_view_path_correctly
61
61
  @controller.prepend_view_path 'baz'
62
- assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths
62
+ assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
63
63
 
64
64
  @controller.prepend_view_path(%w(foo bar))
65
- assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
65
+ assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
66
66
 
67
67
  @controller.prepend_view_path(FIXTURE_LOAD_PATH)
68
- assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
68
+ assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
69
69
  end
70
70
 
71
71
  def test_template_appends_view_path_correctly
@@ -73,10 +73,10 @@ class ViewLoadPathsTest < Test::Unit::TestCase
73
73
  class_view_paths = TestController.view_paths
74
74
 
75
75
  @controller.append_view_path 'foo'
76
- assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths
76
+ assert_equal [FIXTURE_LOAD_PATH, 'foo'], @controller.view_paths.map(&:to_s)
77
77
 
78
78
  @controller.append_view_path(%w(bar baz))
79
- assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths
79
+ assert_equal [FIXTURE_LOAD_PATH, 'foo', 'bar', 'baz'], @controller.view_paths.map(&:to_s)
80
80
  assert_equal class_view_paths, TestController.view_paths
81
81
  end
82
82
 
@@ -85,10 +85,10 @@ class ViewLoadPathsTest < Test::Unit::TestCase
85
85
  class_view_paths = TestController.view_paths
86
86
 
87
87
  @controller.prepend_view_path 'baz'
88
- assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths
88
+ assert_equal ['baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
89
89
 
90
90
  @controller.prepend_view_path(%w(foo bar))
91
- assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths
91
+ assert_equal ['foo', 'bar', 'baz', FIXTURE_LOAD_PATH], @controller.view_paths.map(&:to_s)
92
92
  assert_equal class_view_paths, TestController.view_paths
93
93
  end
94
94
 
@@ -130,12 +130,12 @@ class ViewLoadPathsTest < Test::Unit::TestCase
130
130
 
131
131
  A.view_paths = ['a/path']
132
132
 
133
- assert_equal ['a/path'], A.view_paths
133
+ assert_equal ['a/path'], A.view_paths.map(&:to_s)
134
134
  assert_equal A.view_paths, B.view_paths
135
135
  assert_equal original_load_paths, C.view_paths
136
136
 
137
137
  C.view_paths = []
138
138
  assert_nothing_raised { C.view_paths << 'c/path' }
139
- assert_equal ['c/path'], C.view_paths
139
+ assert_equal ['c/path'], C.view_paths.map(&:to_s)
140
140
  end
141
141
  end
@@ -1,19 +1,7 @@
1
1
  require 'abstract_unit'
2
2
 
3
- class WebServiceTest < Test::Unit::TestCase
4
- class MockCGI < CGI #:nodoc:
5
- attr_accessor :stdoutput, :env_table
6
-
7
- def initialize(env, data = '')
8
- self.env_table = env
9
- self.stdoutput = StringIO.new
10
- super(nil, StringIO.new(data))
11
- end
12
- end
13
-
3
+ class WebServiceTest < ActionController::IntegrationTest
14
4
  class TestController < ActionController::Base
15
- session :off
16
-
17
5
  def assign_parameters
18
6
  if params[:full]
19
7
  render :text => dump_params_keys
@@ -22,7 +10,7 @@ class WebServiceTest < Test::Unit::TestCase
22
10
  end
23
11
  end
24
12
 
25
- def dump_params_keys(hash=params)
13
+ def dump_params_keys(hash = params)
26
14
  hash.keys.sort.inject("") do |s, k|
27
15
  value = hash[k]
28
16
  value = Hash === value ? "(#{dump_params_keys(value)})" : ""
@@ -33,7 +21,7 @@ class WebServiceTest < Test::Unit::TestCase
33
21
 
34
22
  def rescue_action(e) raise end
35
23
  end
36
-
24
+
37
25
  def setup
38
26
  @controller = TestController.new
39
27
  @default_param_parsers = ActionController::Base.param_parsers.dup
@@ -44,186 +32,229 @@ class WebServiceTest < Test::Unit::TestCase
44
32
  end
45
33
 
46
34
  def test_check_parameters
47
- process('GET')
48
- assert_equal '', @controller.response.body
35
+ with_test_route_set do
36
+ get "/"
37
+ assert_equal '', @controller.response.body
38
+ end
49
39
  end
50
40
 
51
41
  def test_post_xml
52
- process('POST', 'application/xml', '<entry attributed="true"><summary>content...</summary></entry>')
53
-
54
- assert_equal 'entry', @controller.response.body
55
- assert @controller.params.has_key?(:entry)
56
- assert_equal 'content...', @controller.params["entry"]['summary']
57
- assert_equal 'true', @controller.params["entry"]['attributed']
42
+ with_test_route_set do
43
+ post "/", '<entry attributed="true"><summary>content...</summary></entry>',
44
+ {'CONTENT_TYPE' => 'application/xml'}
45
+
46
+ assert_equal 'entry', @controller.response.body
47
+ assert @controller.params.has_key?(:entry)
48
+ assert_equal 'content...', @controller.params["entry"]['summary']
49
+ assert_equal 'true', @controller.params["entry"]['attributed']
50
+ end
58
51
  end
59
52
 
60
53
  def test_put_xml
61
- process('PUT', 'application/xml', '<entry attributed="true"><summary>content...</summary></entry>')
54
+ with_test_route_set do
55
+ put "/", '<entry attributed="true"><summary>content...</summary></entry>',
56
+ {'CONTENT_TYPE' => 'application/xml'}
62
57
 
63
- assert_equal 'entry', @controller.response.body
64
- assert @controller.params.has_key?(:entry)
65
- assert_equal 'content...', @controller.params["entry"]['summary']
66
- assert_equal 'true', @controller.params["entry"]['attributed']
58
+ assert_equal 'entry', @controller.response.body
59
+ assert @controller.params.has_key?(:entry)
60
+ assert_equal 'content...', @controller.params["entry"]['summary']
61
+ assert_equal 'true', @controller.params["entry"]['attributed']
62
+ end
67
63
  end
68
64
 
69
65
  def test_put_xml_using_a_type_node
70
- process('PUT', 'application/xml', '<type attributed="true"><summary>content...</summary></type>')
66
+ with_test_route_set do
67
+ put "/", '<type attributed="true"><summary>content...</summary></type>',
68
+ {'CONTENT_TYPE' => 'application/xml'}
71
69
 
72
- assert_equal 'type', @controller.response.body
73
- assert @controller.params.has_key?(:type)
74
- assert_equal 'content...', @controller.params["type"]['summary']
75
- assert_equal 'true', @controller.params["type"]['attributed']
70
+ assert_equal 'type', @controller.response.body
71
+ assert @controller.params.has_key?(:type)
72
+ assert_equal 'content...', @controller.params["type"]['summary']
73
+ assert_equal 'true', @controller.params["type"]['attributed']
74
+ end
76
75
  end
77
76
 
78
77
  def test_put_xml_using_a_type_node_and_attribute
79
- process('PUT', 'application/xml', '<type attributed="true"><summary type="boolean">false</summary></type>')
78
+ with_test_route_set do
79
+ put "/", '<type attributed="true"><summary type="boolean">false</summary></type>',
80
+ {'CONTENT_TYPE' => 'application/xml'}
80
81
 
81
- assert_equal 'type', @controller.response.body
82
- assert @controller.params.has_key?(:type)
83
- assert_equal false, @controller.params["type"]['summary']
84
- assert_equal 'true', @controller.params["type"]['attributed']
82
+ assert_equal 'type', @controller.response.body
83
+ assert @controller.params.has_key?(:type)
84
+ assert_equal false, @controller.params["type"]['summary']
85
+ assert_equal 'true', @controller.params["type"]['attributed']
86
+ end
85
87
  end
86
88
 
87
89
  def test_post_xml_using_a_type_node
88
- process('POST', 'application/xml', '<font attributed="true"><type>arial</type></font>')
90
+ with_test_route_set do
91
+ post "/", '<font attributed="true"><type>arial</type></font>',
92
+ {'CONTENT_TYPE' => 'application/xml'}
89
93
 
90
- assert_equal 'font', @controller.response.body
91
- assert @controller.params.has_key?(:font)
92
- assert_equal 'arial', @controller.params['font']['type']
93
- assert_equal 'true', @controller.params["font"]['attributed']
94
+ assert_equal 'font', @controller.response.body
95
+ assert @controller.params.has_key?(:font)
96
+ assert_equal 'arial', @controller.params['font']['type']
97
+ assert_equal 'true', @controller.params["font"]['attributed']
98
+ end
94
99
  end
95
100
 
96
101
  def test_post_xml_using_a_root_node_named_type
97
- process('POST', 'application/xml', '<type type="integer">33</type>')
102
+ with_test_route_set do
103
+ post "/", '<type type="integer">33</type>',
104
+ {'CONTENT_TYPE' => 'application/xml'}
98
105
 
99
- assert @controller.params.has_key?(:type)
100
- assert_equal 33, @controller.params['type']
106
+ assert @controller.params.has_key?(:type)
107
+ assert_equal 33, @controller.params['type']
108
+ end
101
109
  end
102
110
 
103
111
  def test_post_xml_using_an_attributted_node_named_type
104
- ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| XmlSimple.xml_in(data, 'ForceArray' => false) }
105
- process('POST', 'application/xml', '<request><type type="string">Arial,12</type><z>3</z></request>')
112
+ with_test_route_set do
113
+ ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| Hash.from_xml(data)['request'].with_indifferent_access }
114
+ post "/", '<request><type type="string">Arial,12</type><z>3</z></request>',
115
+ {'CONTENT_TYPE' => 'application/xml'}
106
116
 
107
- assert_equal 'type, z', @controller.response.body
108
- assert @controller.params.has_key?(:type)
109
- assert_equal 'string', @controller.params['type']['type']
110
- assert_equal 'Arial,12', @controller.params['type']['content']
111
- assert_equal '3', @controller.params['z']
117
+ assert_equal 'type, z', @controller.response.body
118
+ assert @controller.params.has_key?(:type)
119
+ assert_equal 'Arial,12', @controller.params['type'], @controller.params.inspect
120
+ assert_equal '3', @controller.params['z'], @controller.params.inspect
121
+ end
112
122
  end
113
123
 
114
124
  def test_register_and_use_yaml
115
- ActionController::Base.param_parsers[Mime::YAML] = Proc.new { |d| YAML.load(d) }
116
- process('POST', 'application/x-yaml', {"entry" => "loaded from yaml"}.to_yaml)
117
- assert_equal 'entry', @controller.response.body
118
- assert @controller.params.has_key?(:entry)
119
- assert_equal 'loaded from yaml', @controller.params["entry"]
125
+ with_test_route_set do
126
+ ActionController::Base.param_parsers[Mime::YAML] = Proc.new { |d| YAML.load(d) }
127
+ post "/", {"entry" => "loaded from yaml"}.to_yaml,
128
+ {'CONTENT_TYPE' => 'application/x-yaml'}
129
+
130
+ assert_equal 'entry', @controller.response.body
131
+ assert @controller.params.has_key?(:entry)
132
+ assert_equal 'loaded from yaml', @controller.params["entry"]
133
+ end
120
134
  end
121
-
135
+
122
136
  def test_register_and_use_yaml_as_symbol
123
- ActionController::Base.param_parsers[Mime::YAML] = :yaml
124
- process('POST', 'application/x-yaml', {"entry" => "loaded from yaml"}.to_yaml)
125
- assert_equal 'entry', @controller.response.body
126
- assert @controller.params.has_key?(:entry)
127
- assert_equal 'loaded from yaml', @controller.params["entry"]
137
+ with_test_route_set do
138
+ ActionController::Base.param_parsers[Mime::YAML] = :yaml
139
+ post "/", {"entry" => "loaded from yaml"}.to_yaml,
140
+ {'CONTENT_TYPE' => 'application/x-yaml'}
141
+
142
+ assert_equal 'entry', @controller.response.body
143
+ assert @controller.params.has_key?(:entry)
144
+ assert_equal 'loaded from yaml', @controller.params["entry"]
145
+ end
128
146
  end
129
147
 
130
148
  def test_register_and_use_xml_simple
131
- ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| XmlSimple.xml_in(data, 'ForceArray' => false) }
132
- process('POST', 'application/xml', '<request><summary>content...</summary><title>SimpleXml</title></request>' )
133
- assert_equal 'summary, title', @controller.response.body
134
- assert @controller.params.has_key?(:summary)
135
- assert @controller.params.has_key?(:title)
136
- assert_equal 'content...', @controller.params["summary"]
137
- assert_equal 'SimpleXml', @controller.params["title"]
149
+ with_test_route_set do
150
+ ActionController::Base.param_parsers[Mime::XML] = Proc.new { |data| Hash.from_xml(data)['request'].with_indifferent_access }
151
+ post "/", '<request><summary>content...</summary><title>SimpleXml</title></request>',
152
+ {'CONTENT_TYPE' => 'application/xml'}
153
+
154
+ assert_equal 'summary, title', @controller.response.body
155
+ assert @controller.params.has_key?(:summary)
156
+ assert @controller.params.has_key?(:title)
157
+ assert_equal 'content...', @controller.params["summary"]
158
+ assert_equal 'SimpleXml', @controller.params["title"]
159
+ end
138
160
  end
139
161
 
140
162
  def test_use_xml_ximple_with_empty_request
141
- ActionController::Base.param_parsers[Mime::XML] = :xml_simple
142
- assert_nothing_raised { process('POST', 'application/xml', "") }
143
- assert_equal "", @controller.response.body
163
+ with_test_route_set do
164
+ ActionController::Base.param_parsers[Mime::XML] = :xml_simple
165
+ assert_nothing_raised { post "/", "", {'CONTENT_TYPE' => 'application/xml'} }
166
+ assert_equal "", @controller.response.body
167
+ end
144
168
  end
145
169
 
146
170
  def test_dasherized_keys_as_xml
147
- ActionController::Base.param_parsers[Mime::XML] = :xml_simple
148
- process('POST', 'application/xml', "<first-key>\n<sub-key>...</sub-key>\n</first-key>", true)
149
- assert_equal 'action, controller, first_key(sub_key), full', @controller.response.body
150
- assert_equal "...", @controller.params[:first_key][:sub_key]
171
+ with_test_route_set do
172
+ ActionController::Base.param_parsers[Mime::XML] = :xml_simple
173
+ post "/?full=1", "<first-key>\n<sub-key>...</sub-key>\n</first-key>",
174
+ {'CONTENT_TYPE' => 'application/xml'}
175
+ assert_equal 'action, controller, first_key(sub_key), full', @controller.response.body
176
+ assert_equal "...", @controller.params[:first_key][:sub_key]
177
+ end
151
178
  end
152
179
 
153
180
  def test_typecast_as_xml
154
- ActionController::Base.param_parsers[Mime::XML] = :xml_simple
155
- process('POST', 'application/xml', <<-XML)
156
- <data>
157
- <a type="integer">15</a>
158
- <b type="boolean">false</b>
159
- <c type="boolean">true</c>
160
- <d type="date">2005-03-17</d>
161
- <e type="datetime">2005-03-17T21:41:07Z</e>
162
- <f>unparsed</f>
163
- <g type="integer">1</g>
164
- <g>hello</g>
165
- <g type="date">1974-07-25</g>
166
- </data>
167
- XML
168
- params = @controller.params
169
- assert_equal 15, params[:data][:a]
170
- assert_equal false, params[:data][:b]
171
- assert_equal true, params[:data][:c]
172
- assert_equal Date.new(2005,3,17), params[:data][:d]
173
- assert_equal Time.utc(2005,3,17,21,41,7), params[:data][:e]
174
- assert_equal "unparsed", params[:data][:f]
175
- assert_equal [1, "hello", Date.new(1974,7,25)], params[:data][:g]
181
+ with_test_route_set do
182
+ ActionController::Base.param_parsers[Mime::XML] = :xml_simple
183
+ xml = <<-XML
184
+ <data>
185
+ <a type="integer">15</a>
186
+ <b type="boolean">false</b>
187
+ <c type="boolean">true</c>
188
+ <d type="date">2005-03-17</d>
189
+ <e type="datetime">2005-03-17T21:41:07Z</e>
190
+ <f>unparsed</f>
191
+ <g type="integer">1</g>
192
+ <g>hello</g>
193
+ <g type="date">1974-07-25</g>
194
+ </data>
195
+ XML
196
+ post "/", xml, {'CONTENT_TYPE' => 'application/xml'}
197
+
198
+ params = @controller.params
199
+ assert_equal 15, params[:data][:a]
200
+ assert_equal false, params[:data][:b]
201
+ assert_equal true, params[:data][:c]
202
+ assert_equal Date.new(2005,3,17), params[:data][:d]
203
+ assert_equal Time.utc(2005,3,17,21,41,7), params[:data][:e]
204
+ assert_equal "unparsed", params[:data][:f]
205
+ assert_equal [1, "hello", Date.new(1974,7,25)], params[:data][:g]
206
+ end
176
207
  end
177
208
 
178
209
  def test_entities_unescaped_as_xml_simple
179
- ActionController::Base.param_parsers[Mime::XML] = :xml_simple
180
- process('POST', 'application/xml', <<-XML)
181
- <data>&lt;foo &quot;bar&apos;s&quot; &amp; friends&gt;</data>
182
- XML
183
- assert_equal %(<foo "bar's" & friends>), @controller.params[:data]
210
+ with_test_route_set do
211
+ ActionController::Base.param_parsers[Mime::XML] = :xml_simple
212
+ xml = <<-XML
213
+ <data>&lt;foo &quot;bar&apos;s&quot; &amp; friends&gt;</data>
214
+ XML
215
+ post "/", xml, {'CONTENT_TYPE' => 'application/xml'}
216
+ assert_equal %(<foo "bar's" & friends>), @controller.params[:data]
217
+ end
184
218
  end
185
219
 
186
220
  def test_typecast_as_yaml
187
- ActionController::Base.param_parsers[Mime::YAML] = :yaml
188
- process('POST', 'application/x-yaml', <<-YAML)
189
- ---
190
- data:
191
- a: 15
192
- b: false
193
- c: true
194
- d: 2005-03-17
195
- e: 2005-03-17T21:41:07Z
196
- f: unparsed
197
- g:
198
- - 1
199
- - hello
200
- - 1974-07-25
201
- YAML
202
- params = @controller.params
203
- assert_equal 15, params[:data][:a]
204
- assert_equal false, params[:data][:b]
205
- assert_equal true, params[:data][:c]
206
- assert_equal Date.new(2005,3,17), params[:data][:d]
207
- assert_equal Time.utc(2005,3,17,21,41,7), params[:data][:e]
208
- assert_equal "unparsed", params[:data][:f]
209
- assert_equal [1, "hello", Date.new(1974,7,25)], params[:data][:g]
210
- end
211
-
212
- private
213
-
214
- def process(verb, content_type = 'application/x-www-form-urlencoded', data = '', full=false)
215
-
216
- cgi = MockCGI.new({
217
- 'REQUEST_METHOD' => verb,
218
- 'CONTENT_TYPE' => content_type,
219
- 'QUERY_STRING' => "action=assign_parameters&controller=webservicetest/test#{"&full=1" if full}",
220
- "REQUEST_URI" => "/",
221
- "HTTP_HOST" => 'testdomain.com',
222
- "CONTENT_LENGTH" => data.size,
223
- "SERVER_PORT" => "80",
224
- "HTTPS" => "off"}, data)
225
-
226
- @controller.send(:process, ActionController::CgiRequest.new(cgi, {}), ActionController::CgiResponse.new(cgi))
227
- end
228
-
221
+ with_test_route_set do
222
+ ActionController::Base.param_parsers[Mime::YAML] = :yaml
223
+ yaml = <<-YAML
224
+ ---
225
+ data:
226
+ a: 15
227
+ b: false
228
+ c: true
229
+ d: 2005-03-17
230
+ e: 2005-03-17T21:41:07Z
231
+ f: unparsed
232
+ g:
233
+ - 1
234
+ - hello
235
+ - 1974-07-25
236
+ YAML
237
+ post "/", yaml, {'CONTENT_TYPE' => 'application/x-yaml'}
238
+ params = @controller.params
239
+ assert_equal 15, params[:data][:a]
240
+ assert_equal false, params[:data][:b]
241
+ assert_equal true, params[:data][:c]
242
+ assert_equal Date.new(2005,3,17), params[:data][:d]
243
+ assert_equal Time.utc(2005,3,17,21,41,7), params[:data][:e]
244
+ assert_equal "unparsed", params[:data][:f]
245
+ assert_equal [1, "hello", Date.new(1974,7,25)], params[:data][:g]
246
+ end
247
+ end
248
+
249
+ private
250
+ def with_test_route_set
251
+ with_routing do |set|
252
+ set.draw do |map|
253
+ map.with_options :controller => "web_service_test/test" do |c|
254
+ c.connect "/", :action => "assign_parameters"
255
+ end
256
+ end
257
+ yield
258
+ end
259
+ end
229
260
  end