Skip to content

Commit

Permalink
Use stable branch for --edge option when possible
Browse files Browse the repository at this point in the history
This alleviates the need to update the code when there is a new stable
branch (for example, as done in #41454).
  • Loading branch information
jonathanhefner committed Mar 7, 2021
1 parent c431432 commit 7762770
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion railties/lib/rails/generators/app_base.rb
Expand Up @@ -276,8 +276,9 @@ def rails_gemfile_entry
GemfileEntry.path("rails", Rails::Generators::RAILS_DEV_PATH)
]
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?
[
Expand Down
16 changes: 14 additions & 2 deletions railties/test/generators/app_generator_test.rb
Expand Up @@ -863,8 +863,20 @@ def test_dev_option
end

def test_edge_option
generator([destination_root], edge: true, skip_webpack_install: true)
run_generator_instance
Rails.stub(:gem_version, Gem::Version.new("2.1.0")) do
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_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']main["']$}
Expand Down
16 changes: 14 additions & 2 deletions railties/test/generators/plugin_generator_test.rb
Expand Up @@ -250,8 +250,20 @@ def test_dev_option
end

def test_edge_option
generator([destination_root], edge: true)
run_generator_instance
Rails.stub(:gem_version, Gem::Version.new("2.1.0")) do
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_file "Gemfile", %r{^gem\s+["']rails["'],\s+github:\s+["']#{Regexp.escape("rails/rails")}["'],\s+branch:\s+["']main["']$}
Expand Down

0 comments on commit 7762770

Please sign in to comment.