rails 4.2.0.beta4 → 4.2.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. checksums.yaml +4 -4
  2. data/guides/Rakefile +3 -1
  3. data/guides/bug_report_templates/action_controller_gem.rb +2 -2
  4. data/guides/bug_report_templates/action_controller_master.rb +2 -2
  5. data/guides/source/3_0_release_notes.md +2 -2
  6. data/guides/source/4_1_release_notes.md +1 -1
  7. data/guides/source/4_2_release_notes.md +250 -225
  8. data/guides/source/_welcome.html.erb +1 -1
  9. data/guides/source/action_controller_overview.md +6 -6
  10. data/guides/source/action_mailer_basics.md +26 -11
  11. data/guides/source/action_view_overview.md +0 -1
  12. data/guides/source/active_job_basics.md +29 -23
  13. data/guides/source/active_record_postgresql.md +2 -7
  14. data/guides/source/active_record_validations.md +1 -0
  15. data/guides/source/active_support_core_extensions.md +1 -1
  16. data/guides/source/active_support_instrumentation.md +5 -5
  17. data/guides/source/asset_pipeline.md +2 -2
  18. data/guides/source/association_basics.md +0 -2
  19. data/guides/source/command_line.md +6 -15
  20. data/guides/source/configuring.md +4 -4
  21. data/guides/source/documents.yaml +0 -1
  22. data/guides/source/engines.md +26 -15
  23. data/guides/source/form_helpers.md +10 -2
  24. data/guides/source/getting_started.md +9 -9
  25. data/guides/source/rails_on_rack.md +2 -2
  26. data/guides/source/ruby_on_rails_guides_guidelines.md +1 -0
  27. data/guides/source/security.md +1 -1
  28. data/guides/source/testing.md +80 -13
  29. data/guides/source/upgrading_ruby_on_rails.md +23 -20
  30. metadata +29 -229
  31. data/guides/output/2_2_release_notes.html +0 -724
  32. data/guides/output/2_3_release_notes.html +0 -870
  33. data/guides/output/3_0_release_notes.html +0 -773
  34. data/guides/output/3_1_release_notes.html +0 -740
  35. data/guides/output/3_2_release_notes.html +0 -797
  36. data/guides/output/4_0_release_notes.html +0 -523
  37. data/guides/output/4_1_release_notes.html +0 -806
  38. data/guides/output/4_2_release_notes.html +0 -728
  39. data/guides/output/Gemfile +0 -6
  40. data/guides/output/_license.html +0 -226
  41. data/guides/output/_welcome.html +0 -233
  42. data/guides/output/action_controller_overview.html +0 -1335
  43. data/guides/output/action_mailer_basics.html +0 -928
  44. data/guides/output/action_view_overview.html +0 -1509
  45. data/guides/output/active_job_basics.html +0 -546
  46. data/guides/output/active_model_basics.html +0 -438
  47. data/guides/output/active_record_basics.html +0 -594
  48. data/guides/output/active_record_callbacks.html +0 -592
  49. data/guides/output/active_record_migrations.html +0 -1123
  50. data/guides/output/active_record_postgresql.html +0 -675
  51. data/guides/output/active_record_querying.html +0 -1796
  52. data/guides/output/active_record_validations.html +0 -1301
  53. data/guides/output/active_support_core_extensions.html +0 -3450
  54. data/guides/output/active_support_instrumentation.html +0 -1121
  55. data/guides/output/api_documentation_guidelines.html +0 -498
  56. data/guides/output/asset_pipeline.html +0 -1167
  57. data/guides/output/association_basics.html +0 -2086
  58. data/guides/output/caching_with_rails.html +0 -553
  59. data/guides/output/command_line.html +0 -791
  60. data/guides/output/configuring.html +0 -1055
  61. data/guides/output/contributing_to_ruby_on_rails.html +0 -657
  62. data/guides/output/credits.html +0 -284
  63. data/guides/output/debugging_rails_applications.html +0 -1014
  64. data/guides/output/development_dependencies_install.html +0 -478
  65. data/guides/output/engines.html +0 -1438
  66. data/guides/output/form_helpers.html +0 -1074
  67. data/guides/output/generators.html +0 -838
  68. data/guides/output/getting_started.html +0 -2092
  69. data/guides/output/i18n.html +0 -1198
  70. data/guides/output/images/akshaysurve.jpg +0 -0
  71. data/guides/output/images/belongs_to.png +0 -0
  72. data/guides/output/images/book_icon.gif +0 -0
  73. data/guides/output/images/bullet.gif +0 -0
  74. data/guides/output/images/chapters_icon.gif +0 -0
  75. data/guides/output/images/check_bullet.gif +0 -0
  76. data/guides/output/images/credits_pic_blank.gif +0 -0
  77. data/guides/output/images/csrf.png +0 -0
  78. data/guides/output/images/edge_badge.png +0 -0
  79. data/guides/output/images/favicon.ico +0 -0
  80. data/guides/output/images/feature_tile.gif +0 -0
  81. data/guides/output/images/footer_tile.gif +0 -0
  82. data/guides/output/images/fxn.png +0 -0
  83. data/guides/output/images/getting_started/article_with_comments.png +0 -0
  84. data/guides/output/images/getting_started/challenge.png +0 -0
  85. data/guides/output/images/getting_started/confirm_dialog.png +0 -0
  86. data/guides/output/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
  87. data/guides/output/images/getting_started/forbidden_attributes_for_new_post.png +0 -0
  88. data/guides/output/images/getting_started/form_with_errors.png +0 -0
  89. data/guides/output/images/getting_started/index_action_with_edit_link.png +0 -0
  90. data/guides/output/images/getting_started/new_article.png +0 -0
  91. data/guides/output/images/getting_started/new_post.png +0 -0
  92. data/guides/output/images/getting_started/post_with_comments.png +0 -0
  93. data/guides/output/images/getting_started/rails_welcome.png +0 -0
  94. data/guides/output/images/getting_started/routing_error_no_controller.png +0 -0
  95. data/guides/output/images/getting_started/routing_error_no_route_matches.png +0 -0
  96. data/guides/output/images/getting_started/show_action_for_articles.png +0 -0
  97. data/guides/output/images/getting_started/show_action_for_posts.png +0 -0
  98. data/guides/output/images/getting_started/template_is_missing_articles_new.png +0 -0
  99. data/guides/output/images/getting_started/template_is_missing_posts_new.png +0 -0
  100. data/guides/output/images/getting_started/undefined_method_post_path.png +0 -0
  101. data/guides/output/images/getting_started/unknown_action_create_for_articles.png +0 -0
  102. data/guides/output/images/getting_started/unknown_action_create_for_posts.png +0 -0
  103. data/guides/output/images/getting_started/unknown_action_new_for_articles.png +0 -0
  104. data/guides/output/images/getting_started/unknown_action_new_for_posts.png +0 -0
  105. data/guides/output/images/grey_bullet.gif +0 -0
  106. data/guides/output/images/habtm.png +0 -0
  107. data/guides/output/images/has_many.png +0 -0
  108. data/guides/output/images/has_many_through.png +0 -0
  109. data/guides/output/images/has_one.png +0 -0
  110. data/guides/output/images/has_one_through.png +0 -0
  111. data/guides/output/images/header_backdrop.png +0 -0
  112. data/guides/output/images/header_tile.gif +0 -0
  113. data/guides/output/images/i18n/demo_html_safe.png +0 -0
  114. data/guides/output/images/i18n/demo_localized_pirate.png +0 -0
  115. data/guides/output/images/i18n/demo_translated_en.png +0 -0
  116. data/guides/output/images/i18n/demo_translated_pirate.png +0 -0
  117. data/guides/output/images/i18n/demo_translation_missing.png +0 -0
  118. data/guides/output/images/i18n/demo_untranslated.png +0 -0
  119. data/guides/output/images/icons/README +0 -5
  120. data/guides/output/images/icons/callouts/1.png +0 -0
  121. data/guides/output/images/icons/callouts/10.png +0 -0
  122. data/guides/output/images/icons/callouts/11.png +0 -0
  123. data/guides/output/images/icons/callouts/12.png +0 -0
  124. data/guides/output/images/icons/callouts/13.png +0 -0
  125. data/guides/output/images/icons/callouts/14.png +0 -0
  126. data/guides/output/images/icons/callouts/15.png +0 -0
  127. data/guides/output/images/icons/callouts/2.png +0 -0
  128. data/guides/output/images/icons/callouts/3.png +0 -0
  129. data/guides/output/images/icons/callouts/4.png +0 -0
  130. data/guides/output/images/icons/callouts/5.png +0 -0
  131. data/guides/output/images/icons/callouts/6.png +0 -0
  132. data/guides/output/images/icons/callouts/7.png +0 -0
  133. data/guides/output/images/icons/callouts/8.png +0 -0
  134. data/guides/output/images/icons/callouts/9.png +0 -0
  135. data/guides/output/images/icons/caution.png +0 -0
  136. data/guides/output/images/icons/example.png +0 -0
  137. data/guides/output/images/icons/home.png +0 -0
  138. data/guides/output/images/icons/important.png +0 -0
  139. data/guides/output/images/icons/next.png +0 -0
  140. data/guides/output/images/icons/note.png +0 -0
  141. data/guides/output/images/icons/prev.png +0 -0
  142. data/guides/output/images/icons/tip.png +0 -0
  143. data/guides/output/images/icons/up.png +0 -0
  144. data/guides/output/images/icons/warning.png +0 -0
  145. data/guides/output/images/nav_arrow.gif +0 -0
  146. data/guides/output/images/oscardelben.jpg +0 -0
  147. data/guides/output/images/polymorphic.png +0 -0
  148. data/guides/output/images/radar.png +0 -0
  149. data/guides/output/images/rails4_features.png +0 -0
  150. data/guides/output/images/rails_guides_kindle_cover.jpg +0 -0
  151. data/guides/output/images/rails_guides_logo.gif +0 -0
  152. data/guides/output/images/rails_logo_remix.gif +0 -0
  153. data/guides/output/images/session_fixation.png +0 -0
  154. data/guides/output/images/tab_grey.gif +0 -0
  155. data/guides/output/images/tab_info.gif +0 -0
  156. data/guides/output/images/tab_note.gif +0 -0
  157. data/guides/output/images/tab_red.gif +0 -0
  158. data/guides/output/images/tab_yellow.gif +0 -0
  159. data/guides/output/images/tab_yellow.png +0 -0
  160. data/guides/output/images/vijaydev.jpg +0 -0
  161. data/guides/output/index.html +0 -354
  162. data/guides/output/initialization.html +0 -876
  163. data/guides/output/javascripts/guides.js +0 -59
  164. data/guides/output/javascripts/jquery.min.js +0 -4
  165. data/guides/output/javascripts/responsive-tables.js +0 -43
  166. data/guides/output/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
  167. data/guides/output/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
  168. data/guides/output/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
  169. data/guides/output/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
  170. data/guides/output/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
  171. data/guides/output/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
  172. data/guides/output/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
  173. data/guides/output/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
  174. data/guides/output/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
  175. data/guides/output/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
  176. data/guides/output/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
  177. data/guides/output/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
  178. data/guides/output/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
  179. data/guides/output/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
  180. data/guides/output/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
  181. data/guides/output/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
  182. data/guides/output/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
  183. data/guides/output/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
  184. data/guides/output/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
  185. data/guides/output/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
  186. data/guides/output/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
  187. data/guides/output/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
  188. data/guides/output/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
  189. data/guides/output/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
  190. data/guides/output/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
  191. data/guides/output/javascripts/syntaxhighlighter/shCore.js +0 -17
  192. data/guides/output/layout.html +0 -448
  193. data/guides/output/layouts_and_rendering.html +0 -1541
  194. data/guides/output/maintenance_policy.html +0 -257
  195. data/guides/output/migrations.html +0 -1360
  196. data/guides/output/nested_model_forms.html +0 -412
  197. data/guides/output/plugins.html +0 -644
  198. data/guides/output/rails_application_templates.html +0 -450
  199. data/guides/output/rails_on_rack.html +0 -547
  200. data/guides/output/routing.html +0 -1631
  201. data/guides/output/ruby_on_rails_guides_guidelines.html +0 -329
  202. data/guides/output/security.html +0 -935
  203. data/guides/output/stylesheets/fixes.css +0 -16
  204. data/guides/output/stylesheets/kindle.css +0 -11
  205. data/guides/output/stylesheets/main.css +0 -713
  206. data/guides/output/stylesheets/print.css +0 -52
  207. data/guides/output/stylesheets/reset.css +0 -43
  208. data/guides/output/stylesheets/responsive-tables.css +0 -50
  209. data/guides/output/stylesheets/style.css +0 -13
  210. data/guides/output/stylesheets/syntaxhighlighter/shCore.css +0 -226
  211. data/guides/output/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
  212. data/guides/output/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
  213. data/guides/output/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
  214. data/guides/output/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
  215. data/guides/output/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
  216. data/guides/output/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
  217. data/guides/output/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
  218. data/guides/output/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
  219. data/guides/output/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
  220. data/guides/output/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
  221. data/guides/output/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
  222. data/guides/output/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
  223. data/guides/output/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
  224. data/guides/output/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
  225. data/guides/output/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
  226. data/guides/output/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
  227. data/guides/output/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
  228. data/guides/output/testing.html +0 -1350
  229. data/guides/output/upgrading_ruby_on_rails.html +0 -1135
  230. data/guides/output/working_with_javascript_in_rails.html +0 -587
