Skip to content

Commit d379fae

Browse files
committed
Add runtime options from Thor::Actions to app:update
1 parent 296ac75 commit d379fae

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

railties/CHANGELOG.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
* Add options to bin/rails app:update.
2+
3+
`bin/rails app:update` now supports the same generic options that generators do:
4+
5+
* `--force`: Accept all changes to existing files
6+
* `--skip`: Refuse all changes to existing files
7+
* `--pretend`: Don't make any changes
8+
* `--quiet`: Don't output all changes made
9+
10+
*Étienne Barrié*
11+
112
* Implement Rails console commands and helpers with IRB v1.13's extension APIs
213

314
Rails console users will now see `helper`, `controller`, `new_session`, and `app` under

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

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ module Rails
77
module Command
88
module App
99
class UpdateCommand < Base # :nodoc:
10+
include Thor::Actions
11+
add_runtime_options!
12+
1013
desc "update", "Update configs and some other initially generated files (or use just update:configs or update:bin)"
1114
def perform
1215
configs

railties/test/generators/app_generator_test.rb

+30-2
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,34 @@ def test_app_update_create_new_framework_defaults
188188
assert_file defaults_path
189189
end
190190

191+
def test_app_update_supports_skip
192+
run_generator
193+
FileUtils.cd(destination_root) do
194+
config = "config/application.rb"
195+
File.open(config, "a") do |file|
196+
file.puts "# some configuration"
197+
end
198+
assert_no_changes -> { File.readlines(config) } do
199+
run_app_update(flags: "--skip")
200+
end
201+
end
202+
end
203+
204+
def test_app_update_supports_pretend
205+
run_generator
206+
FileUtils.cd(destination_root) do
207+
config = "config/application.rb"
208+
File.open(config, "a") do |file|
209+
file.puts "# some configuration"
210+
end
211+
assert_no_changes -> { File.readlines(config) } do
212+
run_app_update(flags: "--pretend --force")
213+
end
214+
defaults_path = "config/initializers/new_framework_defaults_#{Rails::VERSION::MAJOR}_#{Rails::VERSION::MINOR}.rb"
215+
assert_no_file defaults_path
216+
end
217+
end
218+
191219
def test_app_update_does_not_create_rack_cors
192220
run_generator
193221
run_app_update
@@ -1500,13 +1528,13 @@ def run_generator_and_bundler(args)
15001528
end
15011529
end
15021530

1503-
def run_app_update(app_root = destination_root)
1531+
def run_app_update(app_root = destination_root, flags: "--force")
15041532
Dir.chdir(app_root) do
15051533
gemfile_contents = File.read("Gemfile")
15061534
gemfile_contents.sub!(/^(gem "rails").*/, "\\1, path: #{File.expand_path("../../..", __dir__).inspect}")
15071535
File.write("Gemfile", gemfile_contents)
15081536

1509-
quietly { system({ "BUNDLE_GEMFILE" => "Gemfile" }, "yes | bin/rails app:update", exception: true) }
1537+
quietly { system({ "BUNDLE_GEMFILE" => "Gemfile" }, "bin/rails app:update #{flags}", exception: true) }
15101538
end
15111539
end
15121540

0 commit comments

Comments
 (0)