diff options
author | Gannon McGibbon <gannon.mcgibbon@gmail.com> | 2019-04-20 12:39:03 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-20 12:39:03 +0900 |
commit | d3dc651a819d95f0467b0bdad6bc85080debcc43 (patch) | |
tree | ebe50d49fc06232428024cb3b3d6e313018e1b4a | |
parent | 9057e64151428143cf182b115829d3cd6a0e94ff (diff) | |
parent | b08daf48dac4e98076a6eaad5cddc8405ec91af9 (diff) | |
download | rails-d3dc651a819d95f0467b0bdad6bc85080debcc43.tar.gz rails-d3dc651a819d95f0467b0bdad6bc85080debcc43.tar.bz2 rails-d3dc651a819d95f0467b0bdad6bc85080debcc43.zip |
Merge pull request #35896 from jlw/bug/active-jobless-seeds
[#35782] Allow loading seeds without ActiveJob (~> 5.2.3)
-rw-r--r-- | railties/CHANGELOG.md | 6 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 2 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 30 |
3 files changed, 37 insertions, 1 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 78a94f7c28..e5f9e37c33 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -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. diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index eb2f0e8fca..06b4019fc7 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -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) diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index fe5c62c07d..8ce68dbcfa 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -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'") |