Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
89f77640
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,体验更适合开发者的 AI 搜索 >>
提交
89f77640
编写于
12月 15, 2015
作者:
E
eileencodes
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'remove-test-case'
上级
f8edd204
becf1bcb
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
64 addition
and
52 deletion
+64
-52
railties/lib/rails/generators/named_base.rb
railties/lib/rails/generators/named_base.rb
+12
-0
railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb
...erators/test_unit/controller/templates/functional_test.rb
+3
-5
railties/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb
...ators/test_unit/scaffold/templates/api_functional_test.rb
+10
-9
railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb
...enerators/test_unit/scaffold/templates/functional_test.rb
+12
-11
railties/test/application/rake_test.rb
railties/test/application/rake_test.rb
+3
-3
railties/test/generators/namespaced_generators_test.rb
railties/test/generators/namespaced_generators_test.rb
+4
-4
railties/test/generators/resource_generator_test.rb
railties/test/generators/resource_generator_test.rb
+1
-1
railties/test/generators/scaffold_controller_generator_test.rb
...ies/test/generators/scaffold_controller_generator_test.rb
+9
-9
railties/test/generators/scaffold_generator_test.rb
railties/test/generators/scaffold_generator_test.rb
+10
-10
未找到文件。
railties/lib/rails/generators/named_base.rb
浏览文件 @
89f77640
...
...
@@ -129,6 +129,18 @@ def index_helper
uncountable?
?
"
#{
plural_table_name
}
_index"
:
plural_table_name
end
def
show_helper
"
#{
singular_table_name
}
_url(@
#{
singular_table_name
}
)"
end
def
edit_helper
"edit_
#{
show_helper
}
"
end
def
new_helper
"new_
#{
singular_table_name
}
_url"
end
def
singular_table_name
@singular_table_name
||=
(
pluralize_table_names?
?
table_name
.
singularize
:
table_name
)
end
...
...
railties/lib/rails/generators/test_unit/controller/templates/functional_test.rb
浏览文件 @
89f77640
require
'test_helper'
<
% module_namespacing
do
-
%>
class <%= class_name %>
ControllerTest
<
Action
Controller
::
TestCase
class <%= class_name %>
ControllerTest
<
Action
Dispatch
::
IntegrationTest
<
% if
mountable_engine?
-
%>
setup do
@routes = Engine.routes
end
include Engine.routes.url_helpers
<% end -%>
<
% if
actions
.
empty?
-
%>
...
...
@@ -15,7 +13,7 @@ class <%= class_name %>ControllerTest < ActionController::TestCase
<% else -%>
<
% actions.each
do
|
action
|
-
%>
test "should get <%= action %>
" do
get
:<%= action %>
get
<%= file_name %>_<%= action %>_url
assert_response :success
end
...
...
railties/lib/rails/generators/test_unit/scaffold/templates/api_functional_test.rb
浏览文件 @
89f77640
require
'test_helper'
<
% module_namespacing
do
-
%>
class <%= controller_class_name %>
ControllerTest
<
ActionController
::
TestCase
class <%= controller_class_name %>
ControllerTest
<
ActionDispatch
::
IntegrationTest
<
% if
mountable_engine?
-
%>
include Engine.routes.url_helpers
<% end -%>
setup
do
@
<
%= singular_table_name %> =
<
%= fixture_name %>(:one)
<% if mountable_engine? -%>
@routes =
Engine
.
routes
<
% end
-
%>
end
test "should get index" do
get
:index
get
<%=
index_helper
%>_url
assert_response :success
end
test "should create <%= singular_table_name %>
" do
assert_difference('<%= class_name %>.count') do
post
:create
, params: { <%= "
#{singular_table_name}: { #{attributes_hash} }" %> }
post
<%= index_helper %>_url
, params: { <%= "
#{singular_table_name}: { #{attributes_hash} }" %> }
end
assert_response
201
end
test
"should show <%= singular_table_name %>"
do
get
:show
,
params:
{
id:
<
%= "@#{singular_table_name}" %> }
get
<
%= show_helper %>
assert_response :success
end
test "should update <%=
singular_table_name
%>" do
patch
:update, params: { id: <%= "@#{singular_table_name}" %>
,
<
%= "#{singular_table_name}: { #{attributes_hash} }" %> }
patch
<%= show_helper %>
,
params:
{
<
%= "#{singular_table_name}: { #{attributes_hash} }" %> }
assert_response 200
end
test "should destroy <%=
singular_table_name
%>" do
assert_difference('<%= class_name %>
.
count
'
,
-
1
)
do
delete
:destroy
,
params:
{
id:
<
%= "@#{singular_table_name}" %> }
delete
<
%= show_helper %>
end
assert_response 204
...
...
railties/lib/rails/generators/test_unit/scaffold/templates/functional_test.rb
浏览文件 @
89f77640
require
'test_helper'
<
% module_namespacing
do
-
%>
class <%= controller_class_name %>
ControllerTest
<
ActionController
::
TestCase
class <%= controller_class_name %>
ControllerTest
<
ActionDispatch
::
IntegrationTest
<
%- if mountable_engine? -%>
include Engine.routes.url_helpers
<% end -%>
setup
do
@
<
%= singular_table_name %> =
<
%= fixture_name %>(:one)
<% if mountable_engine? -%>
@routes =
Engine
.
routes
<
% end
-
%>
end
test "should get index" do
get
:index
get
<%=
index_helper
%>_url
assert_response :success
end
test "should get new" do
get
:new
get
<%= new_helper %>
assert_response
:success
end
test
"should create <%= singular_table_name %>"
do
assert_difference
(
'<%= class_name %>.count'
)
do
post
:create
, params: { <%= "
#{singular_table_name}: { #{attributes_hash} }" %> }
post
<
%= index_helper %>_url
, params: { <%=
"
#{
singular_table_name
}
: {
#{
attributes_hash
}
}"
%>
}
end
assert_redirected_to
<
%= singular_table_name %>_path(<%=
class_name
%>.last)
end
test "should show <%= singular_table_name %>
" do
get
:show, params: { id: <%= "
@
#{singular_table_name}" %> }
get
<%= show_helper %>
assert_response :success
end
test "
should
get
edit
" do
get
:edit
,
params:
{
id:
<
%= "@#{singular_table_name}" %> }
get
<%= edit_helper %>
assert_response :success
end
test "
should
update
<
%= singular_table_name %>" do
patch
:update, params: { id: <%= "@#{singular_table_name}" %>
,
<
%= "#{singular_table_name}: { #{attributes_hash} }" %> }
patch
<%=
show_helper
%>, params: {
<%= "#{singular_table_name}: { #{attributes_hash} }" %>
}
assert_redirected_to
<
%= singular_table_name %>_path(<%=
"@
#{
singular_table_name
}
"
%>
)
end
test
"should destroy <%= singular_table_name %>"
do
assert_difference
(
'<%= class_name %>.count'
,
-
1
)
do
delete
:destroy
,
params:
{
id:
<
%= "@#{singular_table_name}" %> }
delete
<
%= show_helper %>
end
assert_redirected_to <%=
index_helper
%>_path
...
...
railties/test/application/rake_test.rb
浏览文件 @
89f77640
...
...
@@ -186,7 +186,7 @@ def test_loading_only_yml_fixtures
def
test_scaffold_tests_pass_by_default
output
=
Dir
.
chdir
(
app_path
)
do
`bin/rails generate scaffold user username:string password:string;
bin/rake db:migrate test`
RAILS_ENV=test
bin/rake db:migrate test`
end
assert_match
(
/7 runs, 12 assertions, 0 failures, 0 errors/
,
output
)
...
...
@@ -205,7 +205,7 @@ class ApplicationController < ActionController::API
output
=
Dir
.
chdir
(
app_path
)
do
`bin/rails generate scaffold user username:string password:string;
bin/rake db:migrate test`
RAILS_ENV=test
bin/rake db:migrate test`
end
assert_match
(
/5 runs, 7 assertions, 0 failures, 0 errors/
,
output
)
...
...
@@ -218,7 +218,7 @@ def test_scaffold_with_references_columns_tests_pass_when_belongs_to_is_optional
output
=
Dir
.
chdir
(
app_path
)
do
`bin/rails generate scaffold LineItems product:references cart:belongs_to;
bin/rake db:migrate test`
RAILS_ENV=test
bin/rake db:migrate test`
end
assert_match
(
/7 runs, 12 assertions, 0 failures, 0 errors/
,
output
)
...
...
railties/test/generators/namespaced_generators_test.rb
浏览文件 @
89f77640
...
...
@@ -218,7 +218,7 @@ def test_scaffold_on_invoke
/class ProductLinesController < ApplicationController/
assert_file
"test/controllers/test_app/product_lines_controller_test.rb"
,
/module TestApp\n class ProductLinesControllerTest < Action
Controller::TestCase
/
/module TestApp\n class ProductLinesControllerTest < Action
Dispatch::IntegrationTest
/
# Views
%w(index edit new show _form)
.
each
do
|
view
|
...
...
@@ -285,7 +285,7 @@ def test_scaffold_with_namespace_on_invoke
end
assert_file
"test/controllers/test_app/admin/roles_controller_test.rb"
,
/module TestApp\n class Admin::RolesControllerTest < Action
Controller::TestCase
/
/module TestApp\n class Admin::RolesControllerTest < Action
Dispatch::IntegrationTest
/
# Views
%w(index edit new show _form)
.
each
do
|
view
|
...
...
@@ -352,7 +352,7 @@ def test_scaffold_with_nested_namespace_on_invoke
end
assert_file
"test/controllers/test_app/admin/user/special/roles_controller_test.rb"
,
/module TestApp\n class Admin::User::Special::RolesControllerTest < Action
Controller::TestCase
/
/module TestApp\n class Admin::User::Special::RolesControllerTest < Action
Dispatch::IntegrationTest
/
# Views
%w(index edit new show _form)
.
each
do
|
view
|
...
...
@@ -418,6 +418,6 @@ def test_api_scaffold_with_namespace_on_invoke
assert_match
(
%r(require_dependency "test_app/application_controller")
,
content
)
end
assert_file
"test/controllers/test_app/admin/roles_controller_test.rb"
,
/module TestApp\n class Admin::RolesControllerTest < Action
Controller::TestCase
/
/module TestApp\n class Admin::RolesControllerTest < Action
Dispatch::IntegrationTest
/
end
end
railties/test/generators/resource_generator_test.rb
浏览文件 @
89f77640
...
...
@@ -33,7 +33,7 @@ def test_inherited_invocations_with_attributes
def
test_resource_controller_with_pluralized_class_name
run_generator
assert_file
"app/controllers/accounts_controller.rb"
,
/class AccountsController < ApplicationController/
assert_file
"test/controllers/accounts_controller_test.rb"
,
/class AccountsControllerTest < Action
Controller::TestCase
/
assert_file
"test/controllers/accounts_controller_test.rb"
,
/class AccountsControllerTest < Action
Dispatch::IntegrationTest
/
assert_file
"app/helpers/accounts_helper.rb"
,
/module AccountsHelper/
end
...
...
railties/test/generators/scaffold_controller_generator_test.rb
浏览文件 @
89f77640
...
...
@@ -104,10 +104,10 @@ def test_functional_tests
run_generator
[
"User"
,
"name:string"
,
"age:integer"
,
"organization:references{polymorphic}"
]
assert_file
"test/controllers/users_controller_test.rb"
do
|
content
|
assert_match
(
/class UsersControllerTest < Action
Controller::TestCase
/
,
content
)
assert_match
(
/class UsersControllerTest < Action
Dispatch::IntegrationTest
/
,
content
)
assert_match
(
/test "should get index"/
,
content
)
assert_match
(
/post
:create
, params: \{ user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/
,
content
)
assert_match
(
/patch
:update, params: \{ id: @user,
user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/
,
content
)
assert_match
(
/post
users_url
, params: \{ user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/
,
content
)
assert_match
(
/patch
user_url\(@user\), params: \{
user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/
,
content
)
end
end
...
...
@@ -115,10 +115,10 @@ def test_functional_tests_without_attributes
run_generator
[
"User"
]
assert_file
"test/controllers/users_controller_test.rb"
do
|
content
|
assert_match
(
/class UsersControllerTest < Action
Controller::TestCase
/
,
content
)
assert_match
(
/class UsersControllerTest < Action
Dispatch::IntegrationTest
/
,
content
)
assert_match
(
/test "should get index"/
,
content
)
assert_match
(
/post
:create
, params: \{ user: \{ \} \}/
,
content
)
assert_match
(
/patch
:update, params: \{ id: @user,
user: \{ \} \}/
,
content
)
assert_match
(
/post
users_url
, params: \{ user: \{ \} \}/
,
content
)
assert_match
(
/patch
user_url\(@user\), params: \{
user: \{ \} \}/
,
content
)
end
end
...
...
@@ -236,10 +236,10 @@ def test_api_controller_tests
run_generator
[
"User"
,
"name:string"
,
"age:integer"
,
"organization:references{polymorphic}"
,
"--api"
]
assert_file
"test/controllers/users_controller_test.rb"
do
|
content
|
assert_match
(
/class UsersControllerTest < Action
Controller::TestCase
/
,
content
)
assert_match
(
/class UsersControllerTest < Action
Dispatch::IntegrationTest
/
,
content
)
assert_match
(
/test "should get index"/
,
content
)
assert_match
(
/post
:create
, params: \{ user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/
,
content
)
assert_match
(
/patch
:update, params: \{ id: @user,
user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/
,
content
)
assert_match
(
/post
users_url
, params: \{ user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/
,
content
)
assert_match
(
/patch
user_url\(@user\), params: \{
user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \} \}/
,
content
)
assert_no_match
(
/assert_redirected_to/
,
content
)
end
end
...
...
railties/test/generators/scaffold_generator_test.rb
浏览文件 @
89f77640
...
...
@@ -57,9 +57,9 @@ def test_scaffold_on_invoke
end
assert_file
"test/controllers/product_lines_controller_test.rb"
do
|
test
|
assert_match
(
/class ProductLinesControllerTest < Action
Controller::TestCase
/
,
test
)
assert_match
(
/post
:create
, params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/
,
test
)
assert_match
(
/patch
:update, params: \{ id: @product_line,
product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/
,
test
)
assert_match
(
/class ProductLinesControllerTest < Action
Dispatch::IntegrationTest
/
,
test
)
assert_match
(
/post
product_lines_url
, params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/
,
test
)
assert_match
(
/patch
product_line_url\(@product_line\), params: \{
product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/
,
test
)
end
# Views
...
...
@@ -135,9 +135,9 @@ def test_api_scaffold_on_invoke
end
assert_file
"test/controllers/product_lines_controller_test.rb"
do
|
test
|
assert_match
(
/class ProductLinesControllerTest < Action
Controller::TestCase
/
,
test
)
assert_match
(
/post
:create
, params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/
,
test
)
assert_match
(
/patch
:update, params: \{ id: @product_line,
product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/
,
test
)
assert_match
(
/class ProductLinesControllerTest < Action
Dispatch::IntegrationTest
/
,
test
)
assert_match
(
/post
product_lines_url
, params: \{ product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/
,
test
)
assert_match
(
/patch
product_line_url\(@product_line\), params: \{
product_line: \{ product_id: @product_line\.product_id, title: @product_line\.title, user_id: @product_line\.user_id \} \}/
,
test
)
assert_no_match
(
/assert_redirected_to/
,
test
)
end
...
...
@@ -161,10 +161,10 @@ def test_functional_tests_without_attributes
run_generator
[
"product_line"
]
assert_file
"test/controllers/product_lines_controller_test.rb"
do
|
content
|
assert_match
(
/class ProductLinesControllerTest < Action
Controller::TestCase
/
,
content
)
assert_match
(
/class ProductLinesControllerTest < Action
Dispatch::IntegrationTest
/
,
content
)
assert_match
(
/test "should get index"/
,
content
)
assert_match
(
/post
:create
, params: \{ product_line: \{ \} \}/
,
content
)
assert_match
(
/patch
:update, params: \{ id: @product_line,
product_line: \{ \} \}/
,
content
)
assert_match
(
/post
product_lines_url
, params: \{ product_line: \{ \} \}/
,
content
)
assert_match
(
/patch
product_line_url\(@product_line\), params: \{
product_line: \{ \} \}/
,
content
)
end
end
...
...
@@ -250,7 +250,7 @@ def test_scaffold_with_namespace_on_invoke
end
assert_file
"test/controllers/admin/roles_controller_test.rb"
,
/class Admin::RolesControllerTest < Action
Controller::TestCase
/
/class Admin::RolesControllerTest < Action
Dispatch::IntegrationTest
/
# Views
%w(index edit new show _form)
.
each
do
|
view
|
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录