@@ -528,6 +528,19 @@ All of request types have equivalent methods that you can use. In a typical C.R.
NOTE: Functional tests do not verify whether the specified request type is accepted by the action, we're more concerned with the result. Request tests exist for this use case to make your tests more purposeful.
### Testing XHR (AJAX) requests
`xhr` accepts method (listed in the section above), action name and parameters:
```ruby
test"ajax request responds with no layout"do
xhr:get,:show,id: articles(:first).id
assert_template:index
assert_templatelayout: nil
end
```
### The Four Hashes of the Apocalypse
After a request has been made and processed, you will have 4 Hash objects ready for use:
...
...
@@ -740,10 +753,8 @@ class ArticlesControllerTest < ActionController::TestCase
# called after every single test
defteardown
# as we are re-initializing @article before every test
# setting it to nil here is not essential but I hope
# you understand how you can use the teardown method
@article=nil
# when controller is using cache it may be a good idea to reset it afterwards
Rails.cache.clear
end
test"should show article"do
...
...
@@ -769,6 +780,41 @@ end
Similar to other callbacks in Rails, the `setup` and `teardown` methods can also be used by passing a block, lambda, or method name as a symbol to call.
### Test helpers
To avoid code duplication, you can add your own test helpers.