Skip to content

Commit

Permalink
Add runtime options from Thor::Actions to app:update
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebarrie committed May 2, 2024
1 parent 296ac75 commit d379fae
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
11 changes: 11 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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é*

* Implement Rails console commands and helpers with IRB v1.13's extension APIs

Rails console users will now see `helper`, `controller`, `new_session`, and `app` under
Expand Down
3 changes: 3 additions & 0 deletions railties/lib/rails/commands/app/update_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 30 additions & 2 deletions railties/test/generators/app_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d379fae

Please sign in to comment.