aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Baarsen <jeroenvanbaarsen@gmail.com>2015-02-22 21:52:58 +0100
committerJeroen van Baarsen <jeroenvanbaarsen@gmail.com>2015-03-23 22:37:11 +0100
commit929a794a317666e4d29954e4f071c1dd57482aa7 (patch)
tree44804aa0548b42c7942b5613826cd4a1c05d7444
parentb6c038b600487b1adcf8f5e69ba70a992b07e195 (diff)
downloadrails-929a794a317666e4d29954e4f071c1dd57482aa7.tar.gz
rails-929a794a317666e4d29954e4f071c1dd57482aa7.tar.bz2
rails-929a794a317666e4d29954e4f071c1dd57482aa7.zip
Add explicit base class for ActiveJob jobs
* Jobs generated now inherent from ApplicationJob * ApplicationJob inherents from ActiveJob::Base * Added entry to changelog Signed-off-by: Jeroen van Baarsen <jeroenvanbaarsen@gmail.com>
-rw-r--r--activejob/CHANGELOG.md4
-rw-r--r--activejob/lib/rails/generators/job/job_generator.rb1
-rw-r--r--activejob/lib/rails/generators/job/templates/job.rb2
-rw-r--r--guides/source/upgrading_ruby_on_rails.md15
-rw-r--r--railties/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb3
-rw-r--r--railties/test/application/rake_test.rb2
-rw-r--r--railties/test/generators/app_generator_test.rb6
-rw-r--r--railties/test/generators/job_generator_test.rb6
8 files changed, 33 insertions, 6 deletions
diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md
index d4e19274fa..47975b2f2f 100644
--- a/activejob/CHANGELOG.md
+++ b/activejob/CHANGELOG.md
@@ -77,4 +77,8 @@
*Isaac Seymour*
+* A generated job now inherents from `app/job/application_job.rb` by default.
+
+ *Jeroen van Baarsen*
+
Please check [4-2-stable](https://github.com/rails/rails/blob/4-2-stable/activejob/CHANGELOG.md) for previous changes.
diff --git a/activejob/lib/rails/generators/job/job_generator.rb b/activejob/lib/rails/generators/job/job_generator.rb
index 979ffcb748..86e4c5266c 100644
--- a/activejob/lib/rails/generators/job/job_generator.rb
+++ b/activejob/lib/rails/generators/job/job_generator.rb
@@ -18,7 +18,6 @@ module Rails
def create_job_file
template 'job.rb', File.join('app/jobs', class_path, "#{file_name}_job.rb")
end
-
end
end
end
diff --git a/activejob/lib/rails/generators/job/templates/job.rb b/activejob/lib/rails/generators/job/templates/job.rb
index 462c71d917..4ad2914a45 100644
--- a/activejob/lib/rails/generators/job/templates/job.rb
+++ b/activejob/lib/rails/generators/job/templates/job.rb
@@ -1,5 +1,5 @@
<% module_namespacing do -%>
-class <%= class_name %>Job < ActiveJob::Base
+class <%= class_name %>Job < ApplicationJob
queue_as :<%= options[:queue] %>
def perform(*args)
diff --git a/guides/source/upgrading_ruby_on_rails.md b/guides/source/upgrading_ruby_on_rails.md
index 05c46a9e76..5a6f267360 100644
--- a/guides/source/upgrading_ruby_on_rails.md
+++ b/guides/source/upgrading_ruby_on_rails.md
@@ -75,6 +75,21 @@ warning by adding the following configuration to your `config/application.rb`:
See [#17227](https://github.com/rails/rails/pull/17227) for more details.
+### ActiveJob jobs now inherent from ApplicationJob by default
+
+In Rails 4.2 an ActiveJob inherents from `ActiveJob::Base`. In Rails 5.0 this
+behaviour has changed to now inherent from `ApplicationJob`.
+
+When upgrading from Rails 4.2 to Rails 5.0 you need to create a file
+`application_job.rb` in `app/jobs/` and add the following content:
+
+```
+class ApplicationJob < ActiveJob::Base
+end
+```
+
+See [#19034](https://github.com/rails/rails/pull/19034) for more details
+
Upgrading from Rails 4.1 to Rails 4.2
-------------------------------------
diff --git a/railties/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb b/railties/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb
new file mode 100644
index 0000000000..bddb5bcd0d
--- /dev/null
+++ b/railties/lib/rails/generators/rails/app/templates/app/jobs/application_job.rb
@@ -0,0 +1,3 @@
+class ApplicationJob < ActiveJob::Base
+
+end
diff --git a/railties/test/application/rake_test.rb b/railties/test/application/rake_test.rb
index 2bff21dae5..0648b11813 100644
--- a/railties/test/application/rake_test.rb
+++ b/railties/test/application/rake_test.rb
@@ -99,7 +99,7 @@ module ApplicationTests
end
def test_code_statistics_sanity
- assert_match "Code LOC: 5 Test LOC: 0 Code to Test Ratio: 1:0.0",
+ assert_match "Code LOC: 7 Test LOC: 0 Code to Test Ratio: 1:0.0",
Dir.chdir(app_path){ `rake stats` }
end
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index 4c5dd70a88..1630e844aa 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -18,6 +18,7 @@ DEFAULT_APP_FILES = %w(
app/mailers
app/models
app/models/concerns
+ app/jobs
app/views/layouts
bin/bundle
bin/rails
@@ -67,6 +68,11 @@ class AppGeneratorTest < Rails::Generators::TestCase
assert_file("app/assets/javascripts/application.js")
end
+ def test_application_job_file_present
+ run_generator
+ assert_file("app/jobs/application_job.rb")
+ end
+
def test_invalid_application_name_raises_an_error
content = capture(:stderr){ run_generator [File.join(destination_root, "43-things")] }
assert_equal "Invalid application name 43-things. Please give a name which does not start with numbers.\n", content
diff --git a/railties/test/generators/job_generator_test.rb b/railties/test/generators/job_generator_test.rb
index a9e0cea94f..7fd8f2062f 100644
--- a/railties/test/generators/job_generator_test.rb
+++ b/railties/test/generators/job_generator_test.rb
@@ -7,14 +7,14 @@ class JobGeneratorTest < Rails::Generators::TestCase
def test_job_skeleton_is_created
run_generator ["refresh_counters"]
assert_file "app/jobs/refresh_counters_job.rb" do |job|
- assert_match(/class RefreshCountersJob < ActiveJob::Base/, job)
+ assert_match(/class RefreshCountersJob < ApplicationJob/, job)
end
end
def test_job_queue_param
run_generator ["refresh_counters", "--queue", "important"]
assert_file "app/jobs/refresh_counters_job.rb" do |job|
- assert_match(/class RefreshCountersJob < ActiveJob::Base/, job)
+ assert_match(/class RefreshCountersJob < ApplicationJob/, job)
assert_match(/queue_as :important/, job)
end
end
@@ -22,7 +22,7 @@ class JobGeneratorTest < Rails::Generators::TestCase
def test_job_namespace
run_generator ["admin/refresh_counters", "--queue", "admin"]
assert_file "app/jobs/admin/refresh_counters_job.rb" do |job|
- assert_match(/class Admin::RefreshCountersJob < ActiveJob::Base/, job)
+ assert_match(/class Admin::RefreshCountersJob < ApplicationJob/, job)
assert_match(/queue_as :admin/, job)
end
end