mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #19034 from jvanbaarsen/explicit-job-base-class
Add explicit base class for ActiveJob jobs
This commit is contained in:
commit
cb01246721
8 changed files with 33 additions and 6 deletions
|
@ -1,3 +1,7 @@
|
|||
* A generated job now inherents from `app/jobs/application_job.rb` by default.
|
||||
|
||||
*Jeroen van Baarsen*
|
||||
|
||||
* Add an `:only` option to `perform_enqueued_jobs` to filter jobs based on
|
||||
type.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
-------------------------------------
|
||||
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
class ApplicationJob < ActiveJob::Base
|
||||
|
||||
end
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue