aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source
diff options
context:
space:
mode:
Diffstat (limited to 'guides/source')
-rw-r--r--guides/source/5_0_release_notes.md6
-rw-r--r--guides/source/active_record_postgresql.md2
-rw-r--r--guides/source/api_app.md70
-rw-r--r--guides/source/asset_pipeline.md17
-rw-r--r--guides/source/command_line.md6
-rw-r--r--guides/source/configuring.md4
-rw-r--r--guides/source/contributing_to_ruby_on_rails.md10
-rw-r--r--guides/source/documents.yaml5
-rw-r--r--guides/source/getting_started.md6
-rw-r--r--guides/source/initialization.md2
-rw-r--r--guides/source/rails_on_rack.md10
-rw-r--r--guides/source/routing.md17
-rw-r--r--guides/source/security.md2
-rw-r--r--guides/source/testing.md47
-rw-r--r--guides/source/upgrading_ruby_on_rails.md2
15 files changed, 115 insertions, 91 deletions
diff --git a/guides/source/5_0_release_notes.md b/guides/source/5_0_release_notes.md
index 2650384df3..4e8252f85b 100644
--- a/guides/source/5_0_release_notes.md
+++ b/guides/source/5_0_release_notes.md
@@ -253,6 +253,9 @@ Please refer to the [Changelog][action-pack] for detailed changes.
`ActionDispatch::IntegrationTest` instead.
([commit](https://github.com/rails/rails/commit/4414c5d1795e815b102571425974a8b1d46d932d))
+* Rails will only generate "weak", instead of strong ETags.
+ ([Pull Request](https://github.com/rails/rails/pull/17573))
+
Action View
-------------
@@ -378,6 +381,9 @@ Please refer to the [Changelog][active-record] for detailed changes.
* Removed support for the `protected_attributes` gem.
([commit](https://github.com/rails/rails/commit/f4fbc0301021f13ae05c8e941c8efc4ae351fdf9))
+* Removed support for PostgreSQL versions below 9.1.
+ ([Pull Request](https://github.com/rails/rails/pull/23434))
+
### Deprecations
* Deprecated passing a class as a value in a query. Users should pass strings
diff --git a/guides/source/active_record_postgresql.md b/guides/source/active_record_postgresql.md
index 68c6a77882..5eb19f5214 100644
--- a/guides/source/active_record_postgresql.md
+++ b/guides/source/active_record_postgresql.md
@@ -14,7 +14,7 @@ After reading this guide, you will know:
--------------------------------------------------------------------------------
-In order to use the PostgreSQL adapter you need to have at least version 8.2
+In order to use the PostgreSQL adapter you need to have at least version 9.1
installed. Older versions are not supported.
To get started with PostgreSQL have a look at the
diff --git a/guides/source/api_app.md b/guides/source/api_app.md
index 86baa9ee84..64b6bb64f2 100644
--- a/guides/source/api_app.md
+++ b/guides/source/api_app.md
@@ -8,7 +8,7 @@ In this guide you will learn:
* What Rails provides for API-only applications
* How to configure Rails to start without any browser features
-* How to decide which middlewares you will want to include
+* How to decide which middleware you will want to include
* How to decide which modules to use in your controller
--------------------------------------------------------------------------------
@@ -44,11 +44,11 @@ using Rails is: "isn't using Rails to spit out some JSON overkill? Shouldn't I
just use something like Sinatra?".
For very simple APIs, this may be true. However, even in very HTML-heavy
-applications, most of an application's logic is actually outside of the view
+applications, most of an application's logic lives outside of the view
layer.
The reason most people use Rails is that it provides a set of defaults that
-allows us to get up and running quickly without having to make a lot of trivial
+allows developers to get up and running quickly, without having to make a lot of trivial
decisions.
Let's take a look at some of the things that Rails provides out of the box that are
@@ -86,7 +86,7 @@ Handled at the middleware layer:
and return just the headers on the way out. This makes `HEAD` work reliably in
all Rails APIs.
-While you could obviously build these up in terms of existing Rack middlewares,
+While you could obviously build these up in terms of existing Rack middleware,
this list demonstrates that the default Rails middleware stack provides a lot
of value, even if you're "just generating JSON".
@@ -97,7 +97,7 @@ Handled at the Action Pack layer:
means not having to spend time thinking about how to model your API in terms
of HTTP.
- URL Generation: The flip side of routing is URL generation. A good API based
- on HTTP includes URLs (see [the GitHub gist API](http://developer.github.com/v3/gists/)
+ on HTTP includes URLs (see [the GitHub Gist API](http://developer.github.com/v3/gists/)
for an example).
- Header and Redirection Responses: `head :no_content` and
`redirect_to user_url(current_user)` come in handy. Sure, you could manually
@@ -126,7 +126,7 @@ when configuring Active Record.
**The short version is**: you may not have thought about which parts of Rails
are still applicable even if you remove the view layer, but the answer turns out
-to be "most of it".
+to be most of it.
The Basic Configuration
-----------------------
@@ -143,11 +143,11 @@ $ rails new my_api --api
This will do three main things for you:
-- Configure your application to start with a more limited set of middlewares
+- Configure your application to start with a more limited set of middleware
than normal. Specifically, it will not include any middleware primarily useful
for browser applications (like cookies support) by default.
- Make `ApplicationController` inherit from `ActionController::API` instead of
- `ActionController::Base`. As with middlewares, this will leave out any Action
+ `ActionController::Base`. As with middleware, this will leave out any Action
Controller modules that provide functionalities primarily used by browser
applications.
- Configure the generators to skip generating views, helpers and assets when
@@ -185,18 +185,18 @@ class ApplicationController < ActionController::API
end
```
-Choosing Middlewares
+Choosing Middleware
--------------------
-An API application comes with the following middlewares by default:
+An API application comes with the following middleware by default:
- `Rack::Sendfile`
- `ActionDispatch::Static`
-- `Rack::Lock`
+- `ActionDispatch::LoadInterlock`
- `ActiveSupport::Cache::Strategy::LocalCache::Middleware`
+- `Rack::Runtime`
- `ActionDispatch::RequestId`
- `Rails::Rack::Logger`
-- `Rack::Runtime`
- `ActionDispatch::ShowExceptions`
- `ActionDispatch::DebugExceptions`
- `ActionDispatch::RemoteIp`
@@ -206,14 +206,14 @@ An API application comes with the following middlewares by default:
- `Rack::ConditionalGet`
- `Rack::ETag`
-See the [internal middlewares](rails_on_rack.html#internal-middleware-stack)
+See the [internal middleware](rails_on_rack.html#internal-middleware-stack)
section of the Rack guide for further information on them.
-Other plugins, including Active Record, may add additional middlewares. In
-general, these middlewares are agnostic to the type of application you are
+Other plugins, including Active Record, may add additional middleware. In
+general, these middleware are agnostic to the type of application you are
building, and make sense in an API-only Rails application.
-You can get a list of all middlewares in your application via:
+You can get a list of all middleware in your application via:
```bash
$ rails middleware
@@ -262,9 +262,6 @@ subsequent inbound requests for the same URL.
Think of it as page caching using HTTP semantics.
-NOTE: This middleware is always outside of the `Rack::Lock` mutex, even in
-single-threaded applications.
-
### Using Rack::Sendfile
When you use the `send_file` method inside a Rails controller, it sets the
@@ -296,9 +293,6 @@ config.action_dispatch.x_sendfile_header = "X-Accel-Redirect"
Make sure to configure your server to support these options following the
instructions in the `Rack::Sendfile` documentation.
-NOTE: The `Rack::Sendfile` middleware is always outside of the `Rack::Lock`
-mutex, even in single-threaded applications.
-
### Using ActionDispatch::Request
`ActionDispatch::Request#params` will take parameters from the client in the JSON
@@ -327,9 +321,9 @@ will be:
{ :person => { :firstName => "Yehuda", :lastName => "Katz" } }
```
-### Other Middlewares
+### Other Middleware
-Rails ships with a number of other middlewares that you might want to use in an
+Rails ships with a number of other middleware that you might want to use in an
API application, especially if one of your API clients is the browser:
- `Rack::MethodOverride`
@@ -340,13 +334,13 @@ API application, especially if one of your API clients is the browser:
* `ActionDispatch::Session::CookieStore`
* `ActionDispatch::Session::MemCacheStore`
-Any of these middlewares can be added via:
+Any of these middleware can be added via:
```ruby
config.middleware.use Rack::MethodOverride
```
-### Removing Middlewares
+### Removing Middleware
If you don't want to use a middleware that is included by default in the API-only
middleware set, you can remove it with:
@@ -355,7 +349,7 @@ middleware set, you can remove it with:
config.middleware.delete ::Rack::Sendfile
```
-Keep in mind that removing these middlewares will remove support for certain
+Keep in mind that removing these middleware will remove support for certain
features in Action Controller.
Choosing Controller Modules
@@ -364,22 +358,24 @@ Choosing Controller Modules
An API application (using `ActionController::API`) comes with the following
controller modules by default:
-- `ActionController::UrlFor`: Makes `url_for` and friends available.
+- `ActionController::UrlFor`: Makes `url_for` and similar helpers available.
- `ActionController::Redirecting`: Support for `redirect_to`.
-- `ActionController::Rendering`: Basic support for rendering.
+- `AbstractController::Rendering` and `ActionController::ApiRendering`: Basic support for rendering.
- `ActionController::Renderers::All`: Support for `render :json` and friends.
- `ActionController::ConditionalGet`: Support for `stale?`.
-- `ActionController::ForceSSL`: Support for `force_ssl`.
-- `ActionController::DataStreaming`: Support for `send_file` and `send_data`.
-- `AbstractController::Callbacks`: Support for `before_action` and friends.
-- `ActionController::Instrumentation`: Support for the instrumentation
- hooks defined by Action Controller (see [the instrumentation
- guide](active_support_instrumentation.html#action-controller)).
-- `ActionController::Rescue`: Support for `rescue_from`.
- `ActionController::BasicImplicitRender`: Makes sure to return an empty response
if there's not an explicit one.
- `ActionController::StrongParameters`: Support for parameters white-listing in
combination with Active Model mass assignment.
+- `ActionController::ForceSSL`: Support for `force_ssl`.
+- `ActionController::DataStreaming`: Support for `send_file` and `send_data`.
+- `AbstractController::Callbacks`: Support for `before_action` and
+ similar helpers.
+- `ActionController::Rescue`: Support for `rescue_from`.
+- `ActionController::Instrumentation`: Support for the instrumentation
+ hooks defined by Action Controller (see [the instrumentation
+ guide](active_support_instrumentation.html#action-controller) for
+more information regarding this).
- `ActionController::ParamsWrapper`: Wraps the parameters hash into a nested hash
so you don't have to specify root elements sending POST requests for instance.
@@ -408,5 +404,5 @@ Some common modules you might want to add:
- `ActionController::Cookies`: Support for `cookies`, which includes
support for signed and encrypted cookies. This requires the cookies middleware.
-The best place to add a module is in your `ApplicationController` but you can
+The best place to add a module is in your `ApplicationController`, but you can
also add modules to individual controllers.
diff --git a/guides/source/asset_pipeline.md b/guides/source/asset_pipeline.md
index 5bdaf600ad..439f2bef3a 100644
--- a/guides/source/asset_pipeline.md
+++ b/guides/source/asset_pipeline.md
@@ -1177,19 +1177,14 @@ TIP: For further details have a look at the docs of your production web server:
Assets Cache Store
------------------
-The default Rails cache store will be used by Sprockets to cache assets in
-development and production. This can be changed by setting
-`config.assets.cache_store`:
+By default, Sprockets caches assets in `tmp/cache/assets` in development
+and production environments. This can be changed as follows:
```ruby
-config.assets.cache_store = :memory_store
-```
-
-The options accepted by the assets cache store are the same as the application's
-cache store.
-
-```ruby
-config.assets.cache_store = :memory_store, { size: 32.megabytes }
+config.assets.configure do |env|
+ env.cache = ActiveSupport::Cache.lookup_store(:memory_store,
+ { size: 32.megabytes })
+end
```
To disable the assets cache store:
diff --git a/guides/source/command_line.md b/guides/source/command_line.md
index f33e729de0..e865a02cbd 100644
--- a/guides/source/command_line.md
+++ b/guides/source/command_line.md
@@ -325,7 +325,7 @@ With the `helper` method it is possible to access Rails and your application's h
### `rails dbconsole`
-`rails dbconsole` figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL, PostgreSQL, SQLite and SQLite3.
+`rails dbconsole` figures out which database you're using and drops you into whichever command line interface you would use with it (and figures out the command line parameters to give to it, too!). It supports MySQL, PostgreSQL and SQLite3.
INFO: You can also use the alias "db" to invoke the dbconsole: `rails db`.
@@ -432,7 +432,7 @@ Ruby version 2.2.2 (x86_64-linux)
RubyGems version 2.4.6
Rack version 1.6
JavaScript Runtime Node.js (V8)
-Middleware Rack::Sendfile, ActionDispatch::Static, Rack::Lock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007ffd131a7c88>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, Rack::Head, Rack::ConditionalGet, Rack::ETag
+Middleware Rack::Sendfile, ActionDispatch::Static, ActionDispatch::LoadInterlock, #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007ffd131a7c88>, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, Rails::Rack::Logger, ActionDispatch::ShowExceptions, ActionDispatch::DebugExceptions, ActionDispatch::RemoteIp, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, Rack::Head, Rack::ConditionalGet, Rack::ETag
Application root /home/foobar/commandsapp
Environment development
Database adapter sqlite3
@@ -618,7 +618,7 @@ We had to create the **gitapp** directory and initialize an empty git repository
```bash
$ cat config/database.yml
-# PostgreSQL. Versions 8.2 and up are supported.
+# PostgreSQL. Versions 9.1 and up are supported.
#
# Install the pg driver:
# gem install pg
diff --git a/guides/source/configuring.md b/guides/source/configuring.md
index 8a21d4062a..d9c345fb71 100644
--- a/guides/source/configuring.md
+++ b/guides/source/configuring.md
@@ -159,8 +159,6 @@ pipeline is enabled. It is set to true by default.
* `config.assets.debug` disables the concatenation and compression of assets. Set to `true` by default in `development.rb`.
-* `config.assets.cache_store` defines the cache store that Sprockets will use. The default is the Rails file store.
-
* `config.assets.compile` is a boolean that can be used to turn on live Sprockets compilation in production.
* `config.assets.logger` accepts a logger conforming to the interface of Log4r or the default Ruby `Logger` class. Defaults to the same configured at `config.logger`. Setting `config.assets.logger` to false will turn off served assets logging.
@@ -200,7 +198,7 @@ Every Rails application comes with a standard set of middleware which it uses in
* `ActionDispatch::SSL` forces every request to be served using HTTPS. Enabled if `config.force_ssl` is set to `true`. Options passed to this can be configured by setting `config.ssl_options`.
* `ActionDispatch::Static` is used to serve static assets. Disabled if `config.public_file_server.enabled` is `false`. Set `config.public_file_server.index_name` if you need to serve a static directory index file that is not named `index`. For example, to serve `main.html` instead of `index.html` for directory requests, set `config.public_file_server.index_name` to `"main"`.
-* `Rack::Lock` wraps the app in mutex so it can only be called by a single thread at a time. Only enabled when `config.cache_classes` is `false`.
+* `ActionDispatch::LoadInterlock` allows thread safe code reloading. Disabled if `config.allow_concurrency` is `false`, which causes `Rack::Lock` to be loaded. `Rack::Lock` wraps the app in mutex so it can only be called by a single thread at a time.
* `ActiveSupport::Cache::Strategy::LocalCache` serves as a basic memory backed cache. This cache is not thread safe and is intended only for serving as a temporary memory cache for a single thread.
* `Rack::Runtime` sets an `X-Runtime` header, containing the time (in seconds) taken to execute the request.
* `Rails::Rack::Logger` notifies the logs that the request has begun. After request is complete, flushes all the logs.
diff --git a/guides/source/contributing_to_ruby_on_rails.md b/guides/source/contributing_to_ruby_on_rails.md
index cbc304c87f..0f98d12217 100644
--- a/guides/source/contributing_to_ruby_on_rails.md
+++ b/guides/source/contributing_to_ruby_on_rails.md
@@ -105,7 +105,7 @@ $ git checkout -b testing_branch
Then you can use their remote branch to update your codebase. For example, let's say the GitHub user JohnSmith has forked and pushed to a topic branch "orange" located at https://github.com/JohnSmith/rails.
```bash
-$ git remote add JohnSmith git://github.com/JohnSmith/rails.git
+$ git remote add JohnSmith https://github.com/JohnSmith/rails.git
$ git pull JohnSmith orange
```
@@ -159,7 +159,7 @@ If you want to translate the Rails guides in your own language, follows these st
* Copy the contents of *guides/source* into your own language directory and translate them.
* Do NOT translate the HTML files, as they are automatically generated.
-To generate the guides in HTML format cd into the *guides* direcotry then run (eg. for it-IT):
+To generate the guides in HTML format cd into the *guides* directory then run (eg. for it-IT):
```bash
$ bundle install
@@ -204,7 +204,7 @@ In case you can't use the Rails development box, see [this other guide](developm
To be able to contribute code, you need to clone the Rails repository:
```bash
-$ git clone git://github.com/rails/rails.git
+$ git clone https://github.com/rails/rails.git
```
and create a dedicated branch:
@@ -506,7 +506,7 @@ Navigate to the Rails [GitHub repository](https://github.com/rails/rails) and pr
Add the new remote to your local repository on your local machine:
```bash
-$ git remote add mine git@github.com:<your user name>/rails.git
+$ git remote add mine https://github.com:<your user name>/rails.git
```
Push to your remote:
@@ -520,7 +520,7 @@ You might have cloned your forked repository into your machine and might want to
In the directory you cloned your fork:
```bash
-$ git remote add rails git://github.com/rails/rails.git
+$ git remote add rails https://github.com/rails/rails.git
```
Download new commits and branches from the official repository:
diff --git a/guides/source/documents.yaml b/guides/source/documents.yaml
index 4473eba478..fdd6d4d33d 100644
--- a/guides/source/documents.yaml
+++ b/guides/source/documents.yaml
@@ -135,6 +135,11 @@
work_in_progress: true
url: profiling.html
description: This guide explains how to profile your Rails applications to improve performance.
+ -
+ name: Using Rails for API-only Applications
+ work_in_progress: true
+ url: api_app.html
+ description: This guide explains how to effectively use Rails to develop a JSON API application.
-
name: Extending Rails
diff --git a/guides/source/getting_started.md b/guides/source/getting_started.md
index 9677ab1583..2cbc591629 100644
--- a/guides/source/getting_started.md
+++ b/guides/source/getting_started.md
@@ -93,7 +93,7 @@ current version of Ruby installed:
```bash
$ ruby -v
-ruby 2.2.2p95
+ruby 2.3.0p0
```
TIP: A number of tools exist to help you quickly install Ruby and Ruby
@@ -767,7 +767,7 @@ Why do you have to bother? The ability to grab and automatically assign all
controller parameters to your model in one shot makes the programmer's job
easier, but this convenience also allows malicious use. What if a request to
the server was crafted to look like a new article form submit but also included
-extra fields with values that violated your applications integrity? They would
+extra fields with values that violated your application's integrity? They would
be 'mass assigned' into your model and then into the database along with the
good stuff - potentially breaking your application or worse.
@@ -1540,7 +1540,7 @@ This is very similar to the `Article` model that you saw earlier. The difference
is the line `belongs_to :article`, which sets up an Active Record _association_.
You'll learn a little about associations in the next section of this guide.
-The (`:references`) keyword used in the bash command is a special data type for models.
+The (`:references`) keyword used in the bash command is a special data type for models.
It creates a new column on your database table with the provided model name appended with an `_id`
that can hold integer values. You can get a better understanding after analyzing the
`db/schema.rb` file below.
diff --git a/guides/source/initialization.md b/guides/source/initialization.md
index 6232ef4c57..156f9c92b4 100644
--- a/guides/source/initialization.md
+++ b/guides/source/initialization.md
@@ -157,7 +157,7 @@ snippet.
If we had used `s` rather than `server`, Rails would have used the `aliases`
defined here to find the matching command.
-### `rails/commands/command_tasks.rb`
+### `rails/commands/commands_tasks.rb`
When one types a valid Rails command, `run_command!` a method of the same name
is called. If Rails doesn't recognize the command, it tries to run a Rake task
diff --git a/guides/source/rails_on_rack.md b/guides/source/rails_on_rack.md
index 934693252e..3b61d65df5 100644
--- a/guides/source/rails_on_rack.md
+++ b/guides/source/rails_on_rack.md
@@ -104,7 +104,7 @@ For a freshly generated Rails application, this might produce something like:
```ruby
use Rack::Sendfile
use ActionDispatch::Static
-use Rack::Lock
+use ActionDispatch::LoadInterlock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x000000029a0838>
use Rack::Runtime
use Rack::MethodOverride
@@ -171,10 +171,10 @@ Add the following lines to your application configuration:
```ruby
# config/application.rb
-config.middleware.delete Rack::Lock
+config.middleware.delete Rack::Runtime
```
-And now if you inspect the middleware stack, you'll find that `Rack::Lock` is
+And now if you inspect the middleware stack, you'll find that `Rack::Runtime` is
not a part of it.
```bash
@@ -219,6 +219,10 @@ Much of Action Controller's functionality is implemented as Middlewares. The fol
* Sets `env["rack.multithread"]` flag to `false` and wraps the application within a Mutex.
+**`ActionDispatch::LoadInterlock`**
+
+* Used for thread safe code reloading during development.
+
**`ActiveSupport::Cache::Strategy::LocalCache::Middleware`**
* Used for memory caching. This cache is not thread safe.
diff --git a/guides/source/routing.md b/guides/source/routing.md
index 5a745b10cd..777d1d24b6 100644
--- a/guides/source/routing.md
+++ b/guides/source/routing.md
@@ -1136,10 +1136,21 @@ For example, here's a small section of the `rails routes` output for a RESTful r
edit_user GET /users/:id/edit(.:format) users#edit
```
-You may restrict the listing to the routes that map to a particular controller setting the `CONTROLLER` environment variable:
+You can search through your routes with the --grep option (-g for short). This outputs any routes that partially match the URL helper method name, the HTTP verb, or the URL path.
-```bash
-$ CONTROLLER=users bin/rails routes
+```
+$ bin/rails routes --grep new_comment
+$ bin/rails routes -g POST
+$ bin/rails routes -g admin
+```
+
+If you only want to see the routes that map to a specific controller, there's the --controller option (-c for short).
+
+```
+$ bin/rails routes --controller users
+$ bin/rails routes --controller admin/users
+$ bin/rails routes -c Comments
+$ bin/rails routes -c Articles::CommentsController
```
TIP: You'll find that the output from `rails routes` is much more readable if you widen your terminal window until the output lines don't wrap.
diff --git a/guides/source/security.md b/guides/source/security.md
index 1d0e87d831..96b9f4bcce 100644
--- a/guides/source/security.md
+++ b/guides/source/security.md
@@ -102,7 +102,7 @@ Thus the session becomes a more secure place to store data. The encryption is
done using a server-side secret key `secrets.secret_key_base` stored in
`config/secrets.yml`.
-That means the security of this storage depends on this secret (and on the digest algorithm, which defaults to SHA1, for compatibility). So _don't use a trivial secret, i.e. a word from a dictionary, or one which is shorter than 30 characters, use `rake secret` instead_.
+That means the security of this storage depends on this secret (and on the digest algorithm, which defaults to SHA1, for compatibility). So _don't use a trivial secret, i.e. a word from a dictionary, or one which is shorter than 30 characters, use `rails secret` instead_.
`secrets.secret_key_base` is used for specifying a key which allows sessions for the application to be verified against a known secure key to prevent tampering. Applications get `secrets.secret_key_base` initialized to a random key present in `config/secrets.yml`, e.g.:
diff --git a/guides/source/testing.md b/guides/source/testing.md
index b5e49a41f4..f4894d4c11 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -638,9 +638,9 @@ We were able to successfully test a very small workflow for visiting our blog an
Functional Tests for Your Controllers
-------------------------------------
-In Rails, testing the various actions of a controller is a form of writing functional tests. Remember your controllers handle the incoming web requests to your application and eventually respond with a rendered view. When writing functional tests, you're testing how your actions handle the requests and the expected result, or response in some cases an HTML view.
+In Rails, testing the various actions of a controller is a form of writing functional tests. Remember your controllers handle the incoming web requests to your application and eventually respond with a rendered view. When writing functional tests, you are testing how your actions handle the requests and the expected result or response, in some cases an HTML view.
-### What to Include in your Functional Tests
+### What to include in your Functional Tests
You should test for things such as:
@@ -650,8 +650,7 @@ You should test for things such as:
* was the correct object stored in the response template?
* was the appropriate message displayed to the user in the view?
-The easiest way to see functional tests in action is to generate a controller
-scaffold:
+The easiest way to see functional tests in action is to generate a controller using the scaffold generator:
```bash
$ bin/rails generate scaffold_controller article title:string body:text
@@ -664,7 +663,7 @@ create test/controllers/articles_controller_test.rb
```
This will generate the controller code and tests for an `Article` resource.
-You can take look at the file `articles_controller_test.rb` in the `test/controllers` directory.
+You can take a look at the file `articles_controller_test.rb` in the `test/controllers` directory.
If you already have a controller and just want to generate the test scaffold code for
each of the seven default actions, you can use the following command:
@@ -677,7 +676,7 @@ create test/controllers/articles_controller_test.rb
...
```
-Let me take you through one such test, `test_should_get_index` from the file `articles_controller_test.rb`.
+Let's take a look at one such test, `test_should_get_index` from the file `articles_controller_test.rb`.
```ruby
# articles_controller_test.rb
@@ -693,7 +692,7 @@ end
In the `test_should_get_index` test, Rails simulates a request on the action called `index`, making sure the request was successful
and also ensuring that the right response body has been generated.
-The `get` method kicks off the web request and populates the results into the response. It accepts 4 arguments:
+The `get` method kicks off the web request and populates the results into the `@response`. It accepts 4 arguments:
* The action of the controller you are requesting.
This can be in the form of a string or a route (i.e. `articles_url`).
@@ -705,7 +704,7 @@ The `get` method kicks off the web request and populates the results into the re
* `flash`: option with a hash of flash values.
-All the keyword arguments are optional.
+All of these keyword arguments are optional.
Example: Calling the `:show` action, passing an `id` of 12 as the `params` and setting a `user_id` of 5 in the session:
@@ -753,7 +752,7 @@ NOTE: Functional tests do not verify whether the specified request type is accep
### Testing XHR (AJAX) requests
To test AJAX requests, you can specify the `xhr: true` option to `get`, `post`,
-`patch`, `put`, and `delete` methods:
+`patch`, `put`, and `delete` methods. For example:
```ruby
test "ajax request" do
@@ -808,7 +807,7 @@ post article_url # simulate the request with custom env variable
### Testing `flash` notices
-If you remember from earlier one of the Three Hashes of the Apocalypse was `flash`.
+If you remember from earlier, one of the Three Hashes of the Apocalypse was `flash`.
We want to add a `flash` message to our blog application whenever someone
successfully creates a new Article.
@@ -893,7 +892,7 @@ test "should show article" do
end
```
-Remember from our discussion earlier on fixtures the `articles()` method will give us access to our Articles fixtures.
+Remember from our discussion earlier on fixtures, the `articles()` method will give us access to our Articles fixtures.
How about deleting an existing Article?
@@ -913,14 +912,19 @@ We can also add a test for updating an existing Article.
```ruby
test "should update article" do
article = articles(:one)
+
patch '/article', params: { id: article.id, article: { title: "updated" } }
+
assert_redirected_to article_path(article)
+ # Reload association to fetch updated data and assert that title is updated.
+ article.reload
+ assert_equal "updated", article.title
end
```
Notice we're starting to see some duplication in these three tests, they both access the same Article fixture data. We can D.R.Y. this up by using the `setup` and `teardown` methods provided by `ActiveSupport::Callbacks`.
-Our test should now look something like this, disregard the other tests we're leaving them out for brevity.
+Our test should now look something as what follows. Disregard the other tests for now, we're leaving them out for brevity.
```ruby
require 'test_helper'
@@ -952,8 +956,12 @@ class ArticlesControllerTest < ActionDispatch::IntegrationTest
end
test "should update article" do
- patch article_url(@article), params: { article: { title: "updated" } }
+ patch '/article', params: { id: @article.id, article: { title: "updated" } }
+
assert_redirected_to article_path(@article)
+ # Reload association to fetch updated data and assert that title is updated.
+ @article.reload
+ assert_equal "updated", @article.title
end
end
```
@@ -966,7 +974,7 @@ To avoid code duplication, you can add your own test helpers.
Sign in helper can be a good example:
```ruby
-test/test_helper.rb
+#test/test_helper.rb
module SignInHelper
def sign_in(user)
@@ -1087,8 +1095,9 @@ have to use a mixin like this:
```ruby
class UserHelperTest < ActionView::TestCase
- test "should return the user name" do
- # ...
+ test "should return the user's full name" do
+ user = users(:david)
+ assert_equal "David Heinemeier Hansson", user_full_name(user)
end
end
```
@@ -1123,7 +1132,7 @@ In order to test that your mailer is working as expected, you can use unit tests
For the purposes of unit testing a mailer, fixtures are used to provide an example of how the output _should_ look. Because these are example emails, and not Active Record data like the other fixtures, they are kept in their own subdirectory apart from the other fixtures. The name of the directory within `test/fixtures` directly corresponds to the name of the mailer. So, for a mailer named `UserMailer`, the fixtures should reside in `test/fixtures/user_mailer` directory.
-When you generated your mailer, the generator creates stub fixtures for each of the mailers actions. If you didn't use the generator you'll have to make those files yourself.
+When you generated your mailer, the generator creates stub fixtures for each of the mailers actions. If you didn't use the generator, you'll have to create those files yourself.
#### The Basic Test Case
@@ -1204,7 +1213,7 @@ Testing Jobs
------------
Since your custom jobs can be queued at different levels inside your application,
-you'll need to test both jobs themselves (their behavior when they get enqueued)
+you'll need to test both, the jobs themselves (their behavior when they get enqueued)
and that other entities correctly enqueue them.
### A Basic Test Case
@@ -1255,7 +1264,7 @@ end
Testing Time-Dependent Code
---------------------------
-Rails provides inbuilt helper methods that enable you to assert that your time-sensitve code works as expected.
+Rails provides built-in helper methods that enable you to assert that your time-sensitive code works as expected.
Here is an example using the [`travel_to`](http://api.rubyonrails.org/classes/ActiveSupport/Testing/TimeHelpers.html#method-i-travel_to) helper:
diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md
index 202e5b5cb9..e631445492 100644
--- a/guides/source/upgrading_ruby_on_rails.md
+++ b/guides/source/upgrading_ruby_on_rails.md
@@ -402,7 +402,7 @@ secrets, you need to:
3. Remove the `secret_token.rb` initializer.
-4. Use `rake secret` to generate new keys for the `development` and `test` sections.
+4. Use `rails secret` to generate new keys for the `development` and `test` sections.
5. Restart your server.