Added test unit files for scaffold_controller.

This commit is contained in:
José Valim
2009-07-01 19:02:51 +02:00
parent 80cd16372c
commit 86ff074101
8 changed files with 71 additions and 9 deletions

View File

@@ -6,7 +6,7 @@ module Erb
argument :actions, :type => :array, :default => [], :banner => "action action"
def create_view_files
base_path = File.join('app', 'views', class_path, file_name)
base_path = File.join("app/views", class_path, file_name)
empty_directory base_path
actions.each do |action|

View File

@@ -6,13 +6,13 @@ module Erb
argument :actions, :type => :array, :default => [], :banner => "method method"
def create_view_folder
empty_directory File.join("app", "views", file_path)
empty_directory File.join("app/views", file_path)
end
def create_view_files
actions.each do |action|
@action, @path = action, File.join(file_path, action)
template "view.erb", File.join("app", "views", "#{@path}.erb")
template "view.erb", File.join("app/views", "#{@path}.erb")
end
end
end

View File

@@ -28,13 +28,14 @@ module Erb
# TODO invoke_if?
def copy_layout_file
template "layout.html.erb", File.join("app", "views", "layouts", controller_class_path, "#{controller_file_name}.html.erb")
template "layout.html.erb",
File.join("app/views/layouts", controller_class_path, "#{controller_file_name}.html.erb")
end
protected
def copy_view(view)
template "#{view}.html.erb", File.join("app", "views", controller_file_path, "#{view}.html.erb")
template "#{view}.html.erb", File.join("app/views", controller_file_path, "#{view}.html.erb")
end
end

View File

@@ -6,7 +6,8 @@ module TestUnit
check_class_collision :suffix => "ControllerTest"
def create_test_files
template 'functional_test.rb', File.join('test/functional', class_path, "#{file_name}_controller_test.rb")
template 'functional_test.rb',
File.join('test/functional', class_path, "#{file_name}_controller_test.rb")
end
end
end

View File

@@ -7,13 +7,13 @@ module TestUnit
check_class_collision :suffix => "Test"
def create_test_files
template "unit_test.rb", File.join('test', 'unit', class_path, "#{file_name}_test.rb")
template "unit_test.rb", File.join('test/unit', class_path, "#{file_name}_test.rb")
end
def create_fixtures_files
actions.each do |action|
@action, @path = action, File.join(file_path, action)
template "fixture", File.join("test", "fixtures", @path)
template "fixture", File.join("test/fixtures", @path)
end
end
end

View File

@@ -6,7 +6,7 @@ module TestUnit
check_class_collision :suffix => "ObserverTest"
def create_test_files
template 'unit_test.rb', File.join('test', 'unit', class_path, "#{file_name}_observer_test.rb")
template 'unit_test.rb', File.join('test/unit', class_path, "#{file_name}_observer_test.rb")
end
end
end

View File

@@ -0,0 +1,15 @@
require 'generators/test_unit'
module TestUnit
module Generators
class ScaffoldGenerator < Base
include Rails::Generators::ControllerNamedBase
check_class_collision :suffix => "ControllerTest"
def create_test_files
template 'functional_test.rb',
File.join('test/functional', controller_class_path, "#{controller_file_name}_controller_test.rb")
end
end
end
end

View File

@@ -0,0 +1,45 @@
require 'test_helper'
class <%= controller_class_name %>ControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:<%= table_name %>)
end
test "should get new" do
get :new
assert_response :success
end
test "should create <%= file_name %>" do
assert_difference('<%= class_name %>.count') do
post :create, :<%= file_name %> => { }
end
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
end
test "should show <%= file_name %>" do
get :show, :id => <%= table_name %>(:one).to_param
assert_response :success
end
test "should get edit" do
get :edit, :id => <%= table_name %>(:one).to_param
assert_response :success
end
test "should update <%= file_name %>" do
put :update, :id => <%= table_name %>(:one).to_param, :<%= file_name %> => { }
assert_redirected_to <%= file_name %>_path(assigns(:<%= file_name %>))
end
test "should destroy <%= file_name %>" do
assert_difference('<%= class_name %>.count', -1) do
delete :destroy, :id => <%= table_name %>(:one).to_param
end
assert_redirected_to <%= table_name %>_path
end
end