aboutsummaryrefslogtreecommitdiffstats
path: root/guides
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2015-01-15 07:28:21 +0000
committerVijay Dev <vijaydev.cse@gmail.com>2015-01-15 07:28:21 +0000
commit3f96b6973b82ad17e443dd1d21be05996fb6fbf0 (patch)
treeb5fc571abe0b034b61c30b96afbca22743d93b3d /guides
parentd8e710410ea300ec4626250c0b35946cb52bc38c (diff)
parent34dc028e75137707c46f81e1db942dad6660fb31 (diff)
downloadrails-3f96b6973b82ad17e443dd1d21be05996fb6fbf0.tar.gz
rails-3f96b6973b82ad17e443dd1d21be05996fb6fbf0.tar.bz2
rails-3f96b6973b82ad17e443dd1d21be05996fb6fbf0.zip
Merge branch 'master' of github.com:rails/docrails
Diffstat (limited to 'guides')
-rw-r--r--guides/source/active_job_basics.md18
-rw-r--r--guides/source/configuring.md2
-rw-r--r--guides/source/testing.md61
3 files changed, 65 insertions, 16 deletions
diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md
index 53588bdd1d..4d1625b28d 100644
--- a/guides/source/active_job_basics.md
+++ b/guides/source/active_job_basics.md
@@ -78,7 +78,8 @@ end
Enqueue a job like so:
```ruby
-# Enqueue a job to be performed as soon the queueing system is free.
+# Enqueue a job to be performed as soon the queueing system is
+# free.
MyJob.perform_later record
```
@@ -114,8 +115,9 @@ You can easily set your queueing backend:
# config/application.rb
module YourApp
class Application < Rails::Application
- # Be sure to have the adapter's gem in your Gemfile and follow
- # the adapter's specific installation and deployment instructions.
+ # Be sure to have the adapter's gem in your Gemfile
+ # and follow the adapter's specific installation
+ # and deployment instructions.
config.active_job.queue_adapter = :sidekiq
end
end
@@ -153,8 +155,8 @@ class GuestsCleanupJob < ActiveJob::Base
end
# Now your job will run on queue production_low_priority on your
-# production environment and on staging_low_priority on your staging
-# environment
+# production environment and on staging_low_priority
+# on your staging environment
```
The default queue name prefix delimiter is '\_'. This can be changed by setting
@@ -176,8 +178,8 @@ class GuestsCleanupJob < ActiveJob::Base
end
# Now your job will run on queue production.low_priority on your
-# production environment and on staging.low_priority on your staging
-# environment
+# production environment and on staging.low_priority
+# on your staging environment
```
If you want more control on what queue a job will be run you can pass a `:queue`
@@ -295,7 +297,7 @@ end
```
This works with any class that mixes in `GlobalID::Identification`, which
-by default has been mixed into Active Model classes.
+by default has been mixed into Active Record classes.
Exceptions
diff --git a/guides/source/configuring.md b/guides/source/configuring.md
index cc3d840271..9c0f2ddc8a 100644
--- a/guides/source/configuring.md
+++ b/guides/source/configuring.md
@@ -692,7 +692,7 @@ development:
pool: 5
```
-Prepared Statements are enabled by default on PostgreSQL. You can be disable prepared statements by setting `prepared_statements` to `false`:
+Prepared Statements are enabled by default on PostgreSQL. You can disable prepared statements by setting `prepared_statements` to `false`:
```yaml
production:
diff --git a/guides/source/testing.md b/guides/source/testing.md
index 8456a8c4a8..94cfcf12b7 100644
--- a/guides/source/testing.md
+++ b/guides/source/testing.md
@@ -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_template layout: 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
def teardown
- # 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.
+Sign in helper can be a good example:
+
+```ruby
+test/test_helper.rb
+
+module SignInHelper
+ def sign_in(user)
+ session[:user_id] = user.id
+ end
+end
+
+class ActionController::TestCase
+ include SignInHelper
+end
+```
+
+```ruby
+require 'test_helper'
+
+class ProfileControllerTest < ActionController::TestCase
+
+ test "should show profile" do
+ # helper is now reusable from any controller test case
+ sign_in users(:david)
+
+ get :show
+ assert_response :success
+ assert_equal users(:david), assigns(:user)
+ end
+end
+```
+
Testing Routes
--------------
@@ -1050,9 +1096,10 @@ require 'test_helper'
class UserMailerTest < ActionMailer::TestCase
test "invite" do
# Send the email, then test that it got queued
- email = UserMailer.create_invite('me@example.com',
- 'friend@example.com', Time.now).deliver_now
- assert_not ActionMailer::Base.deliveries.empty?
+ assert_emails 1 do
+ email = UserMailer.create_invite('me@example.com',
+ 'friend@example.com', Time.now).deliver_now
+ end
# Test the body of the sent email contains what we expect it to
assert_equal ['me@example.com'], email.from