aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-11-23 00:15:47 -0800
committerGodfrey Chan <godfreykfc@gmail.com>2014-11-23 00:15:47 -0800
commitb7b9e92093ed128c2b27a64c5732f6a98191cbf0 (patch)
tree060475f2cb18186401fa49893ab2957b13d77336
parent77a276411e717353bc562c04d62e144f4410e706 (diff)
downloadrails-b7b9e92093ed128c2b27a64c5732f6a98191cbf0.tar.gz
rails-b7b9e92093ed128c2b27a64c5732f6a98191cbf0.tar.bz2
rails-b7b9e92093ed128c2b27a64c5732f6a98191cbf0.zip
Correct example in the engines testing guide [ci skip]
Reference #17453
-rw-r--r--guides/source/engines.md39
1 files changed, 25 insertions, 14 deletions
diff --git a/guides/source/engines.md b/guides/source/engines.md
index 21ac941ac0..de33f5f067 100644
--- a/guides/source/engines.md
+++ b/guides/source/engines.md
@@ -32,7 +32,7 @@ directory structure, and are both generated using the `rails plugin new`
generator. The difference is that an engine is considered a "full plugin" by
Rails (as indicated by the `--full` option that's passed to the generator
command). We'll actually be using the `--mountable` option here, which includes
-all the features of `--full`, and then some. This guide will refer to these
+all the features of `--full`, and then some. This guide will refer to these
"full plugins" simply as "engines" throughout. An engine **can** be a plugin,
and a plugin **can** be an engine.
@@ -1036,31 +1036,42 @@ functionality, especially controllers. This means that if you were to make a
typical `GET` to a controller in a controller's functional test like this:
```ruby
-get :index
+module Blorgh
+ class FooControllerTest < ActionController::TestCase
+ def test_index
+ get :index
+ ...
+ end
+ end
+end
```
It may not function correctly. This is because the application doesn't know how
to route these requests to the engine unless you explicitly tell it **how**. To
-do this, you must also pass the `:use_route` option as a parameter on these
-requests:
+do this, you must set the `@routes` instance variable to the engine's route set
+in your setup code:
```ruby
-get :index, use_route: :blorgh
+module Blorgh
+ class FooControllerTest < ActionController::TestCase
+ setup do
+ @routes = Engine.routes
+ end
+
+ def test_index
+ get :index
+ ...
+ end
+ end
+end
```
This tells the application that you still want to perform a `GET` request to the
`index` action of this controller, but you want to use the engine's route to get
there, rather than the application's one.
-Another way to do this is to assign the `@routes` instance variable to `Engine.routes` in your test setup:
-
-```ruby
-setup do
- @routes = Engine.routes
-end
-```
-
-This will also ensure url helpers for the engine will work as expected in your tests.
+This also ensures that the engine's URL helpers will work as expected in your
+tests.
Improving engine functionality
------------------------------