From 144be4c767e39bf398a3ecec85575c0e7131a2c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Barri=C3=A9?= Date: Tue, 30 Apr 2024 14:41:03 +0200 Subject: [PATCH] Add runtime options from Thor::Actions to app:update --- railties/CHANGELOG.md | 11 +++++++ .../lib/rails/commands/app/update_command.rb | 3 ++ .../test/generators/app_generator_test.rb | 32 +++++++++++++++++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 5cff64f07e157..e137f24d88b3a 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,14 @@ +* Add options to bin/rails app:update. + + `bin/rails app:update` now supports the same generic options that generators do: + + * `--force`: Accept all changes to existing files + * `--skip`: Refuse all changes to existing files + * `--pretend`: Don't make any changes + * `--quiet`: Don't output all changes made + + *Étienne Barrié* + * Allow Actionable Errors encountered when running tests to be retried. ```txt diff --git a/railties/lib/rails/commands/app/update_command.rb b/railties/lib/rails/commands/app/update_command.rb index cd0d807e4d5ce..50fc6e674e568 100644 --- a/railties/lib/rails/commands/app/update_command.rb +++ b/railties/lib/rails/commands/app/update_command.rb @@ -7,6 +7,9 @@ module Rails module Command module App class UpdateCommand < Base # :nodoc: + include Thor::Actions + add_runtime_options! + desc "update", "Update configs and some other initially generated files (or use just update:configs or update:bin)" def perform configs diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index b36768c7d8714..10871ccc6b48d 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -188,6 +188,34 @@ def test_app_update_create_new_framework_defaults assert_file defaults_path end + def test_app_update_supports_skip + run_generator + FileUtils.cd(destination_root) do + config = "config/application.rb" + File.open(config, "a") do |file| + file.puts "# some configuration" + end + assert_no_changes -> { File.readlines(config) } do + run_app_update(flags: "--skip") + end + end + end + + def test_app_update_supports_pretend + run_generator + FileUtils.cd(destination_root) do + config = "config/application.rb" + File.open(config, "a") do |file| + file.puts "# some configuration" + end + assert_no_changes -> { File.readlines(config) } do + run_app_update(flags: "--pretend --force") + end + defaults_path = "config/initializers/new_framework_defaults_#{Rails::VERSION::MAJOR}_#{Rails::VERSION::MINOR}.rb" + assert_no_file defaults_path + end + end + def test_app_update_does_not_create_rack_cors run_generator run_app_update @@ -1500,13 +1528,13 @@ def run_generator_and_bundler(args) end end - def run_app_update(app_root = destination_root) + def run_app_update(app_root = destination_root, flags: "--force") Dir.chdir(app_root) do gemfile_contents = File.read("Gemfile") gemfile_contents.sub!(/^(gem "rails").*/, "\\1, path: #{File.expand_path("../../..", __dir__).inspect}") File.write("Gemfile", gemfile_contents) - quietly { system({ "BUNDLE_GEMFILE" => "Gemfile" }, "yes | bin/rails app:update", exception: true) } + quietly { system({ "BUNDLE_GEMFILE" => "Gemfile" }, "bin/rails app:update #{flags}", exception: true) } end end