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,4 +1,4 @@
1
- Copyright (c) 2004-2008 David Heinemeier Hansson
1
+ Copyright (c) 2004-2009 David Heinemeier Hansson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README CHANGED
@@ -10,7 +10,7 @@ Action Pack implements these actions as public methods on Action Controllers
10
10
  and uses Action Views to implement the template rendering. Action Controllers
11
11
  are then responsible for handling all the actions relating to a certain part
12
12
  of an application. This grouping usually consists of actions for lists and for
13
- CRUDs revolving around a single (or a few) model objects. So ContactController
13
+ CRUDs revolving around a single (or a few) model objects. So ContactsController
14
14
  would be responsible for listing contacts, creating, deleting, and updating
15
15
  contacts. A WeblogController could be responsible for both posts and comments.
16
16
 
@@ -33,7 +33,7 @@ A short rundown of the major features:
33
33
  * Actions grouped in controller as methods instead of separate command objects
34
34
  and can therefore share helper methods
35
35
 
36
- BlogController < ActionController::Base
36
+ CustomersController < ActionController::Base
37
37
  def show
38
38
  @customer = find_customer
39
39
  end
@@ -42,7 +42,7 @@ A short rundown of the major features:
42
42
  @customer = find_customer
43
43
  @customer.attributes = params[:customer]
44
44
  @customer.save ?
45
- redirect_to(:action => "display") :
45
+ redirect_to(:action => "show") :
46
46
  render(:action => "edit")
47
47
  end
48
48
 
@@ -59,7 +59,7 @@ A short rundown of the major features:
59
59
  Title: <%= post.title %>
60
60
  <% end %>
61
61
 
62
- All post titles: <%= @post.collect{ |p| p.title }.join ", " %>
62
+ All post titles: <%= @posts.collect{ |p| p.title }.join ", " %>
63
63
 
64
64
  <% unless @person.is_client? %>
65
65
  Not for clients to see...
@@ -123,7 +123,7 @@ A short rundown of the major features:
123
123
  <%= text_field "post", "title", "size" => 30 %>
124
124
  <%= html_date_select(Date.today) %>
125
125
  <%= link_to "New post", :controller => "post", :action => "new" %>
126
- <%= truncate(post.title, 25) %>
126
+ <%= truncate(post.title, :length => 25) %>
127
127
 
128
128
  {Learn more}[link:classes/ActionView/Helpers.html]
129
129
 
@@ -177,21 +177,6 @@ A short rundown of the major features:
177
177
  {Learn more}[link:classes/ActionView/Helpers/JavaScriptHelper.html]
178
178
 
179
179
 
180
- * Pagination for navigating lists of results
181
-
182
- # controller
183
- def list
184
- @pages, @people =
185
- paginate :people, :order => 'last_name, first_name'
186
- end
187
-
188
- # view
189
- <%= link_to "Previous page", { :page => @pages.current.previous } if @pages.current.previous %>
190
- <%= link_to "Next page", { :page => @pages.current.next } if @pages.current.next %>
191
-
192
- {Learn more}[link:classes/ActionController/Pagination.html]
193
-
194
-
195
180
  * Easy testing of both controller and rendered template through ActionController::TestCase
196
181
 
197
182
  class LoginControllerTest < ActionController::TestCase
@@ -215,11 +200,11 @@ A short rundown of the major features:
215
200
  If Active Record is used as the model, you'll have the database debugging
216
201
  as well:
217
202
 
