Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
Brakeman
提交
e089e034
B
Brakeman
项目概览
李少辉-开发者
/
Brakeman
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
B
Brakeman
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e089e034
编写于
2月 01, 2012
作者:
J
Justin Collins
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for attr_protected
上级
7d6877fe
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
193 addition
and
4 deletion
+193
-4
test/apps/rails3/app/controllers/products_controller.rb
test/apps/rails3/app/controllers/products_controller.rb
+83
-0
test/apps/rails3/app/helpers/products_helper.rb
test/apps/rails3/app/helpers/products_helper.rb
+2
-0
test/apps/rails3/app/models/product.rb
test/apps/rails3/app/models/product.rb
+3
-0
test/apps/rails3/app/views/products/_form.html.erb
test/apps/rails3/app/views/products/_form.html.erb
+21
-0
test/apps/rails3/app/views/products/edit.html.erb
test/apps/rails3/app/views/products/edit.html.erb
+6
-0
test/apps/rails3/app/views/products/index.html.erb
test/apps/rails3/app/views/products/index.html.erb
+23
-0
test/apps/rails3/app/views/products/new.html.erb
test/apps/rails3/app/views/products/new.html.erb
+5
-0
test/apps/rails3/app/views/products/show.html.erb
test/apps/rails3/app/views/products/show.html.erb
+10
-0
test/apps/rails3/config/routes.rb
test/apps/rails3/config/routes.rb
+2
-0
test/tests/test_rails3.rb
test/tests/test_rails3.rb
+38
-4
未找到文件。
test/apps/rails3/app/controllers/products_controller.rb
0 → 100644
浏览文件 @
e089e034
class
ProductsController
<
ApplicationController
# GET /products
# GET /products.xml
def
index
@products
=
Product
.
all
respond_to
do
|
format
|
format
.
html
# index.html.erb
format
.
xml
{
render
:xml
=>
@products
}
end
end
# GET /products/1
# GET /products/1.xml
def
show
@product
=
Product
.
find
(
params
[
:id
])
respond_to
do
|
format
|
format
.
html
# show.html.erb
format
.
xml
{
render
:xml
=>
@product
}
end
end
# GET /products/new
# GET /products/new.xml
def
new
@product
=
Product
.
new
respond_to
do
|
format
|
format
.
html
# new.html.erb
format
.
xml
{
render
:xml
=>
@product
}
end
end
# GET /products/1/edit
def
edit
@product
=
Product
.
find
(
params
[
:id
])
end
# POST /products
# POST /products.xml
def
create
@product
=
Product
.
new
(
params
[
:product
])
respond_to
do
|
format
|
if
@product
.
save
format
.
html
{
redirect_to
(
@product
,
:notice
=>
'Product was successfully created.'
)
}
format
.
xml
{
render
:xml
=>
@product
,
:status
=>
:created
,
:location
=>
@product
}
else
format
.
html
{
render
:action
=>
"new"
}
format
.
xml
{
render
:xml
=>
@product
.
errors
,
:status
=>
:unprocessable_entity
}
end
end
end
# PUT /products/1
# PUT /products/1.xml
def
update
@product
=
Product
.
find
(
params
[
:id
])
respond_to
do
|
format
|
if
@product
.
update_attributes
(
params
[
:product
])
format
.
html
{
redirect_to
(
@product
,
:notice
=>
'Product was successfully updated.'
)
}
format
.
xml
{
head
:ok
}
else
format
.
html
{
render
:action
=>
"edit"
}
format
.
xml
{
render
:xml
=>
@product
.
errors
,
:status
=>
:unprocessable_entity
}
end
end
end
# DELETE /products/1
# DELETE /products/1.xml
def
destroy
@product
=
Product
.
find
(
params
[
:id
])
@product
.
destroy
respond_to
do
|
format
|
format
.
html
{
redirect_to
(
products_url
)
}
format
.
xml
{
head
:ok
}
end
end
end
test/apps/rails3/app/helpers/products_helper.rb
0 → 100644
浏览文件 @
e089e034
module
ProductsHelper
end
test/apps/rails3/app/models/product.rb
0 → 100644
浏览文件 @
e089e034
class
Product
<
ActiveRecord
::
Base
attr_protected
:price
end
test/apps/rails3/app/views/products/_form.html.erb
0 → 100644
浏览文件 @
e089e034
<%=
form_for
(
@product
)
do
|
f
|
%>
<%
if
@product
.
errors
.
any?
%>
<div
id=
"error_explanation"
>
<h2>
<%=
pluralize
(
@product
.
errors
.
count
,
"error"
)
%>
prohibited this product from being saved:
</h2>
<ul>
<%
@product
.
errors
.
full_messages
.
each
do
|
msg
|
%>
<li>
<%=
msg
%>
</li>
<%
end
%>
</ul>
</div>
<%
end
%>
<div
class=
"field"
>
<%=
f
.
label
:price
%>
<br
/>
<%=
f
.
text_field
:price
%>
</div>
<div
class=
"actions"
>
<%=
f
.
submit
%>
</div>
<%
end
%>
test/apps/rails3/app/views/products/edit.html.erb
0 → 100644
浏览文件 @
e089e034
<h1>
Editing product
</h1>
<%=
render
'form'
%>
<%=
link_to
'Show'
,
@product
%>
|
<%=
link_to
'Back'
,
products_path
%>
test/apps/rails3/app/views/products/index.html.erb
0 → 100644
浏览文件 @
e089e034
<h1>
Listing products
</h1>
<table>
<tr>
<th>
Price
</th>
<th></th>
<th></th>
<th></th>
</tr>
<%
@products
.
each
do
|
product
|
%>
<tr>
<td>
<%=
product
.
price
%>
</td>
<td>
<%=
link_to
'Show'
,
product
%>
</td>
<td>
<%=
link_to
'Edit'
,
edit_product_path
(
product
)
%>
</td>
<td>
<%=
link_to
'Destroy'
,
product
,
:confirm
=>
'Are you sure?'
,
:method
=>
:delete
%>
</td>
</tr>
<%
end
%>
</table>
<br
/>
<%=
link_to
'New Product'
,
new_product_path
%>
test/apps/rails3/app/views/products/new.html.erb
0 → 100644
浏览文件 @
e089e034
<h1>
New product
</h1>
<%=
render
'form'
%>
<%=
link_to
'Back'
,
products_path
%>
test/apps/rails3/app/views/products/show.html.erb
0 → 100644
浏览文件 @
e089e034
<p
id=
"notice"
>
<%=
notice
%>
</p>
<p>
<b>
Price:
</b>
<%=
@product
.
price
%>
</p>
<%=
link_to
'Edit'
,
edit_product_path
(
@product
)
%>
|
<%=
link_to
'Back'
,
products_path
%>
test/apps/rails3/config/routes.rb
浏览文件 @
e089e034
Rails3
::
Application
.
routes
.
draw
do
resources
:products
get
"other/test_locals"
get
"other/test_object"
...
...
test/tests/test_rails3.rb
浏览文件 @
e089e034
...
...
@@ -13,9 +13,9 @@ class Rails3Tests < Test::Unit::TestCase
def
expected
@expected
||=
{
:controller
=>
1
,
:model
=>
4
,
:model
=>
5
,
:template
=>
18
,
:warning
=>
18
:warning
=>
21
}
end
...
...
@@ -77,6 +77,24 @@ class Rails3Tests < Test::Unit::TestCase
:file
=>
/home_controller\.rb/
end
def
test_protected_mass_assignment
assert_warning
:type
=>
:warning
,
:warning_type
=>
"Mass Assignment"
,
:line
=>
43
,
:message
=>
/^Unprotected mass assignment near line 43: Product.new/
,
:confidence
=>
2
,
:file
=>
/products_controller\.rb/
end
def
test_protected_mass_assignment_update
assert_warning
:type
=>
:warning
,
:warning_type
=>
"Mass Assignment"
,
:line
=>
62
,
:message
=>
/^Unprotected mass assignment near line 62: Product.find/
,
:confidence
=>
2
,
:file
=>
/products_controller\.rb/
end
def
test_redirect
assert_warning
:type
=>
:warning
,
:warning_type
=>
"Redirect"
,
...
...
@@ -86,6 +104,15 @@ class Rails3Tests < Test::Unit::TestCase
:file
=>
/home_controller\.rb/
end
def
test_redirect_to_model
assert_warning
:type
=>
:warning
,
:warning_type
=>
"Redirect"
,
:line
=>
63
,
:message
=>
/^Possible unprotected redirect near line 63: redirect_to/
,
:confidence
=>
2
,
:file
=>
/products_controller\.rb/
end
def
test_render_path
assert_warning
:type
=>
:warning
,
:warning_type
=>
"Dynamic Render Path"
,
...
...
@@ -147,6 +174,14 @@ class Rails3Tests < Test::Unit::TestCase
:file
=>
/account, user\.rb/
end
def
test_attr_protected
assert_warning
:type
=>
:model
,
:warning_type
=>
"Attribute Restriction"
,
:message
=>
/^attr_accessible is recommended over attr_protected/
,
:confidence
=>
2
,
:file
=>
/product\.rb/
end
def
test_format_validation
assert_warning
:type
=>
:model
,
:warning_type
=>
"Format Validation"
,
...
...
@@ -391,7 +426,7 @@ class Rails3Tests < Test::Unit::TestCase
def
test_default_routes
assert_warning
:warning_type
=>
"Default Routes"
,
:line
=>
9
3
,
:line
=>
9
5
,
:message
=>
/All public methods in controllers are available as actions/
,
:file
=>
/routes\.rb/
end
...
...
@@ -420,4 +455,3 @@ class Rails3Tests < Test::Unit::TestCase
:file
=>
/Gemfile/
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录