Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
238a4253
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,发现更多精彩内容 >>
提交
238a4253
编写于
7月 07, 2012
作者:
K
kennyj
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added support add_flash_types
上级
c55df930
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
65 addition
and
14 deletion
+65
-14
actionpack/CHANGELOG.md
actionpack/CHANGELOG.md
+10
-0
actionpack/lib/action_controller/metal/flash.rb
actionpack/lib/action_controller/metal/flash.rb
+23
-8
actionpack/test/controller/flash_test.rb
actionpack/test/controller/flash_test.rb
+26
-0
actionpack/test/template/test_case_test.rb
actionpack/test/template/test_case_test.rb
+6
-6
未找到文件。
actionpack/CHANGELOG.md
浏览文件 @
238a4253
## Rails 4.0.0 (unreleased) ##
*
Add
`ActionController::Flash.add_flash_types`
method to allow people to register their own flash types. e.g.:
class ApplicationController
add_flash_types :error, :warning
end
If you add the above code, you can use `<%= error %>` in an erb, and `rediect_to /foo, :error => 'message'` in a controller.
*kennyj*
*
Remove Active Model dependency from Action Pack.
*Guillermo Iguaran*
*
Support unicode characters in routes. Route will be automatically escaped, so instead of manually escaping:
...
...
actionpack/lib/action_controller/metal/flash.rb
浏览文件 @
238a4253
...
...
@@ -3,19 +3,34 @@ module Flash
extend
ActiveSupport
::
Concern
included
do
class_attribute
:_flash_types
,
:instance_methods
=>
false
self
.
_flash_types
=
[]
delegate
:flash
,
:to
=>
:request
delegate
:alert
,
:notice
,
:to
=>
"request.flash"
helper_method
:alert
,
:notice
add_flash_types
(
:alert
,
:notice
)
end
protected
def
redirect_to
(
options
=
{},
response_status_and_flash
=
{})
#:doc:
if
alert
=
response_status_and_flash
.
delete
(
:alert
)
flash
[
:alert
]
=
alert
module
ClassMethods
def
add_flash_types
(
*
types
)
types
.
each
do
|
type
|
next
if
_flash_types
.
include?
(
type
)
define_method
(
type
)
do
request
.
flash
[
type
]
end
helper_method
type
_flash_types
<<
type
end
end
end
if
notice
=
response_status_and_flash
.
delete
(
:notice
)
flash
[
:notice
]
=
notice
protected
def
redirect_to
(
options
=
{},
response_status_and_flash
=
{})
#:doc:
self
.
class
.
_flash_types
.
each
do
|
flash_type
|
if
type
=
response_status_and_flash
.
delete
(
flash_type
)
flash
[
flash_type
]
=
type
end
end
if
other_flashes
=
response_status_and_flash
.
delete
(
:flash
)
...
...
actionpack/test/controller/flash_test.rb
浏览文件 @
238a4253
...
...
@@ -90,6 +90,10 @@ def render_with_flash_now_notice
def
redirect_with_other_flashes
redirect_to
'/wonderland'
,
:flash
=>
{
:joyride
=>
"Horses!"
}
end
def
redirect_with_foo_flash
redirect_to
"/wonderland"
,
:foo
=>
'for great justice'
end
end
tests
TestController
...
...
@@ -203,6 +207,12 @@ def test_redirect_to_with_other_flashes
get
:redirect_with_other_flashes
assert_equal
"Horses!"
,
@controller
.
send
(
:flash
)[
:joyride
]
end
def
test_redirect_to_with_adding_flash_types
@controller
.
class
.
add_flash_types
:foo
get
:redirect_with_foo_flash
assert_equal
"for great justice"
,
@controller
.
send
(
:flash
)[
:foo
]
end
end
class
FlashIntegrationTest
<
ActionDispatch
::
IntegrationTest
...
...
@@ -210,6 +220,9 @@ class FlashIntegrationTest < ActionDispatch::IntegrationTest
SessionSecret
=
'b3c631c314c0bbca50c1b2843150fe33'
class
TestController
<
ActionController
::
Base
add_flash_types
:bar
def
set_flash
flash
[
"that"
]
=
"hello"
head
:ok
...
...
@@ -223,6 +236,11 @@ def set_flash_now
def
use_flash
render
:inline
=>
"flash:
#{
flash
[
"that"
]
}
"
end
def
set_bar
flash
[
:bar
]
=
"for great justice"
head
:ok
end
end
def
test_flash
...
...
@@ -262,6 +280,14 @@ def test_setting_flash_now_does_not_raise_in_following_requests
end
end
def
test_added_flash_types_method
with_test_route_set
do
get
'/set_bar'
assert_response
:success
assert_equal
'for great justice'
,
@controller
.
bar
end
end
private
# Overwrite get to send SessionSecret in env hash
...
...
actionpack/test/template/test_case_test.rb
浏览文件 @
238a4253
...
...
@@ -68,14 +68,14 @@ class GeneralViewTest < ActionView::TestCase
assert_nil
self
.
class
.
determine_default_helper_class
(
"String"
)
end
test
"delegates notice to request.flash"
do
view
.
request
.
flash
.
expects
(
:
notice
).
with
(
"this message"
)
view
.
notice
(
"this message"
)
test
"delegates notice to request.flash
[:notice]
"
do
view
.
request
.
flash
.
expects
(
:
[]
).
with
(
:notice
)
view
.
notice
end
test
"delegates alert to request.flash"
do
view
.
request
.
flash
.
expects
(
:
alert
).
with
(
"this message"
)
view
.
alert
(
"this message"
)
test
"delegates alert to request.flash
[:alert]
"
do
view
.
request
.
flash
.
expects
(
:
[]
).
with
(
:alert
)
view
.
alert
end
test
"uses controller lookup context"
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录