Skip to content

Commit

Permalink
Don't add bin/rubocop if rubocop is not in Gemfile
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebarrie committed Aug 12, 2024
1 parent 0d99610 commit fa8133a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 4 additions & 3 deletions railties/lib/rails/commands/app/update_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def generator_options
skip_action_mailbox: !defined?(ActionMailbox::Engine),
skip_action_text: !defined?(ActionText::Engine),
skip_action_cable: !defined?(ActionCable::Engine),
skip_brakeman: skip_brakeman?,
skip_brakeman: skip_gem?("brakeman"),
skip_rubocop: skip_gem?("rubocop"),
skip_test: !defined?(Rails::TestUnitRailtie),
skip_system_test: Rails.application.config.generators.system_tests.nil?,
asset_pipeline: asset_pipeline,
Expand All @@ -89,8 +90,8 @@ def asset_pipeline
end
end

def skip_brakeman?
require "brakeman"
def skip_gem?(gem_name)
require gem_name
false
rescue LoadError
true
Expand Down
10 changes: 10 additions & 0 deletions railties/test/generators/app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,16 @@ def test_app_update_preserves_skip_brakeman
end
end

def test_app_update_preserves_skip_rubocop
run_generator [ destination_root, "--skip-rubocop" ]

FileUtils.cd(destination_root) do
assert_no_changes -> { File.exist?("bin/rubocop") } do
run_app_update
end
end
end

def test_app_update_preserves_skip_test
run_generator [ destination_root, "--skip-test" ]

Expand Down

0 comments on commit fa8133a

Please sign in to comment.