Skip to content

Commit

Permalink
Do not run active_storage:install when bundle install is skipped
Browse files Browse the repository at this point in the history
In order to execute the `rails` command, need to run bundle install in
advance.
Therefore, if skipped bundle install, `rails` command may fail and
should not do it.
  • Loading branch information
y-yagi committed Nov 8, 2017
1 parent daf77db commit 67db41a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
6 changes: 5 additions & 1 deletion railties/lib/rails/generators/app_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,11 @@ def generate_spring_binstubs

def run_active_storage
unless skip_active_storage?
rails_command "active_storage:install", capture: options[:quiet]
if bundle_install?
rails_command "active_storage:install", capture: options[:quiet]
else
log("Active Storage installation was skipped. Please run 'bin/rails active_storage:install' to install Active Storage files.")
end
end
end

Expand Down
16 changes: 15 additions & 1 deletion railties/test/generators/app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
config/spring.rb
config/storage.yml
db
db/migrate
db/seeds.rb
lib
lib/tasks
Expand Down Expand Up @@ -304,6 +303,21 @@ def test_active_storage_mini_magick_gem
assert_file "Gemfile", /^# gem 'mini_magick'/
end

def test_active_storage_install
command_check = -> command, _ do
@binstub_called ||= 0
case command
when "active_storage:install"
@binstub_called += 1
assert_equal 1, @binstub_called, "active_storage:install expected to be called once, but was called #{@install_called} times."
end
end

generator.stub :rails_command, command_check do
quietly { generator.invoke_all }
end
end

def test_app_update_does_not_generate_active_storage_contents_when_skip_active_storage_is_given
app_root = File.join(destination_root, "myapp")
run_generator [app_root, "--skip-active-storage"]
Expand Down
1 change: 0 additions & 1 deletion railties/test/generators/shared_generator_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ def test_generator_for_active_storage
end

assert_file "#{application_path}/config/storage.yml"
assert_directory "#{application_path}/db/migrate"
assert_directory "#{application_path}/storage"
assert_directory "#{application_path}/tmp/storage"

Expand Down
4 changes: 4 additions & 0 deletions railties/test/railties/engine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def up
boot_rails

Dir.chdir(app_path) do
# Install Active Storage migration file first so as not to affect test.
`bundle exec rake active_storage:install`
output = `bundle exec rake bukkits:install:migrations`

["CreateUsers", "AddLastNameToUsers", "CreateSessions"].each do |migration_name|
Expand Down Expand Up @@ -175,6 +177,8 @@ class CreateKeys < ActiveRecord::Migration::Current; end
boot_rails

Dir.chdir(app_path) do
# Install Active Storage migration file first so as not to affect test.
`bundle exec rake active_storage:install`
output = `bundle exec rake railties:install:migrations`.split("\n")

assert_match(/Copied migration \d+_create_users\.core_engine\.rb from core_engine/, output.first)
Expand Down

0 comments on commit 67db41a

Please sign in to comment.