diff options
author | willnet <netwillnet@gmail.com> | 2017-07-22 00:01:40 +0900 |
---|---|---|
committer | willnet <netwillnet@gmail.com> | 2017-11-22 09:27:59 +0900 |
commit | 424debb096c670404428141b13de2af0185c9675 (patch) | |
tree | 818bd1c171b77c75ec1420b8601bd47e1b604322 /railties | |
parent | 4d5f0bb30b5ac76407c9864b83b69b8a83ac3dd6 (diff) | |
download | rails-424debb096c670404428141b13de2af0185c9675.tar.gz rails-424debb096c670404428141b13de2af0185c9675.tar.bz2 rails-424debb096c670404428141b13de2af0185c9675.zip |
Fix generator suggestion raise error when I18n.available_locales don’t include :en
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators.rb | 3 | ||||
-rw-r--r-- | railties/test/generators_test.rb | 13 |
2 files changed, 15 insertions, 1 deletions
diff --git a/railties/lib/rails/generators.rb b/railties/lib/rails/generators.rb index 5592e8d78e..6c9c109f17 100644 --- a/railties/lib/rails/generators.rb +++ b/railties/lib/rails/generators.rb @@ -274,8 +274,9 @@ module Rails else options = sorted_groups.flat_map(&:last) suggestions = options.sort_by { |suggested| levenshtein_distance(namespace.to_s, suggested) }.first(3) + suggestions.map! { |s| "'#{s}'" } msg = "Could not find generator '#{namespace}'. ".dup - msg << "Maybe you meant #{ suggestions.map { |s| "'#{s}'" }.to_sentence(last_word_connector: " or ", locale: :en) }\n" + msg << "Maybe you meant #{ suggestions[0...-1].join(', ')} or #{suggestions[-1]}\n" msg << "Run `rails generate --help` for more options." puts msg end diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 28e7617d7f..1735804664 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -36,6 +36,19 @@ class GeneratorsTest < Rails::Generators::TestCase assert_match "Maybe you meant 'migration'", output end + def test_generator_suggestions_except_en_locale + orig_available_locales = I18n.available_locales + orig_default_locale = I18n.default_locale + I18n.available_locales = :ja + I18n.default_locale = :ja + name = :tas + output = capture(:stdout) { Rails::Generators.invoke name } + assert_match "Maybe you meant 'task', 'job' or", output + ensure + I18n.available_locales = orig_available_locales + I18n.default_locale = orig_default_locale + end + def test_generator_multiple_suggestions name = :tas output = capture(:stdout) { Rails::Generators.invoke name } |