@@ -153,7 +153,7 @@ pipeline is enabled. It is set to true by default.
153
153
 
154
154
  * `config.assets.manifest` defines the full path to be used for the asset precompiler's manifest file. Defaults to a file named `manifest-<random>.json` in the `config.assets.prefix` directory within the public folder.
155
155
 
156
- * `config.assets.digest` enables the use of MD5 fingerprints in asset names. Set to `true` by default in `production.rb`.
156
+ * `config.assets.digest` enables the use of MD5 fingerprints in asset names. Set to `true` by default in `production.rb` and `development.rb`.
157
157
 
158
158
  * `config.assets.debug` disables the concatenation and compression of assets. Set to `true` by default in `development.rb`.
159
159
 
@@ -214,7 +214,7 @@ Every Rails application comes with a standard set of middleware which it uses in
214
214
  * `ActionDispatch::Flash` sets up the `flash` keys. Only available if `config.action_controller.session_store` is set to a value.
215
215
  * `ActionDispatch::ParamsParser` parses out parameters from the request into `params`.
216
216
  * `Rack::MethodOverride` allows the method to be overridden if `params[:_method]` is set. This is the middleware which supports the PATCH, PUT, and DELETE HTTP method types.
217
- * `ActionDispatch::Head` converts HEAD requests to GET requests and serves them as so.
217
+ * `Rack::Head` converts HEAD requests to GET requests and serves them as so.
218
218
 
