Skip to content

Commit

Permalink
Respect --force option for config/master.key
Browse files Browse the repository at this point in the history
This is similar to #30700 which ensures the `--quiet` option of `rails new`
is respected by the `MasterKeyGenerator` (missing from #30067).

Before this commit, running `rails new app --force` would still prompt the
user what to do with the conflict in `config/master.key`:

```
              …
   identical  config/locales/en.yml
    conflict  config/master.key
Overwrite /Users/claudiob/Desktop/pizza/config/master.key? (enter "h" for help) [Ynaqdh]
```

After this commit, `config/master.key` is overwritten:

```
           …
identical  config/locales/en.yml
    force  config/master.key
   append  .gitignore
```

The newly added test generates an app and then generates it again with
`--force`. Without this commit, the test would just wait forever for user
input.
  • Loading branch information
claudiob committed Feb 11, 2018
1 parent a2a752d commit 24284fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion railties/lib/rails/generators/rails/app/app_generator.rb
Expand Up @@ -167,7 +167,7 @@ def master_key
return if options[:pretend] || options[:dummy_app]

require "rails/generators/rails/master_key/master_key_generator"
master_key_generator = Rails::Generators::MasterKeyGenerator.new([], quiet: options[:quiet])
master_key_generator = Rails::Generators::MasterKeyGenerator.new([], quiet: options[:quiet], force: options[:force])
master_key_generator.add_master_key_file_silently
master_key_generator.ignore_master_key_file_silently
end
Expand Down
6 changes: 6 additions & 0 deletions railties/test/generators/app_generator_test.rb
Expand Up @@ -638,6 +638,12 @@ def test_quiet_option
assert_empty output
end

def test_force_option
run_generator [File.join(destination_root, "myapp")]
output = run_generator [File.join(destination_root, "myapp"), "--force"]
assert_match(/force/, output)
end

def test_application_name_with_spaces
path = File.join(destination_root, "foo bar")

Expand Down

0 comments on commit 24284fd

Please sign in to comment.