mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Added test unit files for scaffold_controller.
This commit is contained in:
@@ -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|
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user