Skip to content

Commit 707b5cb

Browse files
committed
Revert "Merge pull request rails#49360 from skipkayhil/hm-gemfile-ruby-file"
This reverts commit 6985c3b, reversing changes made to 3163bb7. Reason: While we want to apply this change, it make bundle being more strict about the ruby version. This is particularly problematic for the devcontainer images that don't support defining which patch version of ruby to install. Right now, you can only say you want Ruby 3.2, which could mean 3.2.3 or 3.2.0. If for some reason the devcontainer image doesn't match the patch version on `.ruby-version` it will fail to install. We are planning to solve this problem by publishing our own ruby images that allow defining the patch level, but until that we can't apply this change.
1 parent 53deefa commit 707b5cb

File tree

6 files changed

+5
-27
lines changed

6 files changed

+5
-27
lines changed

railties/CHANGELOG.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
* Use `ruby file: ".ruby-version"` in generated Gemfile if supported.
2-
3-
*Hartley McGuire*
4-
51
* `bin/rails test` will no longer load files named `*_test.rb` if they are located in the `fixtures` folder.
62

73
*Edouard Chin*

railties/lib/rails/generators/app_base.rb

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -436,20 +436,8 @@ def to_s
436436
end
437437
end
438438

439-
def gem_ruby_entry
440-
if Gem::Version.new(Bundler::VERSION) >= Gem::Version.new("2.4.20") # add file: option to #ruby
441-
'ruby file: ".ruby-version"'
442-
else
443-
"ruby \"#{gem_ruby_version}\""
444-
end
445-
end
446-
447439
def gem_ruby_version
448-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new("3.3.13") # patch level removed from Gem.ruby_version
449-
Gem.ruby_version
450-
else
451-
RUBY_VERSION
452-
end
440+
Gem::Version.new(Gem::VERSION) >= Gem::Version.new("3.3.13") ? Gem.ruby_version : RUBY_VERSION
453441
end
454442

455443
def rails_prerelease?

railties/lib/rails/generators/rails/app/templates/Dockerfile.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ RUN curl -fsSL https://bun.sh/install | bash -s -- "bun-v${BUN_VERSION}"
4242

4343
<% end -%>
4444
# Install application gems
45-
COPY .ruby-version Gemfile Gemfile.lock ./
45+
COPY Gemfile Gemfile.lock ./
4646
RUN bundle install && \
4747
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git<% if depend_on_bootsnap? -%> && \
4848
bundle exec bootsnap precompile --gemfile<% end %>

railties/lib/rails/generators/rails/app/templates/Gemfile.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
source "https://rubygems.org"
22

3-
<%= gem_ruby_entry %>
3+
ruby <%= "\"#{gem_ruby_version}\"" -%>
44

55
<% gemfile_entries.each do |gemfile_entry| -%>
66
<%= gemfile_entry %>

railties/test/generators/app_generator_test.rb

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,13 +1006,7 @@ def test_inclusion_of_ruby_version
10061006
run_generator
10071007

10081008
assert_file "Gemfile" do |content|
1009-
if Gem::Version.new(Bundler::VERSION) >= Gem::Version.new("2.4.20") # add file: option to #ruby
1010-
assert_match('ruby file: ".ruby-version"', content)
1011-
elsif Gem::Version.new(Gem::VERSION) >= Gem::Version.new("3.3.13") # patch level removed from Gem.ruby_version
1012-
assert_match("ruby \"#{Gem.ruby_version}\"", content)
1013-
else
1014-
assert_match("ruby \"#{RUBY_VERSION}\"", content)
1015-
end
1009+
assert_match(/ruby "#{Gem::Version.new(Gem::VERSION) >= Gem::Version.new("3.3.13") ? Gem.ruby_version : RUBY_VERSION}"/, content)
10161010
end
10171011
assert_file "Dockerfile" do |content|
10181012
assert_match(/ARG RUBY_VERSION=#{Gem::Version.new(Gem::VERSION) >= Gem::Version.new("3.3.13") ? Gem.ruby_version : RUBY_VERSION}/, content)

railties/test/generators/generators_test_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def evaluate_template_docker(file)
100100
private
101101
def gemfile_locals
102102
{
103-
gem_ruby_entry: "ruby \"#{RUBY_VERSION}\"",
103+
gem_ruby_version: RUBY_VERSION,
104104
rails_prerelease: false,
105105
skip_active_storage: true,
106106
depend_on_bootsnap: false,

0 commit comments

Comments
 (0)