diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 31c443bb9f48e99f9bc0fe5726ff6385dc59b1e3..73793be78c161aa29cd3856f7171facc5a597708 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -2,6 +2,12 @@ *Yuji Yaginuma* +* Add `ruby x.x.x` version to `Gemfile` and create `.ruby-version` + root file containing the 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 6d0b668f05b526198a39b682114292b0e6f6649d..cbe68823d469ff1eb0a8b11da56d07df7e0c1b03 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 @@ def readme copy_file "README.md", "README.md" end + def ruby_version + template "ruby-version", ".ruby-version" + end + def gemfile template "Gemfile" end @@ -253,6 +257,7 @@ def initialize(*args) 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/ruby-version b/railties/lib/rails/generators/rails/app/templates/ruby-version new file mode 100644 index 0000000000000000000000000000000000000000..c444f33b0f0e44c7f526b86905c28d008e3de106 --- /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 3e9f19fa9a8bfa3cdcbb45e2c324951da0b12474..44c4688aa47faff345d6d6097583d5e5248e613f 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -4,6 +4,7 @@ DEFAULT_APP_FILES = %w( .gitignore + .ruby-version README.md Gemfile Rakefile @@ -808,6 +809,17 @@ def test_gitignore_when_non_sqlite3_db 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"