Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6d30219c
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,发现更多精彩内容 >>
提交
6d30219c
编写于
11月 02, 2013
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of github.com:rails/rails
上级
42324950
a2f27385
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
48 addition
and
94 deletion
+48
-94
actionpack/lib/action_controller/metal/strong_parameters.rb
actionpack/lib/action_controller/metal/strong_parameters.rb
+10
-24
actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
...npack/lib/action_dispatch/middleware/exception_wrapper.rb
+1
-2
actionpack/test/controller/parameters/parameters_require_test.rb
...ack/test/controller/parameters/parameters_require_test.rb
+1
-7
actionpack/test/controller/required_params_test.rb
actionpack/test/controller/required_params_test.rb
+0
-19
actionpack/test/dispatch/debug_exceptions_test.rb
actionpack/test/dispatch/debug_exceptions_test.rb
+0
-6
activerecord/CHANGELOG.md
activerecord/CHANGELOG.md
+24
-24
activerecord/lib/active_record/enum.rb
activerecord/lib/active_record/enum.rb
+5
-5
activerecord/test/cases/enum_test.rb
activerecord/test/cases/enum_test.rb
+4
-4
activerecord/test/models/book.rb
activerecord/test/models/book.rb
+2
-2
guides/source/_welcome.html.erb
guides/source/_welcome.html.erb
+1
-1
未找到文件。
actionpack/lib/action_controller/metal/strong_parameters.rb
浏览文件 @
6d30219c
...
...
@@ -10,26 +10,14 @@ module ActionController
# params = ActionController::Parameters.new(a: {})
# params.fetch(:b)
# # => ActionController::ParameterMissing: param not found: b
# params.require(:a)
# # => ActionController::ParameterMissing: param not found: a
class
ParameterMissing
<
KeyError
attr_reader
:param
# :nodoc:
def
initialize
(
param
)
# :nodoc:
@param
=
param
super
(
"param not found:
#{
param
}
"
)
end
end
# Raised when a required parameter value is empty.
#
# params = ActionController::Parameters.new(a: {})
# params.require(:a)
# # => ActionController::EmptyParameter: value is empty for required key: a
class
EmptyParameter
<
IndexError
attr_reader
:param
def
initialize
(
param
)
@param
=
param
super
(
"value is empty for required key:
#{
param
}
"
)
super
(
"param is missing or the value is empty:
#{
param
}
"
)
end
end
...
...
@@ -169,22 +157,20 @@ def permit!
self
end
# Ensures that a parameter is present. If it's present and not empty,
# returns the parameter at the given +key+, if it's empty raises
# an <tt>ActionController::EmptyParameter</tt> error, otherwise
# raises an <tt>ActionController::ParameterMissing</tt> error.
# Ensures that a parameter is present. If it's present, returns
# the parameter at the given +key+, otherwise raises an
# <tt>ActionController::ParameterMissing</tt> error.
#
# ActionController::Parameters.new(person: { name: 'Francesco' }).require(:person)
# # => {"name"=>"Francesco"}
#
# ActionController::Parameters.new(person:
{}
).require(:person)
# # => ActionController::
EmptyParameter: value is empty for required key
: person
# ActionController::Parameters.new(person:
nil
).require(:person)
# # => ActionController::
ParameterMissing: param not found
: person
#
# ActionController::Parameters.new(
name
: {}).require(:person)
# ActionController::Parameters.new(
person
: {}).require(:person)
# # => ActionController::ParameterMissing: param not found: person
def
require
(
key
)
raise
(
ActionController
::
ParameterMissing
.
new
(
key
))
unless
self
.
key?
(
key
)
self
[
key
].
presence
||
raise
(
ActionController
::
EmptyParameter
.
new
(
key
))
self
[
key
].
presence
||
raise
(
ParameterMissing
.
new
(
key
))
end
# Alias of #require.
...
...
actionpack/lib/action_dispatch/middleware/exception_wrapper.rb
浏览文件 @
6d30219c
...
...
@@ -15,8 +15,7 @@ class ExceptionWrapper
'ActionController::InvalidAuthenticityToken'
=>
:unprocessable_entity
,
'ActionDispatch::ParamsParser::ParseError'
=>
:bad_request
,
'ActionController::BadRequest'
=>
:bad_request
,
'ActionController::ParameterMissing'
=>
:bad_request
,
'ActionController::EmptyParameter'
=>
:bad_request
'ActionController::ParameterMissing'
=>
:bad_request
)
cattr_accessor
:rescue_templates
...
...
actionpack/test/controller/parameters/parameters_require_test.rb
浏览文件 @
6d30219c
...
...
@@ -2,14 +2,8 @@
require
'action_controller/metal/strong_parameters'
class
ParametersRequireTest
<
ActiveSupport
::
TestCase
test
"required parameters must be present"
do
test
"required parameters must be present
not merely not nil
"
do
assert_raises
(
ActionController
::
ParameterMissing
)
do
ActionController
::
Parameters
.
new
(
name:
{}).
require
(
:person
)
end
end
test
"required parameters can't be blank"
do
assert_raises
(
ActionController
::
EmptyParameter
)
do
ActionController
::
Parameters
.
new
(
person:
{}).
require
(
:person
)
end
end
...
...
actionpack/test/controller/required_params_test.rb
浏览文件 @
6d30219c
...
...
@@ -5,11 +5,6 @@ def create
params
.
require
(
:book
).
require
(
:name
)
head
:ok
end
def
update
params
.
require
(
:book
)
head
:ok
end
end
class
ActionControllerRequiredParamsTest
<
ActionController
::
TestCase
...
...
@@ -25,20 +20,6 @@ class ActionControllerRequiredParamsTest < ActionController::TestCase
end
end
test
"empty required parameters will raise an exception"
do
assert_raise
ActionController
::
EmptyParameter
do
put
:update
,
{
book:
{}}
end
assert_raise
ActionController
::
EmptyParameter
do
put
:update
,
{
book:
''
}
end
assert_raise
ActionController
::
EmptyParameter
do
put
:update
,
{
book:
nil
}
end
end
test
"required parameters that are present will not raise"
do
post
:create
,
{
book:
{
name:
"Mjallo!"
}
}
assert_response
:ok
...
...
actionpack/test/dispatch/debug_exceptions_test.rb
浏览文件 @
6d30219c
...
...
@@ -43,8 +43,6 @@ def call(env)
raise
ActionController
::
UrlGenerationError
,
"No route matches"
when
"/parameter_missing"
raise
ActionController
::
ParameterMissing
,
:missing_param_key
when
"/required_key_empty_value"
raise
ActionController
::
EmptyParameter
,
:empty_param_key
else
raise
"puke!"
end
...
...
@@ -128,10 +126,6 @@ def setup
get
"/parameter_missing"
,
{},
{
'action_dispatch.show_exceptions'
=>
true
}
assert_response
400
assert_match
(
/ActionController::ParameterMissing/
,
body
)
get
"/required_key_empty_value"
,
{},
{
'action_dispatch.show_exceptions'
=>
true
}
assert_response
400
assert_match
(
/ActionController::EmptyParameter/
,
body
)
end
test
"rescue with text error for xhr request"
do
...
...
activerecord/CHANGELOG.md
浏览文件 @
6d30219c
*
Added ActiveRecord::Base#enum for declaring enum attributes where the values map to integers in the database, but can be queried by name.
Example:
class Conversation < ActiveRecord::Base
enum status: %i( active archived )
end
Conversation::STATUS # => { active: 0, archived: 1 }
# conversation.update! status: 0
conversation.active!
conversation.active? # => true
conversation.status # => :active
# conversation.update! status: 1
conversation.archived!
conversation.archived? # => true
conversation.status # => :archived
# conversation.update! status: 1
conversation.status = :archived
*DHH*
*
Added ActiveRecord::Base#enum for declaring enum attributes where the values map to integers in the database, but can be queried by name.
Example:
class Conversation < ActiveRecord::Base
enum status: [:active, :archived]
end
Conversation::STATUS # => { active: 0, archived: 1 }
# conversation.update! status: 0
conversation.active!
conversation.active? # => true
conversation.status # => :active
# conversation.update! status: 1
conversation.archived!
conversation.archived? # => true
conversation.status # => :archived
# conversation.update! status: 1
conversation.status = :archived
*DHH*
*
ActiveRecord::Base#attribute_for_inspect now truncates long arrays (more than 10 elements)
...
...
@@ -35,6 +35,7 @@
Fixed bug when providing
`includes`
in through association scope, and fetching targets.
Example:
class Vendor < ActiveRecord::Base
has_many :relationships, -> { includes(:user) }
has_many :users, through: :relationships
...
...
@@ -50,7 +51,6 @@
vendor.users.to_a # => No exception is raised
Fixes #12242, #9517, #10240.
*Paul Nikitochkin*
...
...
activerecord/lib/active_record/enum.rb
浏览文件 @
6d30219c
...
...
@@ -2,7 +2,7 @@ module ActiveRecord
# Declare an enum attribute where the values map to integers in the database, but can be queried by name. Example:
#
# class Conversation < ActiveRecord::Base
# enum status:
%i( active archived )
# enum status:
[:active, :archived]
# end
#
# Conversation::STATUS # => { active: 0, archived: 1 }
...
...
@@ -11,21 +11,21 @@ module ActiveRecord
# conversation.active!
# conversation.active? # => true
# conversation.status # => :active
#
#
# # conversation.update! status: 1
# conversation.archived!
# conversation.archived? # => true
# conversation.status # => :archived
#
#
# # conversation.update! status: 1
# conversation.status = :archived
#
# You can set the default value from the database declaration, like:
#
# create_table :conversation
do
# create_table :conversation
s do |t|
# t.column :status, :integer, default: 0
# end
#
#
# Good practice is to let the first declared status be the default.
module
Enum
def
enum
(
definitions
)
...
...
activerecord/test/cases/enum_test.rb
浏览文件 @
6d30219c
...
...
@@ -5,7 +5,7 @@ class StoreTest < ActiveRecord::TestCase
fixtures
:books
setup
do
@book
=
Book
.
create!
name:
'REMOTE'
@book
=
books
(
:awdr
)
end
test
"query state by predicate"
do
...
...
@@ -13,7 +13,7 @@ class StoreTest < ActiveRecord::TestCase
assert_not
@book
.
written?
assert_not
@book
.
published?
end
test
"query state with symbol"
do
assert_equal
:proposed
,
@book
.
status
end
...
...
@@ -22,12 +22,12 @@ class StoreTest < ActiveRecord::TestCase
@book
.
written!
assert
@book
.
written?
end
test
"update by setter"
do
@book
.
update!
status: :written
assert
@book
.
written?
end
test
"constant"
do
assert_equal
0
,
Book
::
STATUS
[
:proposed
]
assert_equal
1
,
Book
::
STATUS
[
:written
]
...
...
activerecord/test/models/book.rb
浏览文件 @
6d30219c
...
...
@@ -6,6 +6,6 @@ class Book < ActiveRecord::Base
has_many
:subscriptions
has_many
:subscribers
,
through: :subscriptions
enum
status:
%i( proposed written published )
enum
status:
[
:proposed
,
:written
,
:published
]
end
guides/source/_welcome.html.erb
浏览文件 @
6d30219c
...
...
@@ -15,7 +15,7 @@
</p>
<%
end
%>
<p>
The guides for Rails 3.2.x are available at
<a
href=
"http://guides.rubyonrails.org/v3.2.1
4/"
>
http://guides.rubyonrails.org/v3.2.14
/
</a>
.
The guides for Rails 3.2.x are available at
<a
href=
"http://guides.rubyonrails.org/v3.2.1
5/"
>
http://guides.rubyonrails.org/v3.2.15
/
</a>
.
</p>
<p>
The guides for Rails 2.3.x are available at
<a
href=
"http://guides.rubyonrails.org/v2.3.11/"
>
http://guides.rubyonrails.org/v2.3.11/
</a>
.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录