mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Seed database with inline ActiveJob job adapter
This commit is contained in:
parent
90536ebfb3
commit
66cc0e768f
3 changed files with 29 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
|||
* Seed database with inline ActiveJob job adapter.
|
||||
|
||||
*Gannon McGibbon*
|
||||
|
||||
* Add `rails db:system:change` command for changing databases.
|
||||
|
||||
```
|
||||
|
|
|
@ -548,7 +548,7 @@ module Rails
|
|||
# Blog::Engine.load_seed
|
||||
def load_seed
|
||||
seed_file = paths["db/seeds.rb"].existent.first
|
||||
load(seed_file) if seed_file
|
||||
with_inline_jobs { load(seed_file) } if seed_file
|
||||
end
|
||||
|
||||
# Add configured load paths to Ruby's load path, and remove duplicate entries.
|
||||
|
@ -658,6 +658,18 @@ module Rails
|
|||
end
|
||||
end
|
||||
|
||||
def with_inline_jobs
|
||||
queue_adapter = config.active_job.queue_adapter
|
||||
ActiveSupport.on_load(:active_job) do
|
||||
self.queue_adapter = :inline
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
ActiveSupport.on_load(:active_job) do
|
||||
self.queue_adapter = queue_adapter
|
||||
end
|
||||
end
|
||||
|
||||
def has_migrations?
|
||||
paths["db/migrate"].existent.any?
|
||||
end
|
||||
|
|
|
@ -879,6 +879,18 @@ YAML
|
|||
assert Bukkits::Engine.config.bukkits_seeds_loaded
|
||||
end
|
||||
|
||||
test "jobs are ran inline while loading seeds" do
|
||||
app_file "db/seeds.rb", <<-RUBY
|
||||
Rails.application.config.seed_queue_adapter = ActiveJob::Base.queue_adapter
|
||||
RUBY
|
||||
|
||||
boot_rails
|
||||
Rails.application.load_seed
|
||||
|
||||
assert_instance_of ActiveJob::QueueAdapters::InlineAdapter, Rails.application.config.seed_queue_adapter
|
||||
assert_instance_of ActiveJob::QueueAdapters::AsyncAdapter, ActiveJob::Base.queue_adapter
|
||||
end
|
||||
|
||||
test "skips nonexistent seed data" do
|
||||
FileUtils.rm "#{app_path}/db/seeds.rb"
|
||||
boot_rails
|
||||
|
|
Loading…
Reference in a new issue