219
219
  Besides these usual middleware, you can add your own by using the `config.middleware.use` method:
220
220
 
@@ -225,13 +225,13 @@ config.middleware.use Magical::Unicorns
225
225
  This will put the `Magical::Unicorns` middleware on the end of the stack. You can use `insert_before` if you wish to add a middleware before another.
226
226
 
227
227
  ```ruby
228
- config.middleware.insert_before ActionDispatch::Head, Magical::Unicorns
228
+ config.middleware.insert_before Rack::Head, Magical::Unicorns
229
229
  ```
230
230
 
231
231
  There's also `insert_after` which will insert a middleware after another:
232
232
 
233
233
  ```ruby
234
- config.middleware.insert_after ActionDispatch::Head, Magical::Unicorns
234
+ config.middleware.insert_after Rack::Head, Magical::Unicorns
235
235
  ```
236
236
 
237
237
  Middlewares can also be completely swapped out and replaced with others:
@@ -171,7 +171,6 @@
171
171
  name: Ruby on Rails 4.2 Release Notes
172
172
  url: 4_2_release_notes.html
173
173
  description: Release notes for Rails 4.2.
174
- work_in_progress: true
175
174
  -
176
175
  name: Ruby on Rails 4.1 Release Notes
177
176
  url: 4_1_release_notes.html
@@ -32,7 +32,7 @@ directory structure, and are both generated using the `rails plugin new`
32
32
  generator. The difference is that an engine is considered a "full plugin" by
33
33
  Rails (as indicated by the `--full` option that's passed to the generator
34
34
  command). We'll actually be using the `--mountable` option here, which includes
35
- all the features of `--full`, and then some. This guide will refer to these
35
+ all the features of `--full`, and then some. This guide will refer to these
36
36
  "full plugins" simply as "engines" throughout. An engine **can** be a plugin,
37
37
  and a plugin **can** be an engine.
38
38
 
@@ -1036,31 +1036,42 @@ functionality, especially controllers. This means that if you were to make a
1036
1036
  typical `GET` to a controller in a controller's functional test like this:
