Skip to content

Commit 0d99610

Browse files
committed
Don't add bin/brakeman if brakeman is not in bundle
Running `bin/rails app:update` with Rails 7.2.0 adds bin/brakeman even if it's not in the Gemfile already. This checks whether brakeman is in the bundle (can be required), otherwise skips brakeman for the application generator.
1 parent d7f9347 commit 0d99610

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

railties/lib/rails/commands/app/update_command.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def generator_options
6969
skip_action_mailbox: !defined?(ActionMailbox::Engine),
7070
skip_action_text: !defined?(ActionText::Engine),
7171
skip_action_cable: !defined?(ActionCable::Engine),
72+
skip_brakeman: skip_brakeman?,
7273
skip_test: !defined?(Rails::TestUnitRailtie),
7374
skip_system_test: Rails.application.config.generators.system_tests.nil?,
7475
asset_pipeline: asset_pipeline,
@@ -87,6 +88,13 @@ def asset_pipeline
8788
nil
8889
end
8990
end
91+
92+
def skip_brakeman?
93+
require "brakeman"
94+
false
95+
rescue LoadError
96+
true
97+
end
9098
end
9199
end
92100
end

railties/test/generators/app_generator_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,16 @@ def test_app_update_preserves_skip_action_text
286286
end
287287
end
288288

289+
def test_app_update_preserves_skip_brakeman
290+
run_generator [ destination_root, "--skip-brakeman" ]
291+
292+
FileUtils.cd(destination_root) do
293+
assert_no_changes -> { File.exist?("bin/brakeman") } do
294+
run_app_update
295+
end
296+
end
297+
end
298+
289299
def test_app_update_preserves_skip_test
290300
run_generator [ destination_root, "--skip-test" ]
291301

0 commit comments

Comments
 (0)