Skip to content

Commit

Permalink
Merge pull request rails#14325 from robin850/issue-12133
Browse files Browse the repository at this point in the history
Make the rails:template rake task load initializers
  • Loading branch information
spastorino committed Mar 8, 2014
2 parents 18c6516 + 9c53b8b commit 1fbb905
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* Make the `rails:template` rake task load the application's initializers.

Fixes #12133.

*Robin Dupret*

* Introduce `Rails.gem_version` as a convenience method to return
`Gem::Version.new(Rails.version)`, suggesting a more reliable way to perform
version comparison.
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/tasks/framework.rake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace :rails do
task update: [ "update:configs", "update:bin" ]

desc "Applies the template supplied by LOCATION=(/path/to/template) or URL"
task :template do
task template: :environment do
template = ENV["LOCATION"]
raise "No LOCATION value given. Please set LOCATION either as path to a file or a URL" if template.blank?
template = File.expand_path(template) if template !~ %r{\A[A-Za-z][A-Za-z0-9+\-\.]*://}
Expand Down
11 changes: 11 additions & 0 deletions railties/test/application/rake_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,5 +271,16 @@ def test_copy_templates
end
end
end

def test_template_load_initializers
app_file "config/initializers/dummy.rb", "puts 'Hello, World!'"
app_file "template.rb", ""

output = Dir.chdir(app_path) do
`bundle exec rake rails:template LOCATION=template.rb`
end

assert_match(/Hello, World!/, output)
end
end
end

0 comments on commit 1fbb905

Please sign in to comment.