1037
1037
 
1038
1038
  ```ruby
1039
- get :index
1039
+ module Blorgh
1040
+ class FooControllerTest < ActionController::TestCase
1041
+ def test_index
1042
+ get :index
1043
+ ...
1044
+ end
1045
+ end
1046
+ end
1040
1047
  ```
1041
1048
 
1042
1049
  It may not function correctly. This is because the application doesn't know how
1043
1050
  to route these requests to the engine unless you explicitly tell it **how**. To
1044
- do this, you must also pass the `:use_route` option as a parameter on these
1045
- requests:
1051
+ do this, you must set the `@routes` instance variable to the engine's route set
1052
+ in your setup code:
1046
1053
 
1047
1054
  ```ruby
1048
- get :index, use_route: :blorgh
1055
+ module Blorgh
1056
+ class FooControllerTest < ActionController::TestCase
1057
+ setup do
1058
+ @routes = Engine.routes
1059
+ end
1060
+
1061
+ def test_index
1062
+ get :index
1063
+ ...
1064
+ end
1065
+ end
1066
+ end
1049
1067
  ```
1050
1068
 
1051
1069
  This tells the application that you still want to perform a `GET` request to the
1052
1070
  `index` action of this controller, but you want to use the engine's route to get
1053
1071
  there, rather than the application's one.
1054
1072
 
1055
- Another way to do this is to assign the `@routes` instance variable to `Engine.routes` in your test setup:
1056
-
1057
- ```ruby
1058
- setup do
1059
- @routes = Engine.routes
1060
- end
1061
- ```
1062
-
1063
- This will also ensure url helpers for the engine will work as expected in your tests.
1073
+ This also ensures that the engine's URL helpers will work as expected in your
1074
+ tests.
1064
1075
 
1065
1076
  Improving engine functionality
1066
1077
  ------------------------------
@@ -1155,7 +1166,7 @@ end
1155
1166
 
1156
1167
  Using `Class#class_eval` is great for simple adjustments, but for more complex
1157
1168
  class modifications, you might want to consider using [`ActiveSupport::Concern`]