218
- Processing WeblogController#create (for 127.0.0.1 at Sat Jun 19 14:04:23)
219
- Params: {"controller"=>"weblog", "action"=>"create",
203
+ Processing PostsController#create (for 127.0.0.1 at Sat Jun 19 14:04:23)
204
+ Params: {"controller"=>"posts", "action"=>"create",
220
205
  "post"=>{"title"=>"this is good"} }
221
206
  SQL (0.000627) INSERT INTO posts (title) VALUES('this is good')
222
- Redirected to http://test/weblog/display/5
207
+ Redirected to http://example.com/posts/5
223
208
  Completed in 0.221764 (4 reqs/sec) | DB: 0.059920 (27%)
224
209
 
225
210
  You specify a logger through a class method, such as:
@@ -256,30 +241,6 @@ A short rundown of the major features:
256
241
  {Learn more}[link:classes/ActionController/Caching.html]
257
242
 
258
243
 
259
- * Component requests from one controller to another
260
-
261
- class WeblogController < ActionController::Base
262
- # Performs a method and then lets hello_world output its render
263
- def delegate_action
264
- do_other_stuff_before_hello_world
265
- render_component :controller => "greeter", :action => "hello_world"
266
- end
267
- end
268
-
269
- class GreeterController < ActionController::Base
270
- def hello_world
271
- render_text "Hello World!"
272
- end
273
- end
274
-
275
- The same can be done in a view to do a partial rendering:
276
-
277
- Let's see a greeting:
278
- <%= render_component :controller => "greeter", :action => "hello_world" %>
279
-
280
- {Learn more}[link:classes/ActionController/Components.html]
281
-
282
-
283
244
  * Powerful debugging mechanism for local requests
284
245
 
285
246
  All exceptions raised on actions performed on the request of a local user
@@ -336,7 +297,7 @@ A short rundown of the major features:
336
297
  class WeblogController < ActionController::Base
337
298
  def create
338
299
  post = Post.create(params[:post])
339
- redirect_to :action => "display", :id => post.id
300
+ redirect_to :action => "show", :id => post.id
340
301
  end
341
302
  end
342
303
 
@@ -362,7 +323,7 @@ methods:
362
323
  @posts = Post.find(:all)
363
324
  end
364
325
 
365
- def display
326
+ def show
366
327
  @post = Post.find(params[:id])
367
328
  end
368
329
 
@@ -372,7 +333,7 @@ methods:
372
333
 
373
334
  def create
374
335
  @post = Post.create(params[:post])
375
- redirect_to :action => "display", :id => @post.id
336
+ redirect_to :action => "show", :id => @post.id
376
337
  end
377
338
  end
378
339
 
@@ -385,47 +346,32 @@ request from the web-server (like to be Apache).
385
346
 
386
347
  And the templates look like this:
387
348
 
388
- weblog/layout.erb:
349
+ weblog/layout.html.erb:
389
350
  <html><body>
390
351
  <%= yield %>
391
352
  </body></html>
392
353
 
393
- weblog/index.erb:
354
+ weblog/index.html.erb:
394
355
  <% for post in @posts %>
395
- <p><%= link_to(post.title, :action => "display", :id => post.id %></p>
356
+ <p><%= link_to(post.title, :action => "show", :id => post.id) %></p>
396
357
  <% end %>
397
358
 
398
- weblog/display.erb:
359
+ weblog/show.html.erb:
399
360
  <p>
400
- <b><%= post.title %></b><br/>
401
- <b><%= post.content %></b>
361
+ <b><%= @post.title %></b><br/>
362
+ <b><%= @post.content %></b>
402
363
  </p>
403
364
 
404
- weblog/new.erb:
365
+ weblog/new.html.erb:
405
366
  <%= form "post" %>
406
367
 
407
368
  This simple setup will list all the posts in the system on the index page,
408
369
  which is called by accessing /weblog/. It uses the form builder for the Active
409
370
  Record model to make the new screen, which in turn hands everything over to
410
371
  the create action (that's the default target for the form builder when given a
411
- new model). After creating the post, it'll redirect to the display page using
412
- an URL such as /weblog/display/5 (where 5 is the id of the post).
413
-
414
-
415
- == Examples
416
-
417
- Action Pack ships with three examples that all demonstrate an increasingly
418
- detailed view of the possibilities. First is blog_controller that is just a
419
- single file for the whole MVC (but still split into separate parts). Second is
420
- the debate_controller that uses separate template files and multiple screens.
421
- Third is the address_book_controller that uses the layout feature to separate
422
- template casing from content.
423
-
424
- Please note that you might need to change the "shebang" line to
425
- #!/usr/local/env ruby, if your Ruby is not placed in /usr/local/bin/ruby
372
+ new model). After creating the post, it'll redirect to the show page using
373
+ an URL such as /weblog/5 (where 5 is the id of the post).
426
374
 
427
- Also note that these examples are all for demonstrating using Action Pack on
428
- its own. Not for when it's used inside of Rails.
429
375
 
430
376
  == Download
431
377
 
@@ -460,4 +406,4 @@ And as Jim from Rake says:
460
406
 
461
407
  Feel free to submit commits or feature requests. If you send a patch,
462
408
  remember to update the corresponding unit tests. If fact, I prefer
463
- new feature to be submitted in the form of new unit tests.
409
+ new feature to be submitted in the form of new unit tests.
data/Rakefile CHANGED
@@ -80,7 +80,7 @@ spec = Gem::Specification.new do |s|
80
80
  s.has_rdoc = true
81
81
  s.requirements << 'none'
82
82
 
83
- s.add_dependency('activesupport', '= 2.2.3' + PKG_BUILD)
83
+ s.add_dependency('activesupport', '= 2.3.2' + PKG_BUILD)
84
84
 
85
85
  s.require_path = 'lib'
86
86
  s.autorequire = 'action_controller'
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2004-2008 David Heinemeier Hansson
2
+ # Copyright (c) 2004-2009 David Heinemeier Hansson
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -31,49 +31,86 @@ rescue LoadError
31
31
  end
32
32
  end
33
33
 
34
- $:.unshift "#{File.dirname(__FILE__)}/action_controller/vendor/html-scanner"
34
+ begin
35
+ gem 'rack', '~> 1.0.0'
36
+ require 'rack'
37
+ rescue Gem::LoadError
38
+ require 'action_controller/vendor/rack-1.0/rack'
39
+ end
35
40
 
36
- require 'action_controller/base'
37
- require 'action_controller/request'
38
- require 'action_controller/rescue'
39
- require 'action_controller/benchmarking'
40
- require 'action_controller/flash'
41
- require 'action_controller/filters'
42
- require 'action_controller/layout'
43
- require 'action_controller/mime_responds'
44
- require 'action_controller/helpers'
45
- require 'action_controller/cookies'
46
- require 'action_controller/cgi_process'
47
- require 'action_controller/caching'
48
- require 'action_controller/verification'
49
- require 'action_controller/streaming'
50
- require 'action_controller/session_management'
51
- require 'action_controller/http_authentication'
52
- require 'action_controller/components'
53
- require 'action_controller/rack_process'
54
- require 'action_controller/record_identifier'
55
- require 'action_controller/request_forgery_protection'
56
- require 'action_controller/headers'
57
- require 'action_controller/translation'
41
+ module ActionController
42
+ # TODO: Review explicit to see if they will automatically be handled by
43
+ # the initilizer if they are really needed.
44
+ def self.load_all!
45
+ [Base, CGIHandler, CgiRequest, Request, Response, Http::Headers, UrlRewriter, UrlWriter]
46
+ end
58
47
 
59
- require 'action_view'
48
+ autoload :AbstractRequest, 'action_controller/request'
49
+ autoload :Base, 'action_controller/base'
50
+ autoload :Benchmarking, 'action_controller/benchmarking'
51
+ autoload :Caching, 'action_controller/caching'
52
+ autoload :Cookies, 'action_controller/cookies'
53
+ autoload :Dispatcher, 'action_controller/dispatcher'
54
+ autoload :Failsafe, 'action_controller/failsafe'
55
+ autoload :Filters, 'action_controller/filters'
56
+ autoload :Flash, 'action_controller/flash'
57
+ autoload :Helpers, 'action_controller/helpers'
58
+ autoload :HttpAuthentication, 'action_controller/http_authentication'
59
+ autoload :Integration, 'action_controller/integration'
60
+ autoload :IntegrationTest, 'action_controller/integration'
61
+ autoload :Layout, 'action_controller/layout'
62
+ autoload :MiddlewareStack, 'action_controller/middleware_stack'
63
+ autoload :MimeResponds, 'action_controller/mime_responds'
64
+ autoload :ParamsParser, 'action_controller/params_parser'
65
+ autoload :PolymorphicRoutes, 'action_controller/polymorphic_routes'
66
+ autoload :RecordIdentifier, 'action_controller/record_identifier'
67
+ autoload :Reloader, 'action_controller/reloader'
68
+ autoload :Request, 'action_controller/request'
69
+ autoload :RequestForgeryProtection, 'action_controller/request_forgery_protection'
70
+ autoload :Rescue, 'action_controller/rescue'
71
+ autoload :Resources, 'action_controller/resources'
72
+ autoload :Response, 'action_controller/response'
73
+ autoload :RewindableInput, 'action_controller/rewindable_input'
74
+ autoload :Routing, 'action_controller/routing'
75
+ autoload :SessionManagement, 'action_controller/session_management'
76
+ autoload :StatusCodes, 'action_controller/status_codes'
77
+ autoload :Streaming, 'action_controller/streaming'
78
+ autoload :TestCase, 'action_controller/test_case'
79
+ autoload :TestProcess, 'action_controller/test_process'
80
+ autoload :Translation, 'action_controller/translation'
81
+ autoload :UploadedFile, 'action_controller/uploaded_file'
82
+ autoload :UploadedStringIO, 'action_controller/uploaded_file'
83
+ autoload :UploadedTempfile, 'action_controller/uploaded_file'
84
+ autoload :UrlRewriter, 'action_controller/url_rewriter'
85
+ autoload :UrlWriter, 'action_controller/url_rewriter'
86
+ autoload :Verification, 'action_controller/verification'
87
+
88
+ module Assertions
89
+ autoload :DomAssertions, 'action_controller/assertions/dom_assertions'
90
+ autoload :ModelAssertions, 'action_controller/assertions/model_assertions'
91
+ autoload :ResponseAssertions, 'action_controller/assertions/response_assertions'
92
+ autoload :RoutingAssertions, 'action_controller/assertions/routing_assertions'
93
+ autoload :SelectorAssertions, 'action_controller/assertions/selector_assertions'
94
+ autoload :TagAssertions, 'action_controller/assertions/tag_assertions'
95
+ end
96
+
97
+ module Http
98
+ autoload :Headers, 'action_controller/headers'
99
+ end
100
+
101
+ module Session
102
+ autoload :AbstractStore, 'action_controller/session/abstract_store'
103
+ autoload :CookieStore, 'action_controller/session/cookie_store'
104
+ autoload :MemCacheStore, 'action_controller/session/mem_cache_store'
105
+ end
60
106
 
61
- ActionController::Base.class_eval do
62
- include ActionController::Flash
63
- include ActionController::Filters
64
- include ActionController::Layout
65
- include ActionController::Benchmarking
66
- include ActionController::Rescue
67
- include ActionController::MimeResponds
68
- include ActionController::Helpers
69
- include ActionController::Cookies
70
- include ActionController::Caching
71
- include ActionController::Verification
72
- include ActionController::Streaming
73
- include ActionController::SessionManagement
74
- include ActionController::HttpAuthentication::Basic::ControllerMethods
75
- include ActionController::Components
76
- include ActionController::RecordIdentifier
77
- include ActionController::RequestForgeryProtection
78
- include ActionController::Translation
107
+ # DEPRECATE: Remove CGI support
108
+ autoload :CgiRequest, 'action_controller/cgi_process'
109
+ autoload :CGIHandler, 'action_controller/cgi_process'
79
110
  end
111
+
112
+ autoload :Mime, 'action_controller/mime_type'
113
+
114
+ autoload :HTML, 'action_controller/vendor/html-scanner'
115
+
116
+ require 'action_view'
@@ -11,6 +11,7 @@ module ActionController
11
11
  # assert_valid(model)
12
12
  #
13
13
  def assert_valid(record)
14
+ ::ActiveSupport::Deprecation.warn("assert_valid is deprecated. Use assert record.valid? instead", caller)
14
15
  clean_backtrace do
15
16
  assert record.valid?, record.errors.full_messages.join("\n")
16
17
  end
@@ -1,6 +1,3 @@
1
- require 'rexml/document'
2
- require 'html/document'
3
-
4
1
  module ActionController
5
2
  module Assertions
6
3
  # A small suite of assertions that test responses from Rails applications.
@@ -19,7 +16,7 @@ module ActionController
19
16
  # ==== Examples
20
17
  #
21
18
  # # assert that the response was a redirection
22
- # assert_response :redirect
19
+ # assert_response :redirect
23
20
  #
24
21
  # # assert that the response code was status code 401 (unauthorized)
25
22
  # assert_response 401
@@ -44,7 +41,7 @@ module ActionController
44
41
  end
45
42
  end
46
43
 
47
- # Assert that the redirection options passed in match those of the redirect called in the latest action.
44
+ # Assert that the redirection options passed in match those of the redirect called in the latest action.
48
45
  # This match can be partial, such that assert_redirected_to(:controller => "weblog") will also
49
46
  # match the redirection of redirect_to(:controller => "weblog", :action => "show") and so on.
50
47
  #
@@ -63,12 +60,12 @@ module ActionController
63
60
  clean_backtrace do
64
61
  assert_response(:redirect, message)
65
62
  return true if options == @response.redirected_to
66
-
63
+
67
64
  # Support partial arguments for hash redirections
68
65
  if options.is_a?(Hash) && @response.redirected_to.is_a?(Hash)
69
66
  return true if options.all? {|(key, value)| @response.redirected_to[key] == value}
70
67
  end
71
-
68
+
72
69
  redirected_to_after_normalisation = normalize_argument_to_redirection(@response.redirected_to)
73
70
  options_after_normalisation = normalize_argument_to_redirection(options)
74
71
 
@@ -78,29 +75,59 @@ module ActionController
78
75
  end
79
76
  end
80
77
 
81
- # Asserts that the request was rendered with the appropriate template file.
78
+ # Asserts that the request was rendered with the appropriate template file or partials
82
79
  #
83
80
  # ==== Examples
84
81
  #
85
82
  # # assert that the "new" view template was rendered
86
83
  # assert_template "new"
87
84
  #
88
- def assert_template(expected = nil, message=nil)
85
+ # # assert that the "_customer" partial was rendered twice
86
+ # assert_template :partial => '_customer', :count => 2
87
+ #
88
+ # # assert that no partials were rendered
89
+ # assert_template :partial => false
90
+ #
91
+ def assert_template(options = {}, message = nil)
89
92
  clean_backtrace do
90
- rendered = @response.rendered_template.to_s
91
- msg = build_message(message, "expecting <?> but rendering with <?>", expected, rendered)
92
- assert_block(msg) do
93
- if expected.nil?
94
- @response.rendered_template.blank?
93
+ case options
94
+ when NilClass, String
95
+ rendered = @response.rendered[:template].to_s
96
+ msg = build_message(message,
97
+ "expecting <?> but rendering with <?>",
98
+ options, rendered)
99
+ assert_block(msg) do
100
+ if options.nil?
101
+ @response.rendered[:template].blank?
102
+ else
103
+ rendered.to_s.match(options)
104
+ end
105
+ end
106
+ when Hash
107
+ if expected_partial = options[:partial]
108
+ partials = @response.rendered[:partials]
109
+ if expected_count = options[:count]
110
+ found = partials.detect { |p, _| p.to_s.match(expected_partial) }
111
+ actual_count = found.nil? ? 0 : found.second
112
+ msg = build_message(message,
113
+ "expecting ? to be rendered ? time(s) but rendered ? time(s)",
114
+ expected_partial, expected_count, actual_count)
115
+ assert(actual_count == expected_count.to_i, msg)
116
+ else
117
+ msg = build_message(message,
118
+ "expecting partial <?> but action rendered <?>",
119
+ options[:partial], partials.keys)
120
+ assert(partials.keys.any? { |p| p.to_s.match(expected_partial) }, msg)
121
+ end
95
122
  else
96
- rendered.to_s.match(expected)
123
+ assert @response.rendered[:partials].empty?,
124
+ "Expected no partials to be rendered"
97
125
  end
98
126
  end
99
127
  end
100
128
  end
101
129
 
102
130
  private
103
-
104
131
  # Proxy to to_param if the object will respond to it.
105
132
  def parameterize(value)
106
133
  value.respond_to?(:to_param) ? value.to_param : value