mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
[#35782] Allow loading seeds without ActiveJob (~> 5.2.3)
This commit is contained in:
parent
1a5381ff0c
commit
b08daf48da
3 changed files with 37 additions and 1 deletions
|
@ -1,3 +1,9 @@
|
|||
* Allow loading seeds without ActiveJob.
|
||||
|
||||
Fixes #35782
|
||||
|
||||
*Jeremy Weathers*
|
||||
|
||||
* `null: false` is set in the migrations by default for column pointed by
|
||||
`belongs_to` / `references` association generated by model generator.
|
||||
|
||||
|
|
|
@ -552,7 +552,7 @@ module Rails
|
|||
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)
|
||||
|
|
|
@ -904,6 +904,32 @@ YAML
|
|||
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,6 +1549,10 @@ YAML
|
|||
Rails.application
|
||||
end
|
||||
|
||||
def undefine_config_option(name)
|
||||
Rails.application.config.class.class_variable_get(:@@options).delete(name)
|
||||
end
|
||||
|
||||
# Restrict frameworks to load in order to avoid engine frameworks affect tests.
|
||||
def restrict_frameworks
|
||||
remove_from_config("require 'rails/all'")
|
||||
|
|
Loading…
Reference in a new issue