aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_dispatch/request/session.rb24
-rw-r--r--actionview/test/actionpack/controller/render_test.rb20
-rw-r--r--activerecord/lib/active_record/enum.rb2
-rw-r--r--activerecord/lib/active_record/fixtures.rb2
-rw-r--r--guides/source/active_job_basics.md53
5 files changed, 56 insertions, 45 deletions
diff --git a/actionpack/lib/action_dispatch/request/session.rb b/actionpack/lib/action_dispatch/request/session.rb
index 773d41de88..a8a3cd20b9 100644
--- a/actionpack/lib/action_dispatch/request/session.rb
+++ b/actionpack/lib/action_dispatch/request/session.rb
@@ -17,7 +17,7 @@ module ActionDispatch
session.merge! session_was if session_was
set(env, session)
- Options.set(env, Request::Session::Options.new(store, env, default_options))
+ Options.set(env, Request::Session::Options.new(store, default_options))
session
end
@@ -38,20 +38,19 @@ module ActionDispatch
env[ENV_SESSION_OPTIONS_KEY]
end
- def initialize(by, env, default_options)
+ def initialize(by, default_options)
@by = by
- @env = env
@delegate = default_options.dup
end
def [](key)
- if key == :id
- @delegate.fetch(key) {
- @delegate[:id] = @by.send(:extract_session_id, @env)
- }
- else
- @delegate[key]
- end
+ @delegate[key]
+ end
+
+ def id(env)
+ @delegate.fetch(:id) {
+ @by.send(:extract_session_id, env)
+ }
end
def []=(k,v); @delegate[k] = v; end
@@ -68,7 +67,7 @@ module ActionDispatch
end
def id
- options[:id]
+ options.id(@env)
end
def options
@@ -78,8 +77,7 @@ module ActionDispatch
def destroy
clear
options = self.options || {}
- new_sid = @by.send(:destroy_session, @env, options[:id], options)
- options[:id] = new_sid # Reset session id with a new value or nil
+ @by.send(:destroy_session, @env, options.id(@env), options)
# Load the new sid to be written with the response
@loaded = false
diff --git a/actionview/test/actionpack/controller/render_test.rb b/actionview/test/actionpack/controller/render_test.rb
index c4228b5683..ebaf39a12d 100644
--- a/actionview/test/actionpack/controller/render_test.rb
+++ b/actionview/test/actionpack/controller/render_test.rb
@@ -1,6 +1,5 @@
require 'abstract_unit'
require 'active_model'
-require 'fileutils'
class ApplicationController < ActionController::Base
self.view_paths = File.join(FIXTURE_LOAD_PATH, "actionpack")
@@ -679,14 +678,6 @@ class RenderTest < ActionController::TestCase
ActionView::Base.logger = nil
end
- def case_sensitive_file_system?
- fname = '.case_sensitive_file_system_test'
- FileUtils.touch(fname)
- !File.exist?(fname.upcase)
- ensure
- FileUtils.rm_f(fname)
- end
-
# :ported:
def test_simple_show
get :hello_world
@@ -753,15 +744,8 @@ class RenderTest < ActionController::TestCase
end
def test_render_action_upcased
- action = :render_action_upcased_hello_world
-
- if case_sensitive_file_system?
- assert_raise ActionView::MissingTemplate do
- get action
- end
- else
- get action
- assert_equal 'Hello world!', @response.body
+ assert_raise ActionView::MissingTemplate do
+ get :render_action_upcased_hello_world
end
end
diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb
index ad33c84dbc..84b05d9136 100644
--- a/activerecord/lib/active_record/enum.rb
+++ b/activerecord/lib/active_record/enum.rb
@@ -89,7 +89,7 @@ module ActiveRecord
# enum verification: [:done, :fail], enum_prefix: :verification_status
# end
#
- # Note that <tt>:enum_prefix</tt>/<tt>:enum_postfix</tt> are reserved keywords
+ # Note that <tt>:enum_prefix</tt>/<tt>:enum_suffix</tt> are reserved keywords
# and can not be used as an enum name.
module Enum
diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb
index 738fab2bd9..b01444a090 100644
--- a/activerecord/lib/active_record/fixtures.rb
+++ b/activerecord/lib/active_record/fixtures.rb
@@ -110,7 +110,7 @@ module ActiveRecord
# <% 1.upto(1000) do |i| %>
# fix_<%= i %>:
# id: <%= i %>
- # name: guy_<%= 1 %>
+ # name: guy_<%= i %>
# <% end %>
#
# This will create 1000 very simple fixtures.
diff --git a/guides/source/active_job_basics.md b/guides/source/active_job_basics.md
index 29d0c32b09..cc7a944f49 100644
--- a/guides/source/active_job_basics.md
+++ b/guides/source/active_job_basics.md
@@ -4,7 +4,7 @@ Active Job Basics
=================
This guide provides you with all you need to get started in creating,
-enqueueing and executing background jobs.
+enqueuing and executing background jobs.
After reading this guide, you will know:
@@ -20,7 +20,7 @@ Introduction
------------
Active Job is a framework for declaring jobs and making them run on a variety
-of queueing backends. These jobs can be everything from regularly scheduled
+of queuing backends. These jobs can be everything from regularly scheduled
clean-ups, to billing charges, to mailings. Anything that can be chopped up
into small units of work and run in parallel, really.
@@ -28,11 +28,14 @@ into small units of work and run in parallel, really.
The Purpose of Active Job
-----------------------------
The main point is to ensure that all Rails apps will have a job infrastructure
-in place, even if it's in the form of an "immediate runner". We can then have
-framework features and other gems build on top of that, without having to
-worry about API differences between various job runners such as Delayed Job
-and Resque. Picking your queuing backend becomes more of an operational concern,
-then. And you'll be able to switch between them without having to rewrite your jobs.
+in place. We can then have framework features and other gems build on top of that,
+without having to worry about API differences between various job runners such as
+Delayed Job and Resque. Picking your queuing backend becomes more of an operational
+concern, then. And you'll be able to switch between them without having to rewrite
+your jobs.
+
+NOTE: Rails by default comes with an "immediate runner" queuing implementation.
+That means that each job that has been enqueued will run immediately.
Creating a Job
@@ -73,12 +76,31 @@ class GuestsCleanupJob < ActiveJob::Base
end
```
+### Make the Job Available for Use
+
+Rails does not autoload the `app/jobs` directory by default. To make your job
+accessible in the rest of your application you need to add the directory to the
+auto-load paths:
+
+```ruby
+# config/application.rb
+module YourApp
+ class Application < Rails::Application
+ # Let Rails autoload your job classes for use in your code
+ config.autoload_paths << Rails.root.join('app/jobs')
+ end
+end
+```
+
+Now you can make use of the job anywhere in your code (e.g. in your controllers
+or models).
+
### Enqueue the Job
Enqueue a job like so:
```ruby
-# Enqueue a job to be performed as soon the queueing system is
+# Enqueue a job to be performed as soon the queuing system is
# free.
MyJob.perform_later record
```
@@ -99,17 +121,20 @@ That's it!
Job Execution
-------------
-If no adapter is set, the job is immediately executed.
+For enqueuing and executing jobs you need to set up a queuing backend, that is to
+say you need to decide for a 3rd-party queuing library that Rails should use.
+Rails itself does not provide a sophisticated queuing system and just executes the
+job immediately if no adapter is set.
### Backends
-Active Job has built-in adapters for multiple queueing backends (Sidekiq,
+Active Job has built-in adapters for multiple queuing backends (Sidekiq,
Resque, Delayed Job and others). To get an up-to-date list of the adapters
see the API Documentation for [ActiveJob::QueueAdapters](http://api.rubyonrails.org/classes/ActiveJob/QueueAdapters.html).
### Setting the Backend
-You can easily set your queueing backend:
+You can easily set your queuing backend:
```ruby
# config/application.rb
@@ -123,6 +148,10 @@ module YourApp
end
```
+NOTE: Since jobs run in parallel to your Rails application, most queuing libraries
+require that you start a library-specific queuing service (in addition to
+starting your Rails app) for the job processing to work. For information on
+how to do that refer to the documentation of your respective library.
Queues
------
@@ -212,7 +241,7 @@ end
ProcessVideoJob.perform_later(Video.last)
```
-NOTE: Make sure your queueing backend "listens" on your queue name. For some
+NOTE: Make sure your queuing backend "listens" on your queue name. For some
backends you need to specify the queues to listen to.