1
0
Fork 0
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:
Gannon McGibbon 2019-01-16 19:02:23 -05:00
parent 90536ebfb3
commit 66cc0e768f
3 changed files with 29 additions and 1 deletions

View file

@ -1,3 +1,7 @@
* Seed database with inline ActiveJob job adapter.
*Gannon McGibbon*
* Add `rails db:system:change` command for changing databases.
```

View file

@ -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

View file

@ -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