Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c972b25d
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c972b25d
编写于
7月 01, 2009
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Tests for scaffold generator.
上级
a7c15913
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
174 addition
and
6 deletion
+174
-6
railties/lib/generators/erb/scaffold/scaffold_generator.rb
railties/lib/generators/erb/scaffold/scaffold_generator.rb
+4
-0
railties/lib/generators/rails/plugin/plugin_generator.rb
railties/lib/generators/rails/plugin/plugin_generator.rb
+11
-1
railties/lib/generators/rails/stylesheets/stylesheets_generator.rb
...lib/generators/rails/stylesheets/stylesheets_generator.rb
+1
-1
railties/test/generators/plugin_generator_test.rb
railties/test/generators/plugin_generator_test.rb
+7
-2
railties/test/generators/scaffold_generator_test.rb
railties/test/generators/scaffold_generator_test.rb
+143
-0
railties/test/generators/stylesheets_generator_test.rb
railties/test/generators/stylesheets_generator_test.rb
+8
-2
未找到文件。
railties/lib/generators/erb/scaffold/scaffold_generator.rb
浏览文件 @
c972b25d
...
...
@@ -10,6 +10,10 @@ class ScaffoldGenerator < Base
class_option
:singleton
,
:type
=>
:boolean
,
:desc
=>
"Supply to skip index action"
class_option
:layout
,
:type
=>
:boolean
def
create_root_folder
empty_directory
File
.
join
(
"app/views"
,
controller_file_path
)
end
def
copy_index_file
return
if
options
[
:singleton
]
copy_view
:index
...
...
railties/lib/generators/rails/plugin/plugin_generator.rb
浏览文件 @
c972b25d
...
...
@@ -11,7 +11,7 @@ class PluginGenerator < NamedBase
def
create_root
self
.
root
=
File
.
expand_path
(
"vendor/plugins/
#{
file_name
}
"
,
root
)
empty_directory
'.'
empty_directory
'.'
if
behavior
==
:invoke
FileUtils
.
cd
(
root
)
end
...
...
@@ -36,6 +36,16 @@ def create_generator_files
return
unless
options
[
:with_generator
]
directory
'generators'
end
# Work around for generator to work on revoke. If we remove the root
# folder at the beginning, it will raise an error since FileUtils.cd
# will move to a non-existent folder.
#
def
remove_on_revoke
return
unless
behavior
==
:revoke
FileUtils
.
cd
(
"../../.."
)
empty_directory
"vendor/plugins/
#{
file_name
}
"
end
end
end
end
railties/lib/generators/rails/stylesheets/stylesheets_generator.rb
浏览文件 @
c972b25d
...
...
@@ -2,7 +2,7 @@ module Rails
module
Generators
class
StylesheetsGenerator
<
Base
def
copy_stylesheets_file
copy_file
"scaffold.css"
,
"public/stylesheets/scaffold.css"
template
"scaffold.css"
,
"public/stylesheets/scaffold.css"
if
behavior
==
:invoke
end
end
end
...
...
railties/test/generators/plugin_generator_test.rb
浏览文件 @
c972b25d
...
...
@@ -44,10 +44,15 @@ def test_creates_generator_if_required
assert_file
"vendor/plugins/plugin_fu/generators/plugin_fu/plugin_fu_generator.rb"
,
flag
end
def
test_plugin_generator_on_revoke
run_generator
run_generator
[
"plugin_fu"
],
:behavior
=>
:revoke
end
protected
def
run_generator
(
args
=
[
"plugin_fu"
])
silence
(
:stdout
)
{
Rails
::
Generators
::
PluginGenerator
.
start
args
,
:root
=>
destination_root
}
def
run_generator
(
args
=
[
"plugin_fu"
]
,
config
=
{}
)
silence
(
:stdout
)
{
Rails
::
Generators
::
PluginGenerator
.
start
args
,
config
.
merge
(
:root
=>
destination_root
)
}
end
end
railties/test/generators/scaffold_generator_test.rb
0 → 100644
浏览文件 @
c972b25d
require
'abstract_unit'
require
'generators/generators_test_helper'
require
'generators/active_record'
require
'generators/rails/scaffold/scaffold_generator'
require
'generators/rails/stylesheets/stylesheets_generator'
# Model
require
'generators/active_record/model/model_generator'
require
'generators/rails/model/model_generator'
require
'generators/test_unit/model/model_generator'
# Controller
require
'generators/erb/scaffold/scaffold_generator'
require
'generators/rails/scaffold_controller/scaffold_controller_generator'
require
'generators/rails/helper/helper_generator'
require
'generators/test_unit/scaffold/scaffold_generator'
require
'generators/test_unit/helper/helper_generator'
class
ScaffoldGeneratorTest
<
GeneratorsTestCase
def
setup
super
routes
=
Rails
::
Generators
::
ResourceGenerator
.
source_root
routes
=
File
.
join
(
routes
,
".."
,
".."
,
"app"
,
"templates"
,
"config"
,
"routes.rb"
)
destination
=
File
.
join
(
destination_root
,
"config"
)
FileUtils
.
mkdir_p
(
destination
)
FileUtils
.
cp
File
.
expand_path
(
routes
),
destination
end
def
test_scaffold_on_invoke
run_generator
# Model
assert_file
"app/models/product_line.rb"
,
/class ProductLine < ActiveRecord::Base/
assert_file
"test/unit/product_line_test.rb"
,
/class ProductLineTest < ActiveSupport::TestCase/
assert_file
"test/fixtures/product_lines.yml"
assert_migration
"db/migrate/create_product_lines.rb"
# Route
assert_file
"config/routes.rb"
do
|
route
|
assert_match
/map\.resources :product_lines$/
,
route
end
# Controller
assert_file
"app/controllers/product_lines_controller.rb"
do
|
content
|
assert_match
/class ProductLinesController < ApplicationController/
,
content
assert_instance_method
content
,
:index
do
|
m
|
assert_match
/@product_lines = ProductLine\.all/
,
m
end
assert_instance_method
content
,
:show
do
|
m
|
assert_match
/@product_line = ProductLine\.find\(params\[:id\]\)/
,
m
end
assert_instance_method
content
,
:new
do
|
m
|
assert_match
/@product_line = ProductLine\.new/
,
m
end
assert_instance_method
content
,
:edit
do
|
m
|
assert_match
/@product_line = ProductLine\.find\(params\[:id\]\)/
,
m
end
assert_instance_method
content
,
:create
do
|
m
|
assert_match
/@product_line = ProductLine\.new\(params\[:product_line\]\)/
,
m
assert_match
/@product_line\.save/
,
m
assert_match
/@product_line\.errors/
,
m
end
assert_instance_method
content
,
:update
do
|
m
|
assert_match
/@product_line = ProductLine\.find\(params\[:id\]\)/
,
m
assert_match
/@product_line\.update_attributes\(params\[:product_line\]\)/
,
m
assert_match
/@product_line\.errors/
,
m
end
assert_instance_method
content
,
:destroy
do
|
m
|
assert_match
/@product_line = ProductLine\.find\(params\[:id\]\)/
,
m
assert_match
/@product_line\.destroy/
,
m
end
end
assert_file
"test/functional/product_lines_controller_test.rb"
,
/class ProductLinesControllerTest < ActionController::TestCase/
# Views
%w(
index
edit
new
show
)
.
each
{
|
view
|
assert_file
"app/views/product_lines/
#{
view
}
.html.erb"
}
assert_file
"app/views/layouts/product_lines.html.erb"
# Helpers
assert_file
"app/helpers/product_lines_helper.rb"
assert_file
"test/unit/helpers/product_lines_helper_test.rb"
# Stylesheets
assert_file
"public/stylesheets/scaffold.css"
end
def
test_scaffold_on_revoke
run_generator
run_generator
:behavior
=>
:revoke
# Model
assert_no_file
"app/models/product_line.rb"
assert_no_file
"test/unit/product_line_test.rb"
assert_no_file
"test/fixtures/product_lines.yml"
assert_no_migration
"db/migrate/create_product_lines.rb"
# Route
assert_file
"config/routes.rb"
do
|
route
|
assert_no_match
/map\.resources :product_lines$/
,
route
end
# Controller
assert_no_file
"app/controllers/product_lines_controller.rb"
assert_no_file
"test/functional/product_lines_controller_test.rb"
# Views
assert_no_file
"app/views/product_lines"
assert_no_file
"app/views/layouts/product_lines.html.erb"
# Helpers
assert_no_file
"app/helpers/product_lines_helper.rb"
assert_no_file
"test/unit/helpers/product_lines_helper_test.rb"
# Stylesheets (should not be removed)
assert_file
"public/stylesheets/scaffold.css"
end
protected
def
run_generator
(
config
=
{})
silence
(
:stdout
)
do
Rails
::
Generators
::
ScaffoldGenerator
.
start
[
"product_line"
,
"title:string"
,
"price:integer"
],
config
.
merge
(
:root
=>
destination_root
)
end
end
end
railties/test/generators/stylesheets_generator_test.rb
浏览文件 @
c972b25d
...
...
@@ -9,10 +9,16 @@ def test_copy_stylesheets
assert_file
"public/stylesheets/scaffold.css"
end
def
test_stylesheets_are_not_deleted_on_revoke
run_generator
run_generator
:behavior
=>
:revoke
assert_file
"public/stylesheets/scaffold.css"
end
protected
def
run_generator
(
args
=
[]
)
silence
(
:stdout
)
{
Rails
::
Generators
::
StylesheetsGenerator
.
start
args
,
:root
=>
destination_root
}
def
run_generator
(
config
=
{}
)
silence
(
:stdout
)
{
Rails
::
Generators
::
StylesheetsGenerator
.
start
[],
config
.
merge
(
:root
=>
destination_root
)
}
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录