Skip to content
This repository
Browse code

Rake tasks generator with test

  • Loading branch information...
commit 5e68fed450f6e6c16f308bad0fc270777d1015f3 1 parent 6bff643
Kir Shatrov authored December 13, 2011
9  railties/lib/rails/generators/rails/task/USAGE
... ...
@@ -0,0 +1,9 @@
  1
+Description:
  2
+    Stubs out a new Rake task. Pass the namespace name, and a list of tasks as arguments.
  3
+
  4
+    This generates a task file in lib/tasks.
  5
+
  6
+Example:
  7
+    `rails generate task feeds fetch erase add`
  8
+
  9
+        Task:      lib/tasks/feeds.rake
12  railties/lib/rails/generators/rails/task/task_generator.rb
... ...
@@ -0,0 +1,12 @@
  1
+module Rails
  2
+  module Generators
  3
+    class TaskGenerator < NamedBase
  4
+      argument :actions, :type => :array, :default => [], :banner => "action action"
  5
+
  6
+      def create_task_files
  7
+        template 'task.rb', File.join('lib/tasks', "#{file_name}.rake")
  8
+      end
  9
+
  10
+    end
  11
+  end
  12
+end
8  railties/lib/rails/generators/rails/task/templates/task.rb
... ...
@@ -0,0 +1,8 @@
  1
+namespace :<%= file_name %> do
  2
+<% actions.each do |action| -%>
  3
+  desc "TODO"
  4
+  task :<%= action %> => :environment do
  5
+  end
  6
+
  7
+<% end -%>
  8
+end
12  railties/test/generators/task_generator_test.rb
... ...
@@ -0,0 +1,12 @@
  1
+require 'generators/generators_test_helper'
  2
+require 'rails/generators/rails/task/task_generator'
  3
+
  4
+class TaskGeneratorTest < Rails::Generators::TestCase
  5
+  include GeneratorsTestHelper
  6
+  arguments %w(feeds foo bar)
  7
+
  8
+  def test_controller_skeleton_is_created
  9
+    run_generator
  10
+    assert_file "lib/tasks/feeds.rake", /namespace :feeds/
  11
+  end
  12
+end

0 notes on commit 5e68fed

Please sign in to comment.
Something went wrong with that request. Please try again.