diff options
author | bogdanvlviv <bogdanvlviv@gmail.com> | 2018-06-18 19:44:39 +0000 |
---|---|---|
committer | bogdanvlviv <bogdanvlviv@gmail.com> | 2018-06-18 19:59:21 +0000 |
commit | 1aace5e2cc7784799c2b91fb3feb2bd285c0e628 (patch) | |
tree | 01435607f74f015c3d7e0a86421c7ee5a60d6fdb /railties | |
parent | 38dbc8e2b87eb6b303180c45ccb153e72da87c44 (diff) | |
download | rails-1aace5e2cc7784799c2b91fb3feb2bd285c0e628.tar.gz rails-1aace5e2cc7784799c2b91fb3feb2bd285c0e628.tar.bz2 rails-1aace5e2cc7784799c2b91fb3feb2bd285c0e628.zip |
Fix Ruby version in `.ruby-version`
Since #30016 Rails generates `.ruby-version` file
in order to help Ruby version manager tools like `rbenv`, `rvm`
determine which Ruby version should be used for the current Rails
project.
Since #32649 Rails sets Ruby version to the file compatible with MRI/JRuby
by default.
Pull Request #31496 reports that `.ruby-version` doesn't match ruby version other
than stable version and recommends to use `ENV["RBENV_VERSION"]`, and
`ENV["rvm_ruby_string"]` in order to set correct Ruby version to the file
that `rbenv` or `rvm` can understand.
Also, there is another similar issue that reports the same case if use
JRuby https://github.com/jruby/jruby/issues/5144.
Closes #31496, https://github.com/jruby/jruby/issues/5144.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/generators/rails/app/templates/ruby-version.tt | 2 | ||||
-rw-r--r-- | railties/test/generators/app_generator_test.rb | 8 |
2 files changed, 8 insertions, 2 deletions
diff --git a/railties/lib/rails/generators/rails/app/templates/ruby-version.tt b/railties/lib/rails/generators/rails/app/templates/ruby-version.tt index 19f0d7f202..bac1339923 100644 --- a/railties/lib/rails/generators/rails/app/templates/ruby-version.tt +++ b/railties/lib/rails/generators/rails/app/templates/ruby-version.tt @@ -1 +1 @@ -<%= "#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}" -%> +<%= ENV["RBENV_VERSION"] || ENV["rvm_ruby_string"] || "#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}" -%> diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 3cb7d66bbb..d8e9ae3369 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -891,7 +891,13 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_match(/ruby '#{RUBY_VERSION}'/, content) end assert_file ".ruby-version" do |content| - assert_match(/#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}/, content) + if ENV["RBENV_VERSION"] + assert_match(/#{ENV["RBENV_VERSION"]}/, content) + elsif ENV["rvm_ruby_string"] + assert_match(/#{ENV["rvm_ruby_string"]}/, content) + else + assert_match(/#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}/, content) + end end end |