Skip to content

Commit

Permalink
fixed hobo_model_controller generator - added missing view.html.erb t…
Browse files Browse the repository at this point in the history
…emplate
  • Loading branch information
drnic committed May 12, 2008
1 parent 149fa2b commit 3d8f747
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 2 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def manifest

# View template for each action.
actions.each do |action|
path = File.join('app/views', class_path, file_name, "#{action}.rhtml")
m.template 'view.rhtml', path,
path = File.join('app/views', class_path, file_name, "#{action}.html.erb")
m.template 'view.html.erb', path,
:assigns => { :action => action, :path => path }
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1><%= class_name %>#<%= action %></h1>
<p>Find me in <%= path %></p>
29 changes: 29 additions & 0 deletions hobo/test/test_generator_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
begin
require File.dirname(__FILE__) + '/test_helper'
rescue LoadError
require 'test/unit'
end
require 'fileutils'

# Must set before requiring generator libs.
TMP_ROOT = File.dirname(__FILE__) + "/tmp" unless defined?(TMP_ROOT)
PROJECT_NAME = "myproject" unless defined?(PROJECT_NAME)
app_root = File.join(TMP_ROOT, PROJECT_NAME)
if defined?(APP_ROOT)
APP_ROOT.replace(app_root)
else
APP_ROOT = app_root
end
if defined?(RAILS_ROOT)
RAILS_ROOT.replace(app_root)
else
RAILS_ROOT = app_root
end

begin
require 'rubigen'
rescue LoadError
require 'rubygems'
require 'rubigen'
end
require 'rubigen/helpers/generator_test_helper'
1 change: 1 addition & 0 deletions hobo/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'test/unit'
70 changes: 70 additions & 0 deletions hobo/test/test_hobo_model_controller_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require File.join(File.dirname(__FILE__), "test_generator_helper.rb")

require 'rails_generator'

class TestHoboModelControllerGenerator < Test::Unit::TestCase
include RubiGen::GeneratorTestHelper

def setup
bare_setup
end

def teardown
bare_teardown
end

# Some generator-related assertions:
# assert_generated_file(name, &block) # block passed the file contents
# assert_directory_exists(name)
# assert_generated_class(name, &block)
# assert_generated_module(name, &block)
# assert_generated_test_for(name, &block)
# The assert_generated_(class|module|test_for) &block is passed the body of the class/module within the file
# assert_has_method(body, *methods) # check that the body has a list of methods (methods with parentheses not supported yet)
#
# Other helper methods are:
# app_root_files - put this in teardown to show files generated by the test method (e.g. p app_root_files)
# bare_setup - place this in setup method to create the APP_ROOT folder for each test
# bare_teardown - place this in teardown method to destroy the TMP_ROOT or APP_ROOT folder after each test

def test_generator_without_options
name = "MyModel"
run_generator('hobo_model_controller', [name], sources)
assert_directory_exists 'app/controllers'
assert_directory_exists 'app/helpers'
assert_directory_exists 'app/views'
assert_directory_exists 'test/functional'

assert_generated_file 'app/controllers/my_models_controller.rb'
assert_generated_class 'app/controllers/my_models_controller'
assert_generated_file 'app/helpers/my_models_helper.rb'
assert_generated_file 'test/functional/my_models_controller_test.rb'
end

def test_generator_with_views
name = "MyModel"
run_generator('hobo_model_controller', [name, 'index', 'show'], sources)
assert_directory_exists 'app/controllers'
assert_directory_exists 'app/helpers'
assert_directory_exists 'app/views'
assert_directory_exists 'test/functional'

assert_generated_file 'app/controllers/my_models_controller.rb'
assert_generated_class 'app/controllers/my_models_controller'
assert_generated_file 'app/helpers/my_models_helper.rb'
assert_generated_file 'test/functional/my_models_controller_test.rb'

assert_generated_file 'app/views/my_models/index.html.erb'
assert_generated_file 'app/views/my_models/show.html.erb'
end

private
def sources
[RubiGen::PathSource.new(:test, File.join(File.dirname(__FILE__),"..", generator_path))
]
end

def generator_path
"rails_generators"
end
end

0 comments on commit 3d8f747

Please sign in to comment.