From 83f2f9fd24fa68a677866b7fba28229d111f67b7 Mon Sep 17 00:00:00 2001 From: Mike Rogers Date: Tue, 19 Jan 2021 21:07:32 +0000 Subject: [PATCH] Changing 'rails new' --master to be --main Renaming test containing flag Updating other test referencing master branch Add notice that --master is deprecated, but still working the same as --main Only set @main if it's nil Making warn wildcard I think a hidden aliaes would be just as good Improving description & fixing rubocop error Forgot comma Deprecation warning was kind of hard - so just doing alias for now rubocop -a --- railties/lib/rails/generators/app_base.rb | 4 ++-- .../rails/generators/rails/app/templates/Gemfile.tt | 2 +- .../rails/plugin/templates/%name%.gemspec.tt | 2 +- .../generators/rails/plugin/templates/Gemfile.tt | 2 +- railties/test/generators/app_generator_test.rb | 12 ++++++++++-- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index b41c0adcf4..4c6f5582b0 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -97,7 +97,7 @@ module Rails class_option :edge, type: :boolean, default: false, desc: "Set up the #{name} with Gemfile pointing to Rails repository" - class_option :master, type: :boolean, default: false, + class_option :main, type: :boolean, default: false, aliases: "--master", desc: "Set up the #{name} with Gemfile pointing to Rails repository main branch" class_option :rc, type: :string, default: nil, @@ -279,7 +279,7 @@ module Rails [ GemfileEntry.github("rails", "rails/rails", "main") ] - elsif options.master? + elsif options.main? [ GemfileEntry.github("rails", "rails/rails", "main") ] diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile.tt b/railties/lib/rails/generators/rails/app/templates/Gemfile.tt index d6ddc4adbb..e3e7099814 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile.tt +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile.tt @@ -46,7 +46,7 @@ end group :development do <%- unless options.api? || options.skip_dev_gems? -%> # Access an interactive console on exception pages or by calling 'console' anywhere in the code. - <%- if options.dev? || options.edge? || options.master? -%> + <%- if options.dev? || options.edge? || options.main? -%> gem 'web-console', github: 'rails/web-console' <%- else -%> gem 'web-console', '>= 4.1.0' diff --git a/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt b/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt index d353b8b89b..3c34045e9d 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/%name%.gemspec.tt @@ -20,5 +20,5 @@ Gem::Specification.new do |spec| spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"] - <%= '# ' if options.dev? || options.edge? || options.master? -%>spec.add_dependency "rails", "<%= Array(rails_version_specifier).join('", "') %>" + <%= '# ' if options.dev? || options.edge? || options.main? -%>spec.add_dependency "rails", "<%= Array(rails_version_specifier).join('", "') %>" end diff --git a/railties/lib/rails/generators/rails/plugin/templates/Gemfile.tt b/railties/lib/rails/generators/rails/plugin/templates/Gemfile.tt index 65e028db18..7776116a76 100644 --- a/railties/lib/rails/generators/rails/plugin/templates/Gemfile.tt +++ b/railties/lib/rails/generators/rails/plugin/templates/Gemfile.tt @@ -2,7 +2,7 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } <% if options[:skip_gemspec] -%> -<%= '# ' if options.dev? || options.edge? || options.master? -%>gem 'rails', '<%= Array(rails_version_specifier).join("', '") %>' +<%= '# ' if options.dev? || options.edge? || options.main? -%>gem 'rails', '<%= Array(rails_version_specifier).join("', '") %>' <% else -%> # Specify your gem's dependencies in <%= name %>.gemspec. gemspec diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 82a17b9755..e14687be6b 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -809,8 +809,8 @@ class AppGeneratorTest < Rails::Generators::TestCase end end - def test_web_console_with_master_option - run_generator [destination_root, "--master"] + def test_web_console_with_main_option + run_generator [destination_root, "--main"] assert_file "Gemfile" do |content| assert_match(/gem 'web-console',\s+github: 'rails\/web-console'/, content) @@ -868,6 +868,14 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']main["']$} end + def test_main_option + generator([destination_root], main: true, skip_webpack_install: true) + run_generator_instance + + assert_equal 1, @bundle_commands.count("install") + assert_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']main["']$} + end + def test_spring jruby_skip "spring doesn't run on JRuby"