Skip to content

Switch template task name depending on Rails version #1796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,17 @@ namespace :generate do

desc "generate a bunch of stuff with generators"
task :stuff do
in_example_app "bin/rake rails:template LOCATION='../../example_app_generator/generate_stuff.rb'"
in_example_app "bin/rake #{template_task_name} LOCATION='../../example_app_generator/generate_stuff.rb'"
end
end

def template_task_name
gem 'rails'

if Gem.loaded_specs['rails'].version >= Gem::Version.create('5.0')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should just be able to check the rails version from it's constant, we try to avoid using rubygems where possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "check the rails version from it's constant" mean ?

require 'rails'

if Rails.version >= '5.0'
...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

"app:template"
else
"rails:template"
end
end

Expand Down Expand Up @@ -90,7 +100,7 @@ end

desc "run a variety of specs against the generated app"
task :smoke do
in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rake rails:template --backtrace"
in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rake #{template_task_name} --backtrace"
end

namespace :smoke do
Expand Down Expand Up @@ -131,7 +141,7 @@ namespace :no_active_record do

desc "run a variety of specs against a non-ActiveRecord generated app"
task :smoke do
in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rake rails:template --backtrace",
in_example_app "LOCATION='../../example_app_generator/run_specs.rb' bin/rake #{template_task_name} --backtrace",
:app_dir => example_app_dir
end

Expand Down Expand Up @@ -180,7 +190,7 @@ namespace :no_active_record do

desc "generate a bunch of stuff with generators"
task :stuff do
in_example_app "bin/rake rails:template LOCATION='../../example_app_generator/generate_stuff.rb'",
in_example_app "bin/rake #{template_task_name} LOCATION='../../example_app_generator/generate_stuff.rb'",
:app_dir => example_app_dir
end
end
Expand Down