Permalink
Browse files

Add generator files...

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4365 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 5108fa8 commit 3115c425a0e65963f2fde5b297676d2cbd505f59 Marcel Molina committed May 23, 2006
@@ -0,0 +1,15 @@
+Description:
+ The observer generator creates stubs for a new observer.
+
+ The generator takes a observer name as its argument. The observer name may be
+ given in CamelCase or under_score and should not be suffixed with 'Observer'.
+
+ The generator creates a observer class in app/models and a test suite in
+ test/unit.
+
+Example:
+ ./script/generate observer Account
+
+ This will create an Account observer:
+ Observer: app/models/account_observer.rb
+ Test: test/unit/account_observer_test.rb
@@ -0,0 +1,16 @@
+class ObserverGenerator < Rails::Generator::NamedBase
+ def manifest
+ record do |m|
+ # Check for class naming collisions.
+ m.class_collisions class_path, "#{class_name}Observer", "#{class_name}ObserverTest"
+
+ # Observer, and test directories.
+ m.directory File.join('app/models', class_path)
+ m.directory File.join('test/unit', class_path)
+
+ # Observer class and unit test fixtures.
+ m.template 'observer.rb', File.join('app/models', class_path, "#{file_name}_observer.rb")
+ m.template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb")
+ end
+ end
+end
@@ -0,0 +1,2 @@
+class <%= class_name %>Observer < ActiveRecord::Observer
+end
@@ -0,0 +1,10 @@
+require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../test_helper'
+
+class <%= class_name %>ObserverTest < Test::Unit::TestCase
+ fixtures :<%= table_name %>
+
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end

0 comments on commit 3115c42

Please sign in to comment.