aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2015-11-19 09:27:55 +0100
committerYves Senn <yves.senn@gmail.com>2015-11-19 09:27:55 +0100
commit58df2f4b4abcce0b698c2540da215a565c24cbc9 (patch)
treef554406753b491c9ea5c14bb5c83d119b45ff20e /guides
parent2d056f3493ad574b49be2baa87546b165e379d85 (diff)
downloadrails-58df2f4b4abcce0b698c2540da215a565c24cbc9.tar.gz
rails-58df2f4b4abcce0b698c2540da215a565c24cbc9.tar.bz2
rails-58df2f4b4abcce0b698c2540da215a565c24cbc9.zip
guides, scaffold no longer used in getting started guide. Closes #22337.
[ci skip] Since the "Getting Started" guide no longer uses the scaffold generator we should rewrite references to that in the testing guide. The functional testing section was quite heavily based on such a scaffold test. I changed it to use `generate scaffold_controller` instead so that we can build up on the model foundation we already have.
Diffstat (limited to 'guides')
-rw-r--r--guides/source/testing.md30
1 files changed, 24 insertions, 6 deletions
diff --git a/guides/source/testing.md b/guides/source/testing.md
index f63ea49955..3bfbf4f7ff 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -54,10 +54,12 @@ NOTE: Your tests are run under `RAILS_ENV=test`.
### Rails meets Minitest
-If you remember when you used the `rails generate scaffold` command from the [Getting Started with Rails](getting_started.html) guide. We created our first resource among other things it created test stubs in the `test` directory:
+If you remember when you used the `rails generate model` command from the
+[Getting Started with Rails](getting_started.html) guide. We created our first
+model among other things it created test stubs in the `test` directory:
```bash
-$ bin/rails generate scaffold article title:string body:text
+$ bin/rails generate model article title:string body:text
...
create app/models/article.rb
create test/models/article_test.rb
@@ -649,14 +651,31 @@ 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?
-Now that we have used Rails scaffold generator for our `Article` resource, it has already created the controller code and tests. You can take look at the file `articles_controller_test.rb` in the `test/controllers` directory.
+The easiest way to see functional tests in action is to generate a controller
+scaffold:
-The following command will generate a controller test case with a filled up
-test for each of the seven default actions.
+```bash
+$ bin/rails generate scaffold_controller article title:string body:test
+...
+create app/controllers/articles_controller.rb
+...
+invoke test_unit
+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.
+
+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:
```bash
$ bin/rails generate test_unit:scaffold article
+...
+invoke test_unit
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`.
@@ -1253,4 +1272,3 @@ assert_equal Date.new(2004, 10, 24), user.activation_date # The change was visib
Please see [`ActiveSupport::TimeHelpers` API Documentation](http://api.rubyonrails.org/classes/ActiveSupport/Testing/TimeHelpers.html)
for in-depth information about the available time helpers.
-