diff options
author | Kir <shatrov@me.com> | 2011-12-13 15:06:36 +0400 |
---|---|---|
committer | Kir <shatrov@me.com> | 2011-12-17 16:42:35 +0400 |
commit | 5e68fed450f6e6c16f308bad0fc270777d1015f3 (patch) | |
tree | 3554f49bb44b5cced25b6b0fec94f8206b03a529 /railties | |
parent | 6bff6439b1960891669485dc978af68dab15af27 (diff) | |
download | rails-5e68fed450f6e6c16f308bad0fc270777d1015f3.tar.gz rails-5e68fed450f6e6c16f308bad0fc270777d1015f3.tar.bz2 rails-5e68fed450f6e6c16f308bad0fc270777d1015f3.zip |
Rake tasks generator with test
Diffstat (limited to 'railties')
4 files changed, 41 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/rails/task/USAGE b/railties/lib/rails/generators/rails/task/USAGE new file mode 100644 index 0000000000..dbe9bbaf08 --- /dev/null +++ b/railties/lib/rails/generators/rails/task/USAGE @@ -0,0 +1,9 @@ +Description: + Stubs out a new Rake task. Pass the namespace name, and a list of tasks as arguments. + + This generates a task file in lib/tasks. + +Example: + `rails generate task feeds fetch erase add` + + Task: lib/tasks/feeds.rake
\ No newline at end of file diff --git a/railties/lib/rails/generators/rails/task/task_generator.rb b/railties/lib/rails/generators/rails/task/task_generator.rb new file mode 100644 index 0000000000..8a62d9e8eb --- /dev/null +++ b/railties/lib/rails/generators/rails/task/task_generator.rb @@ -0,0 +1,12 @@ +module Rails + module Generators + class TaskGenerator < NamedBase + argument :actions, :type => :array, :default => [], :banner => "action action" + + def create_task_files + template 'task.rb', File.join('lib/tasks', "#{file_name}.rake") + end + + end + end +end diff --git a/railties/lib/rails/generators/rails/task/templates/task.rb b/railties/lib/rails/generators/rails/task/templates/task.rb new file mode 100644 index 0000000000..b7407bd6dc --- /dev/null +++ b/railties/lib/rails/generators/rails/task/templates/task.rb @@ -0,0 +1,8 @@ +namespace :<%= file_name %> do +<% actions.each do |action| -%> + desc "TODO" + task :<%= action %> => :environment do + end + +<% end -%> +end diff --git a/railties/test/generators/task_generator_test.rb b/railties/test/generators/task_generator_test.rb new file mode 100644 index 0000000000..f810a21d1e --- /dev/null +++ b/railties/test/generators/task_generator_test.rb @@ -0,0 +1,12 @@ +require 'generators/generators_test_helper' +require 'rails/generators/rails/task/task_generator' + +class TaskGeneratorTest < Rails::Generators::TestCase + include GeneratorsTestHelper + arguments %w(feeds foo bar) + + def test_controller_skeleton_is_created + run_generator + assert_file "lib/tasks/feeds.rake", /namespace :feeds/ + end +end |