responders 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/responders/flash_responder.rb +8 -2
- data/lib/responders/version.rb +1 -1
- data/test/flash_responder_test.rb +12 -0
- data/test/test_helper.rb +0 -1
- metadata +3 -3
@@ -64,6 +64,8 @@ module Responders
|
|
64
64
|
#
|
65
65
|
# respond_with(@user, :notice => "Hooray! Welcome!", :alert => "Woot! You failed.")
|
66
66
|
#
|
67
|
+
# * :flash_now - Sets the flash message using flash.now. Accepts true, :on_failure or :on_sucess.
|
68
|
+
#
|
67
69
|
# == Configure status keys
|
68
70
|
#
|
69
71
|
# As said previously, FlashResponder by default use :notice and :alert
|
@@ -87,8 +89,8 @@ module Responders
|
|
87
89
|
end
|
88
90
|
|
89
91
|
def to_html
|
90
|
-
super
|
91
92
|
set_flash_message! if set_flash_message?
|
93
|
+
super
|
92
94
|
end
|
93
95
|
|
94
96
|
protected
|
@@ -112,10 +114,14 @@ module Responders
|
|
112
114
|
def set_flash(key, value)
|
113
115
|
return if value.blank?
|
114
116
|
flash = controller.flash
|
115
|
-
flash = flash.now if
|
117
|
+
flash = flash.now if set_flash_now?
|
116
118
|
flash[key] ||= value
|
117
119
|
end
|
118
120
|
|
121
|
+
def set_flash_now?
|
122
|
+
(@flash_now == true) || (has_errors? ? @flash_now == :on_failure : @flash_now == :on_success)
|
123
|
+
end
|
124
|
+
|
119
125
|
def set_flash_message? #:nodoc:
|
120
126
|
!get? && @flash != false
|
121
127
|
end
|
data/lib/responders/version.rb
CHANGED
@@ -114,6 +114,18 @@ class FlashResponderTest < ActionController::TestCase
|
|
114
114
|
assert_equal "Resource created with success", @now[:success]
|
115
115
|
end
|
116
116
|
|
117
|
+
def test_sets_flash_message_can_be_set_to_now_only_on_success
|
118
|
+
@now = {}
|
119
|
+
@controller.flash.expects(:now).returns(@now)
|
120
|
+
post :create, :flash_now => :on_success
|
121
|
+
assert_equal "Resource created with success", @now[:success]
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_sets_flash_message_can_be_set_to_now_only_on_failure
|
125
|
+
@controller.flash.expects(:now).never
|
126
|
+
post :create, :flash_now => :on_failure
|
127
|
+
end
|
128
|
+
|
117
129
|
def test_sets_message_based_on_notice_key
|
118
130
|
Responders::FlashResponder.flash_keys = [ :notice, :alert ]
|
119
131
|
post :another
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 5
|
9
|
+
version: 0.5.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- "Jos\xC3\xA9 Valim"
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-03-
|
17
|
+
date: 2010-03-26 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|