Skip to content

Commit

Permalink
Merge pull request rails#41199 from jmalcic/patch-2
Browse files Browse the repository at this point in the history
Fix Active Storage update task when running in an engine
  • Loading branch information
eugeneius authored May 26, 2021
2 parents 56cfefe + 3787ffe commit 5a8d7d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion activestorage/lib/tasks/activestorage.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions railties/test/railties/engine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,21 @@ def index
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
Expand Down

0 comments on commit 5a8d7d9

Please sign in to comment.