diff --git a/activestorage/lib/tasks/activestorage.rake b/activestorage/lib/tasks/activestorage.rake index 6b0469636c..142a5796ca 100644 --- a/activestorage/lib/tasks/activestorage.rake +++ b/activestorage/lib/tasks/activestorage.rake @@ -17,6 +17,10 @@ namespace :active_storage do task update: :environment do ENV["MIGRATIONS_PATH"] = "db/update_migrate" - Rake::Task["active_storage:install"].invoke + if Rake::Task.task_defined?("active_storage:install") + Rake::Task["active_storage:install"].invoke + else + Rake::Task["app:active_storage:install"].invoke + end end end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 8bcd4139d7..23aac0e924 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -1613,6 +1613,21 @@ en: end end + test "active_storage:update task works within engine" do + @plugin.write "Rakefile", <<-RUBY + APP_RAKEFILE = '#{app_path}/Rakefile' + load "rails/tasks/engine.rake" + RUBY + + Dir.chdir(@plugin.path) do + output = `bundle exec rake app:active_storage:update` + assert $?.success?, output + + assert migrations.detect { |migration| migration.name == "AddServiceNameToActiveStorageBlobs" } + assert migrations.detect { |migration| migration.name == "CreateActiveStorageVariantRecords" } + end + end + private def app Rails.application