diff options
author | Guillermo Iguaran <guilleiguaran@gmail.com> | 2017-07-31 14:04:25 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-31 14:04:25 -0500 |
commit | 0d58e7e478e79c2d6b2a39a4444d2a17a903b2a6 (patch) | |
tree | c20963ef6b2e33e35c016180069df849a450703b /railties | |
parent | 0f245882c9c8cdf15dcbb958680f7f2ea4f7d76a (diff) | |
parent | fd7f978a5068921380308fe439af3923566c8f61 (diff) | |
download | rails-0d58e7e478e79c2d6b2a39a4444d2a17a903b2a6.tar.gz rails-0d58e7e478e79c2d6b2a39a4444d2a17a903b2a6.tar.bz2 rails-0d58e7e478e79c2d6b2a39a4444d2a17a903b2a6.zip |
Merge pull request #30016 from albertoalmagro/set-ruby-version-in-gemfile-and-ruby-version-by-default
Set Ruby version in Gemfile and .ruby-version by default
Diffstat (limited to 'railties')
5 files changed, 25 insertions, 0 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 45e1f5f3ea..ec41d17a9f 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,9 @@ +* Add `ruby x.x.x` version to `Gemfile` and create `.ruby-version` + root file containing current Ruby version when new Rails applications are + created. + + *Alberto Almagro* + * Support `-` as a platform-agnostic way to run a script from stdin with `rails runner` diff --git a/railties/lib/rails/generators/rails/app/app_generator.rb b/railties/lib/rails/generators/rails/app/app_generator.rb index 7a59f106e3..507099ef57 100644 --- a/railties/lib/rails/generators/rails/app/app_generator.rb +++ b/railties/lib/rails/generators/rails/app/app_generator.rb @@ -49,6 +49,10 @@ module Rails copy_file "README.md", "README.md" end + def ruby_version + template "ruby-version", ".ruby-version" + end + def gemfile template "Gemfile" end @@ -242,6 +246,7 @@ module Rails def create_root_files build(:readme) build(:rakefile) + build(:ruby_version) build(:configru) build(:gitignore) unless options[:skip_git] build(:gemfile) unless options[:skip_gemfile] diff --git a/railties/lib/rails/generators/rails/app/templates/Gemfile b/railties/lib/rails/generators/rails/app/templates/Gemfile index f49b503f85..4b2842ef46 100644 --- a/railties/lib/rails/generators/rails/app/templates/Gemfile +++ b/railties/lib/rails/generators/rails/app/templates/Gemfile @@ -1,5 +1,6 @@ source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } +ruby <%= "'#{RUBY_VERSION}'" %> <% gemfile_entries.each do |gem| -%> <% if gem.comment -%> diff --git a/railties/lib/rails/generators/rails/app/templates/ruby-version b/railties/lib/rails/generators/rails/app/templates/ruby-version new file mode 100644 index 0000000000..c444f33b0f --- /dev/null +++ b/railties/lib/rails/generators/rails/app/templates/ruby-version @@ -0,0 +1 @@ +<%= RUBY_VERSION -%> diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index ffdee3a6b5..aec73b6955 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -4,6 +4,7 @@ require "generators/shared_generator_tests" DEFAULT_APP_FILES = %w( .gitignore + .ruby-version README.md Gemfile Rakefile @@ -805,6 +806,17 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_inclusion_of_ruby_version + run_generator + + assert_file "Gemfile" do |content| + assert_match(/ruby '#{RUBY_VERSION}'/, content) + end + assert_file ".ruby-version" do |content| + assert_match(/#{RUBY_VERSION}/, content) + end + end + def test_version_control_initializes_git_repo run_generator [destination_root] assert_directory ".git" |