1158
- (http://edgeapi.rubyonrails.org/classes/ActiveSupport/Concern.html).
1169
+ (http://api.rubyonrails.org/classes/ActiveSupport/Concern.html).
1159
1170
  ActiveSupport::Concern manages load order of interlinked dependent modules and
1160
1171
  classes at run time allowing you to significantly modularize your code.
1161
1172
 
@@ -96,7 +96,15 @@ form_tag({controller: "people", action: "search"}, method: "get", class: "nifty_
96
96
 
97
97
  ### Helpers for Generating Form Elements
98
98
 
99
- Rails provides a series of helpers for generating form elements such as checkboxes, text fields, and radio buttons. These basic helpers, with names ending in "_tag" (such as `text_field_tag` and `check_box_tag`), generate just a single `<input>` element. The first parameter to these is always the name of the input. When the form is submitted, the name will be passed along with the form data, and will make its way to the `params` hash in the controller with the value entered by the user for that field. For example, if the form contains `<%= text_field_tag(:query) %>`, then you would be able to get the value of this field in the controller with `params[:query]`.
99
+ Rails provides a series of helpers for generating form elements such as
100
+ checkboxes, text fields, and radio buttons. These basic helpers, with names
101
+ ending in `_tag` (such as `text_field_tag` and `check_box_tag`), generate just a
102
+ single `<input>` element. The first parameter to these is always the name of the
103
+ input. When the form is submitted, the name will be passed along with the form
104
+ data, and will make its way to the `params` hash in the controller with the
105
+ value entered by the user for that field. For example, if the form contains `<%=
106
+ text_field_tag(:query) %>`, then you would be able to get the value of this
107
+ field in the controller with `params[:query]`.
100
108
 
101
109
  When naming inputs, Rails uses certain conventions that make it possible to submit parameters with non-scalar values such as arrays or hashes, which will also be accessible in `params`. You can read more about them in [chapter 7 of this guide](#understanding-parameter-naming-conventions). For details on the precise usage of these helpers, please refer to the [API documentation](http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html).
102
110
 
@@ -506,7 +514,7 @@ As the name implies, this only generates option tags. To generate a working sele
506
514
  <%= collection_select(:person, :city_id, City.all, :id, :name) %>
507
515
  ```
508
516
 
509
- As with other helpers, if you were to use the collection_select helper on a form builder scoped to the @person object, the syntax would be:
517
+ As with other helpers, if you were to use the `collection_select` helper on a form builder scoped to the `@person` object, the syntax would be:
510
518
 
511
519
  ```erb
512
520
  <%= f.collection_select(:city_id, City.all, :id, :name) %>
@@ -101,7 +101,7 @@ If you don't have Ruby installed have a look at
101
101
  install Ruby on your platform.
102
102
 
103
103
  Many popular UNIX-like OSes ship with an acceptable version of SQLite3. Windows
104
- users and others can find installation instructions at [the SQLite3 website](https://www.sqlite.org).
104
+ users and others can find installation instructions at the [SQLite3 website](https://www.sqlite.org).
105
105
  Verify that it is correctly installed and in your PATH:
106
106
 
107
107
  ```bash
@@ -165,7 +165,7 @@ of the files and folders that Rails created by default:
165
165
  |config/|Configure your application's routes, database, and more. This is covered in more detail in [Configuring Rails Applications](configuring.html).|
166
166
  |config.ru|Rack configuration for Rack based servers used to start the application.|
167
167
  |db/|Contains your current database schema, as well as the database migrations.|
168
- |Gemfile<br>Gemfile.lock|These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem. For more information about Bundler, see [the Bundler website](http://bundler.io).|
168
+ |Gemfile<br>Gemfile.lock|These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem. For more information about Bundler, see the [Bundler website](http://bundler.io).|
169
169
  |lib/|Extended modules for your application.|
170
170
  |log/|Application log files.|
171
171
  |public/|The only folder seen by the world as-is. Contains static files and compiled assets.|
@@ -195,8 +195,8 @@ TIP: Compiling CoffeeScript and JavaScript asset compression requires you
195
195
  have a JavaScript runtime available on your system, in the absence
196
196
  of a runtime you will see an `execjs` error during asset compilation.
197
197
  Usually Mac OS X and Windows come with a JavaScript runtime installed.
198
- Rails adds the `therubyracer` gem to the generated `Gemfile` in a
199
- commented line for new apps and you can uncomment if you need it.
198
+ Rails adds the `therubyracer` gem to the generated `Gemfile` in a
199
+ commented line for new apps and you can uncomment if you need it.
200
200
  `therubyrhino` is the recommended runtime for JRuby users and is added by
201
201
  default to the `Gemfile` in apps generated under JRuby. You can investigate
202
202
  all the supported runtimes at [ExecJS](https://github.com/sstephenson/execjs#readme).
@@ -338,8 +338,8 @@ You can create, read, update and destroy items for a resource and these
338
338
  operations are referred to as _CRUD_ operations.
339
339
 
340
340
  Rails provides a `resources` method which can be used to declare a standard REST
341
- resource. Here's what `config/routes.rb` should look like after the
342
- _article resource_ is declared.
341
+ resource. You need to add the _article resource_ to the
342
+ `config/routes.rb` as follows:
343
343
 
344
344
  ```ruby
345
345
  Rails.application.routes.draw do
@@ -833,7 +833,7 @@ class ArticlesController < ApplicationController
833
833
 
834
834
  A couple of things to note. We use `Article.find` to find the article we're
835
835
  interested in, passing in `params[:id]` to get the `:id` parameter from the
836
- request. We also use an instance variable (prefixed by `@`) to hold a
836
+ request. We also use an instance variable (prefixed with `@`) to hold a
837
837
  reference to the article object. We do this because Rails will pass all instance
838
838
  variables to the view.
839
839
 
@@ -1279,7 +1279,7 @@ And here's how our app looks so far:
1279
1279
  Our `edit` page looks very similar to the `new` page; in fact, they
1280
1280
  both share the same code for displaying the form. Let's remove this
1281
1281
  duplication by using a view partial. By convention, partial files are
1282
- prefixed by an underscore.
1282
+ prefixed with an underscore.
1283
1283
 
1284
1284
  TIP: You can read more about partials in the
1285
1285
  [Layouts and Rendering in Rails](layouts_and_rendering.html) guide.
@@ -2049,7 +2049,7 @@ command-line utility:
2049
2049
  in your web browser to explore the API documentation.
2050
2050
 
2051
2051
  TIP: To be able to generate the Rails Guides locally with the `doc:guides` rake
2052
- task you need to install the RedCloth gem. Add it to your `Gemfile` and run
2052
+ task you need to install the RedCloth and Nokogiri gems. Add it to your `Gemfile` and run
2053
2053
  `bundle install` and you're ready to go.
2054
2054
 
2055
2055
  Configuration Gotchas
@@ -277,7 +277,7 @@ Much of Action Controller's functionality is implemented as Middlewares. The fol
277
277
 
278
278
  **`ActionDispatch::Callbacks`**
279
279
 
280
- * Runs the prepare callbacks before serving the request.
280
+ * Provides callbacks to be executed before and after dispatching the request.
281
281
 
282
282
  **`ActiveRecord::Migration::CheckPending`**
283
283
 
@@ -307,7 +307,7 @@ Much of Action Controller's functionality is implemented as Middlewares. The fol
307
307
 
308
308
  * Parses out parameters from the request into `params`.
309
309
 
310
- **`ActionDispatch::Head`**
310
+ **`Rack::Head`**
311
311
 
312
312
  * Converts HEAD requests to `GET` requests and serves them as so.
313
313
 
@@ -54,6 +54,7 @@ API Documentation Guidelines
54
54
  The guides and the API should be coherent and consistent where appropriate. In particular, these sections of the [API Documentation Guidelines](api_documentation_guidelines.html) also apply to the guides:
55
55
 
56
56
  * [Wording](api_documentation_guidelines.html#wording)
57
+ * [English](api_documentation_guidelines.html#english)
57
58
  * [Example Code](api_documentation_guidelines.html#example-code)
58
59
  * [Filenames](api_documentation_guidelines.html#file-names)
59
60
  * [Fonts](api_documentation_guidelines.html#fonts)
@@ -362,7 +362,7 @@ Refer to the Injection section for countermeasures against XSS. It is _recommend
362
362
 
363
363
  **CSRF** Cross-Site Request Forgery (CSRF), also known as Cross-Site Reference Forgery (XSRF), is a gigantic attack method, it allows the attacker to do everything the administrator or Intranet user may do. As you have already seen above how CSRF works, here are a few examples of what attackers can do in the Intranet or admin interface.
364
364
 
365
- A real-world example is a [router reconfiguration by CSRF](http://www.h-online.com/security/Symantec-reports-first-active-attack-on-a-DSL-router--/news/102352). The attackers sent a malicious e-mail, with CSRF in it, to Mexican users. The e-mail claimed there was an e-card waiting for them, but it also contained an image tag that resulted in a HTTP-GET request to reconfigure the user's router (which is a popular model in Mexico). The request changed the DNS-settings so that requests to a Mexico-based banking site would be mapped to the attacker's site. Everyone who accessed the banking site through that router saw the attacker's fake web site and had their credentials stolen.
365
+ A real-world example is a [router reconfiguration by CSRF](http://www.h-online.com/security/news/item/Symantec-reports-first-active-attack-on-a-DSL-router-735883.html). The attackers sent a malicious e-mail, with CSRF in it, to Mexican users. The e-mail claimed there was an e-card waiting for them, but it also contained an image tag that resulted in a HTTP-GET request to reconfigure the user's router (which is a popular model in Mexico). The request changed the DNS-settings so that requests to a Mexico-based banking site would be mapped to the attacker's site. Everyone who accessed the banking site through that router saw the attacker's fake web site and had their credentials stolen.
366
366
 
367
367
  Another example changed Google Adsense's e-mail address and password by. If the victim was logged into Google Adsense, the administration interface for Google advertisements campaigns, an attacker could change their credentials.

368
368
 
@@ -82,7 +82,7 @@ Each fixture is given a name followed by an indented list of colon-separated key
82
82
 
83
83
  If you are working with [associations](/association_basics.html), you can simply
84
84
  define a reference node between two different fixtures. Here's an example with
85
- a belongs_to/has_many association:
85
+ a `belongs_to`/`has_many` association:
86
86
 
87
87
  ```yaml
88
88
  # In fixtures/categories.yml
@@ -728,7 +728,7 @@ class UserFlowsTest < ActionDispatch::IntegrationTest
728
728
  https!(false)
729
729
  get "/articles/all"
730
730
  assert_response :success
731
- assert assigns(:products)
731
+ assert assigns(:articles)
732
732
  end
733
733
  end
734
734
  ```
@@ -785,14 +785,13 @@ end
785
785
  Rake Tasks for Running your Tests
786
786
  ---------------------------------
787
787
 
788
- You don't need to set up and run your tests by hand on a test-by-test basis.
789
- Rails comes with a number of commands to help in testing.
790
- The table below lists all commands that come along in the default Rakefile
791
- when you initiate a Rails project.
788
+ Rails comes with a number of built-in rake tasks to help with testing. The
789
+ table below lists the commands included in the default Rakefile when a Rails
790
+ project is created.
792
791
 
793
792
  | Tasks | Description |
794
793
  | ----------------------- | ----------- |
795
- | `rake test` | Runs all unit, functional and integration tests. You can also simply run `rake` as Rails will run all the tests by default |
794
+ | `rake test` | Runs all tests in the `test` folder. You can also simply run `rake` as Rails will run all the tests by default |
796
795
  | `rake test:controllers` | Runs all the controller tests from `test/controllers` |
797
796
  | `rake test:functionals` | Runs all the functional tests from `test/controllers`, `test/mailers`, and `test/functional` |
798
797
  | `rake test:helpers` | Runs all the helper tests from `test/helpers` |
@@ -801,11 +800,10 @@ when you initiate a Rails project.
801
800
  | `rake test:mailers` | Runs all the mailer tests from `test/mailers` |
802
801
  | `rake test:models` | Runs all the model tests from `test/models` |
803
802
  | `rake test:units` | Runs all the unit tests from `test/models`, `test/helpers`, and `test/unit` |
804
- | `rake test:all` | Runs all tests quickly by merging all types and not resetting db |
805
- | `rake test:all:db` | Runs all tests quickly by merging all types and resetting db |
803
+ | `rake test:db` | Runs all tests in the `test` folder and resets the db |
806
804
 
807
805
 
808
- Brief Note About `Minitest`
806
+ A Brief Note About Minitest
809
807
  -----------------------------
810
808
 
811
809
  Ruby ships with a vast Standard Library for all common use-cases including testing. Since version 1.9, Ruby provides `Minitest`, a framework for testing. All the basic assertions such as `assert_equal` discussed above are actually defined in `Minitest::Assertions`. The classes `ActiveSupport::TestCase`, `ActionController::TestCase`, `ActionMailer::TestCase`, `ActionView::TestCase` and `ActionDispatch::IntegrationTest` - which we have been inheriting in our test classes - include `Minitest::Assertions`, allowing us to use all of the basic assertions in our tests.
@@ -902,11 +900,17 @@ end
902
900
  Testing Routes
903
901
  --------------
904
902
 
905
- Like everything else in your Rails application, it is recommended that you test your routes. An example test for a route in the default `show` action of `Articles` controller above should look like:
903
+ Like everything else in your Rails application, it is recommended that you test your routes. Below are example tests for the routes of default `show` and `create` action of `Articles` controller above and it should look like:
906
904
 
907
905
  ```ruby
908
- test "should route to article" do
909
- assert_routing '/articles/1', {controller: "articles", action: "show", id: "1"}
906
+ class ArticleRoutesTest < ActionController::TestCase
907
+ test "should route to article" do
908
+ assert_routing '/articles/1', { controller: "articles", action: "show", id: "1" }
909
+ end
910
+
911
+ test "should route to create article" do
912
+ assert_routing({ method: 'post', path: '/articles' }, { controller: "articles", action: "create" })
913
+ end
910
914
  end
911
915
  ```
912
916
 
@@ -1043,6 +1047,68 @@ end
1043
1047
  Moreover, since the test class extends from `ActionView::TestCase`, you have
1044
1048
  access to Rails' helper methods such as `link_to` or `pluralize`.
1045
1049
 
1050
+ Testing Jobs
1051
+ ------------
1052
+
1053
+ Since your custom jobs can be queued at different levels inside your application,
1054
+ you'll need to test both jobs themselves (their behavior when they get enqueued)
1055
+ and that other entities correctly enqueue them.
1056
+
1057
+ ### A Basic Test Case
1058
+
1059
+ By default, when you generate a job, an associated test will be generated as well
1060
+ under the `test/jobs` directory. Here's an example test with a billing job:
1061
+
1062
+ ```ruby
1063
+ require 'test_helper'
1064
+
1065
+ class BillingJobTest < ActiveJob::TestCase
1066
+ test 'that account is charged' do
1067
+ BillingJob.perform_now(account, product)
1068
+ assert account.reload.charged_for?(product)
1069
+ end
1070
+ end
1071
+ ```
1072
+
1073
+ This test is pretty simple and only asserts that the job get the work done
1074
+ as expected.
1075
+
1076
+ By default, `ActiveJob::TestCase` will set the queue adapter to `:test` so that
1077
+ your jobs are performed inline. It will also ensure that all previously performed
1078
+ and enqueued jobs are cleared before any test run so you can safely assume that
1079
+ no jobs have already been executed in the scope of each test.
1080
+
1081
+ ### Custom Assertions And Testing Jobs Inside Other Components
1082
+
1083
+ Active Job ships with a bunch of custom assertions that can be used to lessen
1084
+ the verbosity of tests:
1085
+
1086
+ | Assertion | Purpose |
1087
+ | -------------------------------------- | ------- |
1088
+ | `assert_enqueued_jobs(number)` | Asserts that the number of enqueued jobs matches the given number. |
1089
+ | `assert_performed_jobs(number)` | Asserts that the number of performed jobs matches the given number. |
1090
+ | `assert_no_enqueued_jobs { ... }` | Asserts that no jobs have been enqueued. |
1091
+ | `assert_no_performed_jobs { ... }` | Asserts that no jobs have been performed. |
1092
+ | `assert_enqueued_with([args]) { ... }` | Asserts that the job passed in the block has been enqueued with the given arguments. |
1093
+ | `assert_performed_with([args]) { ... }`| Asserts that the job passed in the block has been performed with the given arguments. |
1094
+
1095
+ It's a good practice to ensure that your jobs correctly get enqueued or performed
1096
+ wherever you invoke them (e.g. inside your controllers). This is precisely where
1097
+ the custom assertions provided by Active Job are pretty useful. For instance,
1098
+ within a model:
1099
+
1100
+ ```ruby
1101
+ require 'test_helper'
1102
+
1103
+ class ProductTest < ActiveSupport::TestCase
1104
+ test 'billing job scheduling' do
1105
+ assert_enqueued_with(job: BillingJob) do
1106
+ product.charge(account)
1107
+ end
1108
+ end
1109
+ end
1110
+ ```
1111
+
1046
1112
  Other Testing Approaches
1047
1113
  ------------------------
1048
1114
 
@@ -1054,3 +1120,4 @@ The built-in `minitest` based testing is not the only way to test Rails applicat
1054
1120
  * [MiniTest::Spec Rails](https://github.com/metaskills/minitest-spec-rails), use the MiniTest::Spec DSL within your rails tests.
1055
1121
  * [Shoulda](http://www.thoughtbot.com/projects/shoulda), an extension to `test/unit` with additional helpers, macros, and assertions.
1056
1122
  * [RSpec](http://relishapp.com/rspec), a behavior-driven development framework
1123
+ * [Capybara](http://jnicklas.github.com/capybara/), Acceptance test framework for web applications
@@ -50,22 +50,10 @@ Don't forget to review the difference, to see if there were any unexpected chang
50
50
  Upgrading from Rails 4.1 to Rails 4.2
51
51
  -------------------------------------
52
52
 
53
- NOTE: This section is a work in progress, please help to improve this by sending
54
- a [pull request](https://github.com/rails/rails/edit/master/guides/source/upgrading_ruby_on_rails.md).
55
-
56
53
  ### Web Console
57
54
 
58
55
  First, add `gem 'web-console', '~> 2.0'` to the `:development` group in your Gemfile and run `bundle install` (it won't have been included when you upgraded Rails). Once it's been installed, you can simply drop a reference to the console helper (i.e., `<%= console %>`) into any view you want to enable it for. A console will also be provided on any error page you view in your development environment.
59
56
 
60
- Additionally, you can tell Rails to automatically mount a VT100-compatible console on a predetermined path by setting the appropriate configuration flags in your development config:
61
-
62
- ```ruby
63
- # config/environments/development.rb
64
-
65
- config.web_console.automount = true
66
- config.web_console.default_mount_path = '/terminal' # Optional, defaults to /console
67
- ```
68
-
69
57
  ### Responders
70
58
 
71
59
  `respond_with` and the class-level `respond_to` methods have been extracted to the `responders` gem. To use them, simply add `gem 'responders', '~> 2.0'` to your Gemfile. Calls to `respond_with` and `respond_to` (again, at the class level) will no longer work without having included the `responders` gem in your dependencies:
@@ -145,6 +133,18 @@ assigning `nil` to a serialized attribute will save it to the database
145
133
  as `NULL` instead of passing the `nil` value through the coder (e.g. `"null"`
146
134
  when using the `JSON` coder).
147
135
 
136
+ ### Production log level
137
+
138
+ In Rails 5, the default log level for the production environment will be changed
139
+ to `:debug` (from `:info`). To preserve the current default, add the following
140
+ line to your `production.rb`:
141
+
142
+ ```ruby
143
+ # Set to `:info` to match the current default, or set to `:debug` to opt-into
144
+ # the future default.
145
+ config.log_level = :info
146
+ ```
147
+
148
148
  ### `after_bundle` in Rails templates
149
149
 
150
150
  If you have a Rails template that adds all the files in version control, it
@@ -181,7 +181,7 @@ end
181
181
 
182
182
  There's a new choice for sanitizing HTML fragments in your applications. The
183
183
  venerable html-scanner approach is now officially being deprecated in favor of
184
- [`Rails Html Sanitizer`](https://github.com/rails/rails-html-sanitizer).
184
+ [`Rails HTML Sanitizer`](https://github.com/rails/rails-html-sanitizer).
185
185
 
186
186
  This means the methods `sanitize`, `sanitize_css`, `strip_tags` and
187
187
  `strip_links` are backed by a new implementation.
@@ -207,8 +207,11 @@ gem 'rails-deprecated_sanitizer'
207
207
  ```
208
208
 
209
209
  ### Rails DOM Testing
210
- The [`TagAssertions` module](http://api.rubyonrails.org/classes/ActionDispatch/Assertions/TagAssertions.html) (containing methods such as `assert_tag`), [has been deprecated](https://github.com/rails/rails/blob/6061472b8c310158a2a2e8e9a6b81a1aef6b60fe/actionpack/lib/action_dispatch/testing/assertions/dom.rb) in favor of the `assert_select` methods from the `SelectorAssertions` module, which has been extracted into the [rails-dom-testing gem](https://github.com/rails/rails-dom-testing).
210
+ The [`TagAssertions` module](http://api.rubyonrails.org/classes/ActionDispatch/Assertions/TagAssertions.html) (containing methods such as `assert_tag`), [has been deprecated](https://github.com/rails/rails/blob/6061472b8c310158a2a2e8e9a6b81a1aef6b60fe/actionpack/lib/action_dispatch/testing/assertions/dom.rb) in favor of the `assert_select` methods from the `SelectorAssertions` module, which has been extracted into the [rails-dom-testing gem](https://github.com/rails/rails-dom-testing).
211
+
211
212
 
213
+ ### Masked Authenticity Tokens
214
+ In order to mitigate SSL attacks, `form_authenticity_token` is now masked so that it varies with each request. Thus, tokens are validated by unmasking and then decrypting. As a result, any strategies for verifying requests from non-rails forms that relied on a static session CSRF token have to take this into account.
212
215
 
213
216
  Upgrading from Rails 4.0 to Rails 4.1
214
217
  -------------------------------------
@@ -233,7 +236,7 @@ will now trigger CSRF protection. Switch to
233
236
  xhr :get, :index, format: :js
234
237
  ```
235
238
 
236
- to explicitly test an XmlHttpRequest.
239
+ to explicitly test an `XmlHttpRequest`.
237
240
 
238
241
  If you really mean to load JavaScript from remote `<script>` tags, skip CSRF
239
242
  protection on that action.
@@ -418,7 +421,7 @@ class ReadOnlyModel < ActiveRecord::Base
418
421
  end
419
422
  ```
420
423
 
421
- This behaviour was never intentionally supported. Due to a change in the internals
424
+ This behavior was never intentionally supported. Due to a change in the internals
422
425
  of `ActiveSupport::Callbacks`, this is no longer allowed in Rails 4.1. Using a
423
426
  `return` statement in an inline callback block causes a `LocalJumpError` to
424
427
  be raised when the callback is executed.
@@ -588,7 +591,7 @@ response body, you should be using `render :plain` as most browsers will escape
588
591
  unsafe content in the response for you.
589
592
 
590
593
  We will be deprecating the use of `render :text` in a future version. So please
591
- start using the more precise `:plain:`, `:html`, and `:body` options instead.
594
+ start using the more precise `:plain`, `:html`, and `:body` options instead.
592
595
  Using `render :text` may pose a security risk, as the content is sent as
593
596
  `text/html`.
594
597
 
@@ -767,7 +770,7 @@ this gem such as `whitelist_attributes` or `mass_assignment_sanitizer` options.
767
770
  * Rails 4.0 has deprecated `ActiveRecord::TestCase` in favor of `ActiveSupport::TestCase`.
768
771
 
769
772
  * Rails 4.0 has deprecated the old-style hash based finder API. This means that
770
- methods which previously accepted "finder options" no longer do.
773
+ methods which previously accepted "finder options" no longer do. For example, `Book.find(:all, conditions: { name: '1984' })` has been deprecated in favor of `Book.where(name: '1984')`
771
774
 
772
775
  * All dynamic methods except for `find_by_...` and `find_by_...!` are deprecated.
773
776
  Here's how you can handle the changes:
@@ -792,7 +795,7 @@ Rails 4.0 extracted Active Resource to its own gem. If you still need the featur
792
795
 
793
796
  * Rails 4.0 has changed how errors attach with the `ActiveModel::Validations::ConfirmationValidator`. Now when confirmation validations fail, the error will be attached to `:#{attribute}_confirmation` instead of `attribute`.
794
797
 
795
- * Rails 4.0 has changed `ActiveModel::Serializers::JSON.include_root_in_json` default value to `false`. Now, Active Model Serializers and Active Record objects have the same default behaviour. This means that you can comment or remove the following option in the `config/initializers/wrap_parameters.rb` file:
798
+ * Rails 4.0 has changed `ActiveModel::Serializers::JSON.include_root_in_json` default value to `false`. Now, Active Model Serializers and Active Record objects have the same default behavior. This means that you can comment or remove the following option in the `config/initializers/wrap_parameters.rb` file:
796
799
 
797
800
  ```ruby
798
801
  # Disable root element in JSON by default.
@@ -918,7 +921,7 @@ The order in which helpers from more than one directory are loaded has changed i
918
921
 
919
922
  ### Active Record Observer and Action Controller Sweeper
920
923
 
921
- Active Record Observer and Action Controller Sweeper have been extracted to the `rails-observers` gem. You will need to add the `rails-observers` gem if you require these features.
924
+ `ActiveRecord::Observer` and `ActionController::Caching::Sweeper` have been extracted to the `rails-observers` gem. You will need to add the `rails-observers` gem if you require these features.
922
925
 
923
926
  ### sprockets-rails
924
927