提交 a6bf032b 编写于 作者: G Gannon McGibbon

Merge pull request #35896 from jlw/bug/active-jobless-seeds

[#35782] Allow loading seeds without ActiveJob (~> 5.2.3)
上级 c617cc6b
* Allow loading seeds without ActiveJob.
Fixes #35782
*Jeremy Weathers*
* Only force `:async` ActiveJob adapter to `:inline` during seeding.
*BatedUrGonnaDie*
......
......@@ -550,7 +550,7 @@ def load_seed
seed_file = paths["db/seeds.rb"].existent.first
return unless seed_file
if config.active_job.queue_adapter == :async
if config.try(:active_job)&.queue_adapter == :async
with_inline_jobs { load(seed_file) }
else
load(seed_file)
......
......@@ -905,6 +905,32 @@ def index
assert_instance_of ActiveJob::QueueAdapters::DelayedJobAdapter, ActiveJob::Base.queue_adapter
end
test "seed data can be loaded when ActiveJob is not present" do
@plugin.write "db/seeds.rb", <<-RUBY
Bukkits::Engine.config.bukkits_seeds_loaded = true
RUBY
app_file "db/seeds.rb", <<-RUBY
Rails.application.config.app_seeds_loaded = true
RUBY
boot_rails
# In a real app, config.active_job would be undefined when
# NOT requiring rails/all AND NOT requiring active_job/railtie
# that doesn't work as expected in this test environment, so:
undefine_config_option(:active_job)
assert_raise(NoMethodError) { Rails.application.config.active_job }
assert_raise(NoMethodError) { Rails.application.config.app_seeds_loaded }
assert_raise(NoMethodError) { Bukkits::Engine.config.bukkits_seeds_loaded }
Rails.application.load_seed
assert Rails.application.config.app_seeds_loaded
Bukkits::Engine.load_seed
assert Bukkits::Engine.config.bukkits_seeds_loaded
end
test "skips nonexistent seed data" do
FileUtils.rm "#{app_path}/db/seeds.rb"
boot_rails
......@@ -1523,5 +1549,9 @@ def index
def app
Rails.application
end
def undefine_config_option(name)
Rails.application.config.class.class_variable_get(:@@options).delete(name)
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册