Use stable branch for --edge option when possible

This alleviates the need to update the code when there is a new stable
branch (for example, as done in #41454).
This commit is contained in:
Jonathan Hefner 2021-03-07 16:45:37 -06:00 committed by GitHub
parent c431432f93
commit 7762770805
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 5 deletions

@ -276,8 +276,9 @@ def rails_gemfile_entry
GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH) GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH)
] ]
elsif options.edge? elsif options.edge?
edge_branch = Rails.gem_version.prerelease? ? "main" : [*Rails.gem_version.segments.first(2), "stable"].join("-")
[ [
GemfileEntry.github("rails", "rails/rails", "main") GemfileEntry.github("rails", "rails/rails", edge_branch)
] ]
elsif options.main? elsif options.main?
[ [

@ -863,8 +863,20 @@ def test_dev_option
end end
def test_edge_option def test_edge_option
generator([destination_root], edge: true, skip_webpack_install: true) Rails.stub(:gem_version, Gem::Version.new("2.1.0")) do
run_generator_instance generator([destination_root], edge: true, skip_webpack_install: true)
run_generator_instance
end
assert_equal 1, @bundle_commands.count("install")
assert_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']2-1-stable["']$}
end
def test_edge_option_during_alpha
Rails.stub(:gem_version, Gem::Version.new("2.1.0.alpha")) do
generator([destination_root], edge: true, skip_webpack_install: true)
run_generator_instance
end
assert_equal 1, @bundle_commands.count("install") 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["']$} assert_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']main["']$}

@ -250,8 +250,20 @@ def test_dev_option
end end
def test_edge_option def test_edge_option
generator([destination_root], edge: true) Rails.stub(:gem_version, Gem::Version.new("2.1.0")) do
run_generator_instance generator([destination_root], edge: true)
run_generator_instance
end
assert_empty @bundle_commands
assert_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']2-1-stable["']$}
end
def test_edge_option_during_alpha
Rails.stub(:gem_version, Gem::Version.new("2.1.0.alpha")) do
generator([destination_root], edge: true)
run_generator_instance
end
assert_empty @bundle_commands assert_empty @bundle_commands
assert_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']main["']$} assert_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']main["']$}