cacheable_flash 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +8 -0
- data/Gemfile +2 -0
- data/cacheable_flash.gemspec +1 -1
- data/lib/cacheable_flash.rb +8 -0
- data/lib/cacheable_flash/config.rb +25 -22
- data/lib/cacheable_flash/cookie_flash.rb +2 -2
- data/lib/cacheable_flash/rspec_matchers.rb +20 -17
- data/lib/cacheable_flash/version.rb +1 -1
- data/spec/controllers/comparison_cotroller_spec.rb +270 -0
- data/spec/controllers/dummy_controller_spec.rb +60 -12
- data/spec/dummy/app/controllers/comparison_controller.rb +25 -0
- data/spec/requests/integration_spec.rb +14 -0
- metadata +7 -3
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
0.3.1 - AUG.22.2012
|
2
|
+
* Add specs for non stacking use [Peter Boling]
|
3
|
+
* Use stackable_flash/test_helpers instead of reinventing the wheel [Peter Boling]
|
4
|
+
* Config now works! [Peter Boling]
|
5
|
+
* Update to stackable_flash 0.0.7 (working config) [Peter Boling]
|
6
|
+
* default to non stacking [Peter Boling]
|
7
|
+
|
1
8
|
0.3.0 - AUG.21.2012
|
2
9
|
- Completed integration with stackable_flash (http://github.com/pboling/stackable_flash)
|
3
10
|
- Test::Unit helpers and Rspec Matchers updated to be stackable
|
@@ -8,6 +15,7 @@
|
|
8
15
|
- Allows any data type to be stored in the cookie. Only escapes strings.
|
9
16
|
- Does not convert flash value to string before storing in cookie if value is a number
|
10
17
|
- (v0.2.X converted everything to string)
|
18
|
+
- the CacheableFlash::Config class is experimental, and no code uses the config settings yet.
|
11
19
|
|
12
20
|
0.2.10 - AUG.13.2012
|
13
21
|
- Split test_helpers from rspec_matchers (test_helpers may be useful in TestUnit
|
data/Gemfile
CHANGED
data/cacheable_flash.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.rubygems_version = "1.8.24"
|
24
24
|
s.summary = "Render flash messages from a cookie using JavaScript, instead of in your Rails view template"
|
25
25
|
|
26
|
-
s.add_runtime_dependency(%q<stackable_flash>, [">= 0.0.
|
26
|
+
s.add_runtime_dependency(%q<stackable_flash>, [">= 0.0.7"])
|
27
27
|
s.add_runtime_dependency(%q<json>, [">= 0"])
|
28
28
|
s.add_development_dependency(%q<rails>, ["~> 3.1.3"])
|
29
29
|
s.add_development_dependency(%q<jquery-rails>, [">= 0"])
|
data/lib/cacheable_flash.rb
CHANGED
@@ -10,6 +10,14 @@ module CacheableFlash
|
|
10
10
|
# For older rails use generator
|
11
11
|
end
|
12
12
|
|
13
|
+
# By default stacking is false, but it can be turned on with:
|
14
|
+
# CacheableFlash.configure do |config|
|
15
|
+
# config[:stacking] = true
|
16
|
+
# config[:append_as] = :br
|
17
|
+
# end
|
18
|
+
StackableFlash.stacking = false
|
19
|
+
|
20
|
+
# The configure will override the above default
|
13
21
|
require 'cacheable_flash/config'
|
14
22
|
require 'cacheable_flash/cookie_flash'
|
15
23
|
include CacheableFlash::CookieFlash
|
@@ -1,3 +1,7 @@
|
|
1
|
+
#####################
|
2
|
+
# NOTE: the CacheableFlash::Config class is experimental, and no code uses the config settings yet.
|
3
|
+
# So using config values will do nothing as of now.
|
4
|
+
# These are ust some ideas of what could be...
|
1
5
|
module CacheableFlash
|
2
6
|
class Config
|
3
7
|
|
@@ -6,36 +10,35 @@ module CacheableFlash
|
|
6
10
|
end
|
7
11
|
|
8
12
|
DEFAULTS = {
|
13
|
+
:stacking => false, # or true if you want auto-magically stacking flashes
|
9
14
|
# Specify how multiple flashes at the same key (e.g. :notice, :errors) should be handled
|
10
|
-
:append_as
|
15
|
+
# :append_as is ignored if :stacking is false
|
16
|
+
:append_as => :br # or :array, :p, :ul, :ol, or a proc or lambda of your own design
|
11
17
|
}
|
12
18
|
|
13
|
-
|
19
|
+
@config ||= DEFAULTS
|
14
20
|
def self.configure &block
|
15
|
-
yield
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
config[:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
yield @config
|
22
|
+
if @config[:stacking]
|
23
|
+
StackableFlash.stacking = true
|
24
|
+
StackableFlash::Config.configure do
|
25
|
+
# by default behave like regular non-stacking flash
|
26
|
+
if @config[:append_as].respond_to?(:call)
|
27
|
+
@config[:stack_with_proc] = @config[:append_as]
|
28
|
+
else
|
29
|
+
@config[:stack_with_proc] = case @config[:append_as]
|
30
|
+
when :br then Proc.new {|arr| arr.join('<br/>') }
|
31
|
+
when :array then Proc.new {|arr| arr }
|
32
|
+
when :p then Proc.new {|arr| arr.map! {|x| "<p>#{x}</p>"}.join }
|
33
|
+
when :ul then Proc.new {|arr| '<ul>' + arr.map! {|x| "<li>#{x}</li>"}.join + '</ul>' }
|
34
|
+
when :ol then Proc.new {|arr| '<ol>' + arr.map! {|x| "<li>#{x}</li>"}.join + '</ol>' }
|
35
|
+
end
|
26
36
|
end
|
27
37
|
end
|
38
|
+
else
|
39
|
+
StackableFlash.stacking = false
|
28
40
|
end
|
29
41
|
end
|
30
42
|
|
31
|
-
def self.[](key)
|
32
|
-
return nil unless key.respond_to?(:to_sym)
|
33
|
-
CacheableFlash::Config.config[key.to_sym]
|
34
|
-
end
|
35
|
-
|
36
|
-
def self.method_missing(name, *args)
|
37
|
-
CacheableFlash[name]
|
38
|
-
end
|
39
|
-
|
40
43
|
end
|
41
44
|
end
|
@@ -7,10 +7,10 @@ module CacheableFlash
|
|
7
7
|
if value.kind_of?(String)
|
8
8
|
value = ERB::Util.html_escape(value) unless value.html_safe?
|
9
9
|
end
|
10
|
+
skey = key.to_s
|
10
11
|
# This allows any data type to be stored in the cookie; important for using an array as the value with
|
11
12
|
# stackable_flash
|
12
|
-
skey
|
13
|
-
if cflash[skey].kind_of?(Array) # Stackable!!!
|
13
|
+
if cflash[skey].kind_of?(Array) # Already Stackable!!!
|
14
14
|
if value.kind_of?(Array)
|
15
15
|
cflash[skey] += value # Add the values from the other array, which is already a stackable flash
|
16
16
|
else
|
@@ -1,33 +1,36 @@
|
|
1
|
-
require '
|
1
|
+
require 'stackable_flash/test_helpers' # Used in the definition of these matchers
|
2
|
+
require 'stackable_flash/rspec_matchers' # Not used here, but for convenience
|
3
|
+
require 'cacheable_flash/test_helpers' # Used in the definition of these matchers
|
2
4
|
|
3
5
|
module CacheableFlash
|
4
6
|
module RspecMatchers
|
7
|
+
include StackableFlash::TestHelpers
|
5
8
|
include CacheableFlash::TestHelpers
|
6
9
|
RSpec::Matchers.define :have_flash_cookie do |flash_status, expecting|
|
7
10
|
define_method :has_flash_cookie? do |response|
|
8
|
-
|
9
|
-
if flash.kind_of?(Array)
|
10
|
-
if expecting.kind_of?(Array)
|
11
|
-
flash == expecting
|
12
|
-
else
|
13
|
-
matches = flash.select do |to_check|
|
14
|
-
to_check == expecting
|
15
|
-
end
|
16
|
-
matches.length > 0
|
17
|
-
end
|
18
|
-
else
|
19
|
-
flash == expecting
|
20
|
-
end
|
11
|
+
flash_in_stack(testable_flash(response)[flash_status], expecting)
|
21
12
|
end
|
22
|
-
|
23
13
|
match{|response| has_flash_cookie?(response)}
|
14
|
+
failure_message_for_should do |actual|
|
15
|
+
"expected flash[:#{expected[0]}] to be or include #{expected[1].inspect}, but got #{testable_flash(actual)[expected[0]]}"
|
16
|
+
end
|
17
|
+
failure_message_for_should_not do |actual|
|
18
|
+
"expected flash[:#{expected[0]}] to not be and not include #{expected[1].inspect}, but got #{testable_flash(actual)[expected[0]]}"
|
19
|
+
end
|
20
|
+
end
|
24
21
|
|
22
|
+
RSpec::Matchers.define :have_cacheable_flash do |flash_status, expecting|
|
23
|
+
define_method :has_cacheable_flash? do |response|
|
24
|
+
flash_in_stack(testable_flash(response)[flash_status], expecting)
|
25
|
+
end
|
26
|
+
match{|response| has_cacheable_flash?(response)}
|
25
27
|
failure_message_for_should do |actual|
|
26
|
-
"expected
|
28
|
+
"expected flash[:#{expected[0]}] to be or include #{expected[1].inspect}, but got #{testable_flash(actual)[expected[0]]}"
|
27
29
|
end
|
28
30
|
failure_message_for_should_not do |actual|
|
29
|
-
"expected
|
31
|
+
"expected flash[:#{expected[0]}] to not be and not include #{expected[1].inspect}, but got #{testable_flash(actual)[expected[0]]}"
|
30
32
|
end
|
31
33
|
end
|
34
|
+
|
32
35
|
end
|
33
36
|
end
|
@@ -0,0 +1,270 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Controller specs do not hit the full rails stack, and Middleware is ignored.
|
4
|
+
# For this reason testing in the controller must rely on the around filter,
|
5
|
+
# even if you are actually using the Middleware in your actual app
|
6
|
+
# The DummyController in the dummy app includes CacheableFlash to make the helpers testable as a controller spec.
|
7
|
+
|
8
|
+
describe ComparisonController do
|
9
|
+
|
10
|
+
render_views
|
11
|
+
|
12
|
+
describe "CacheableFlash::TestHelpers" do
|
13
|
+
describe "#flash_cookie" do
|
14
|
+
describe "not stacking" do
|
15
|
+
# This is default, so, as long as other tests don't bleed, should not need to be set
|
16
|
+
#before(:each) do
|
17
|
+
# CacheableFlash.configure do |config|
|
18
|
+
# config[:stacking] = false
|
19
|
+
# end
|
20
|
+
#end
|
21
|
+
it "should handle comparison with hash through keys" do
|
22
|
+
get :single_key_hash
|
23
|
+
flash_cookie['notice'].should == {'hello' => 'asdf'} # Keys of hashes are always strings on the other side of JSON
|
24
|
+
end
|
25
|
+
it "should handle comparison with number" do
|
26
|
+
get :single_key_number
|
27
|
+
flash_cookie['notice'].should == 1
|
28
|
+
end
|
29
|
+
it "should handle comparison with string" do
|
30
|
+
get :single_key_string
|
31
|
+
flash_cookie['notice'].should == 'message'
|
32
|
+
end
|
33
|
+
it "should handle comparison with array" do
|
34
|
+
get :single_key_array
|
35
|
+
flash_cookie['notice'].should == ['message'] # Because actually set to an array, not because stacking
|
36
|
+
end
|
37
|
+
end
|
38
|
+
describe "stacking" do
|
39
|
+
before(:each) do
|
40
|
+
CacheableFlash::Config.configure do |config|
|
41
|
+
config[:stacking] = true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
after(:each) do
|
45
|
+
StackableFlash.stacking = false
|
46
|
+
end
|
47
|
+
it "should handle comparison with hash through keys" do
|
48
|
+
get :single_key_hash
|
49
|
+
flash_cookie['notice'].should == [{'hello' => 'asdf'}] # Keys of hashes are always strings on the other side of JSON
|
50
|
+
end
|
51
|
+
it "should handle comparison with number" do
|
52
|
+
get :single_key_number
|
53
|
+
flash_cookie['notice'].should == [1]
|
54
|
+
end
|
55
|
+
it "should handle comparison with string" do
|
56
|
+
get :single_key_string
|
57
|
+
flash_cookie['notice'].should == ['message'] # flash was set to a string, but comparison is with an array!
|
58
|
+
end
|
59
|
+
it "should handle comparison with array" do
|
60
|
+
get :single_key_array
|
61
|
+
flash_cookie['notice'].should == ['message']
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "CacheableFlash::RspecMatchers" do
|
68
|
+
describe "have_cacheable_flash" do
|
69
|
+
describe "not stacking" do
|
70
|
+
# This is default, so, as long as other tests don't bleed, should not need to be set
|
71
|
+
#before(:each) do
|
72
|
+
# CacheableFlash.configure do |config|
|
73
|
+
# config[:stacking] = false
|
74
|
+
# end
|
75
|
+
#end
|
76
|
+
describe "test against string" do
|
77
|
+
before(:each) do
|
78
|
+
get :single_key_string
|
79
|
+
end
|
80
|
+
context "#should" do
|
81
|
+
it "raises error when not a match" do
|
82
|
+
lambda {response.should have_cacheable_flash('notice','not message')}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
83
|
+
end
|
84
|
+
it "should not raise error when a match" do
|
85
|
+
lambda {response.should have_cacheable_flash('notice','message')}.should_not raise_exception
|
86
|
+
end
|
87
|
+
end
|
88
|
+
context "#should_not" do
|
89
|
+
it "raises error when a match" do
|
90
|
+
lambda {response.should_not have_cacheable_flash('notice','message')}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
91
|
+
end
|
92
|
+
it "should not raise error when not a match" do
|
93
|
+
lambda {response.should_not have_cacheable_flash('notice','not message')}.should_not raise_exception
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
describe "test against array" do
|
99
|
+
before(:each) do
|
100
|
+
get :single_key_array
|
101
|
+
end
|
102
|
+
context "#should" do
|
103
|
+
it "raises error when not a match" do
|
104
|
+
lambda {response.should have_cacheable_flash('notice','not message')}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
105
|
+
end
|
106
|
+
it "should not raise error when a match" do
|
107
|
+
lambda {response.should have_cacheable_flash('notice','message')}.should_not raise_exception
|
108
|
+
end
|
109
|
+
end
|
110
|
+
context "#should_not" do
|
111
|
+
it "raises error when a match" do
|
112
|
+
lambda {response.should_not have_cacheable_flash('notice','message')}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
113
|
+
end
|
114
|
+
it "should not raise error when not a match" do
|
115
|
+
lambda {response.should_not have_cacheable_flash('notice','not message')}.should_not raise_exception
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
describe "test against hash" do
|
120
|
+
before(:each) do
|
121
|
+
get :single_key_hash
|
122
|
+
end
|
123
|
+
context "#should" do
|
124
|
+
it "raises error when not a match" do
|
125
|
+
lambda {response.should have_cacheable_flash('notice','not message')}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
126
|
+
end
|
127
|
+
it "should not raise error when a match" do
|
128
|
+
lambda {response.should have_cacheable_flash('notice',{'hello' => 'asdf'})}.should_not raise_exception
|
129
|
+
end
|
130
|
+
end
|
131
|
+
context "#should_not" do
|
132
|
+
it "raises error when a match" do
|
133
|
+
lambda {response.should_not have_cacheable_flash('notice',{'hello' => 'asdf'})}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
134
|
+
end
|
135
|
+
it "should not raise error when not a match" do
|
136
|
+
lambda {response.should_not have_cacheable_flash('notice','not message')}.should_not raise_exception
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
describe "test against number" do
|
142
|
+
before(:each) do
|
143
|
+
get :single_key_number
|
144
|
+
end
|
145
|
+
context "#should" do
|
146
|
+
it "raises error when not a match" do
|
147
|
+
lambda {response.should have_cacheable_flash('notice',2)}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
148
|
+
end
|
149
|
+
it "should not raise error when a match" do
|
150
|
+
lambda {response.should have_cacheable_flash('notice',1)}.should_not raise_exception
|
151
|
+
end
|
152
|
+
end
|
153
|
+
context "#should_not" do
|
154
|
+
it "raises error when a match" do
|
155
|
+
lambda {response.should_not have_cacheable_flash('notice',1)}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
156
|
+
end
|
157
|
+
it "should not raise error when not a match" do
|
158
|
+
lambda {response.should_not have_cacheable_flash('notice',2)}.should_not raise_exception
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
describe "stacking" do
|
164
|
+
before(:each) do
|
165
|
+
CacheableFlash::Config.configure do |config|
|
166
|
+
config[:stacking] = true
|
167
|
+
end
|
168
|
+
end
|
169
|
+
after(:each) do
|
170
|
+
StackableFlash.stacking = false
|
171
|
+
end
|
172
|
+
describe "test against string" do
|
173
|
+
before(:each) do
|
174
|
+
get :single_key_string
|
175
|
+
end
|
176
|
+
context "#should" do
|
177
|
+
it "raises error when not a match" do
|
178
|
+
lambda {response.should have_cacheable_flash('notice','not message')}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
179
|
+
end
|
180
|
+
it "should not raise error when a match" do
|
181
|
+
lambda {response.should have_cacheable_flash('notice','message')}.should_not raise_exception
|
182
|
+
lambda {response.should have_cacheable_flash('notice',['message'])}.should_not raise_exception
|
183
|
+
end
|
184
|
+
end
|
185
|
+
context "#should_not" do
|
186
|
+
it "raises error when a match" do
|
187
|
+
lambda {response.should_not have_cacheable_flash('notice','message')}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
188
|
+
lambda {response.should_not have_cacheable_flash('notice',['message'])}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
189
|
+
end
|
190
|
+
it "should not raise error when not a match" do
|
191
|
+
lambda {response.should_not have_cacheable_flash('notice','not message')}.should_not raise_exception
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
end
|
196
|
+
describe "test against array" do
|
197
|
+
before(:each) do
|
198
|
+
get :single_key_array
|
199
|
+
end
|
200
|
+
context "#should" do
|
201
|
+
it "raises error when not a match" do
|
202
|
+
lambda {response.should have_cacheable_flash('notice',['not message'])}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
203
|
+
end
|
204
|
+
it "should not raise error when a match" do
|
205
|
+
lambda {response.should have_cacheable_flash('notice','message')}.should_not raise_exception
|
206
|
+
lambda {response.should have_cacheable_flash('notice',['message'])}.should_not raise_exception
|
207
|
+
end
|
208
|
+
end
|
209
|
+
context "#should_not" do
|
210
|
+
it "raises error when a match" do
|
211
|
+
lambda {response.should_not have_cacheable_flash('notice','message')}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
212
|
+
lambda {response.should_not have_cacheable_flash('notice',['message'])}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
213
|
+
end
|
214
|
+
it "should not raise error when not a match" do
|
215
|
+
lambda {response.should_not have_cacheable_flash('notice','not message')}.should_not raise_exception
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
describe "test against hash" do
|
220
|
+
before(:each) do
|
221
|
+
get :single_key_hash
|
222
|
+
end
|
223
|
+
context "#should" do
|
224
|
+
it "raises error when not a match" do
|
225
|
+
lambda {response.should have_cacheable_flash('notice','not message')}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
226
|
+
end
|
227
|
+
it "should not raise error when a match" do
|
228
|
+
lambda {response.should have_cacheable_flash('notice',{'hello' => 'asdf'})}.should_not raise_exception
|
229
|
+
lambda {response.should have_cacheable_flash('notice',[{'hello' => 'asdf'}])}.should_not raise_exception
|
230
|
+
end
|
231
|
+
end
|
232
|
+
context "#should_not" do
|
233
|
+
it "raises error when a match" do
|
234
|
+
lambda {response.should_not have_cacheable_flash('notice',{'hello' => 'asdf'})}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
235
|
+
lambda {response.should_not have_cacheable_flash('notice',[{'hello' => 'asdf'}])}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
236
|
+
end
|
237
|
+
it "should not raise error when not a match" do
|
238
|
+
lambda {response.should_not have_cacheable_flash('notice','not message')}.should_not raise_exception
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
242
|
+
end
|
243
|
+
describe "test against number" do
|
244
|
+
before(:each) do
|
245
|
+
get :single_key_number
|
246
|
+
end
|
247
|
+
context "#should" do
|
248
|
+
it "raises error when not a match" do
|
249
|
+
lambda {response.should have_cacheable_flash('notice',2)}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
250
|
+
end
|
251
|
+
it "should not raise error when a match" do
|
252
|
+
lambda {response.should have_cacheable_flash('notice',1)}.should_not raise_exception
|
253
|
+
lambda {response.should have_cacheable_flash('notice',[1])}.should_not raise_exception
|
254
|
+
end
|
255
|
+
end
|
256
|
+
context "#should_not" do
|
257
|
+
it "raises error when a match" do
|
258
|
+
lambda {response.should_not have_cacheable_flash('notice',1)}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
259
|
+
lambda {response.should_not have_cacheable_flash('notice',[1])}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
260
|
+
end
|
261
|
+
it "should not raise error when not a match" do
|
262
|
+
lambda {response.should_not have_cacheable_flash('notice',2)}.should_not raise_exception
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
@@ -1,21 +1,69 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
# Controller specs do not hit the full rails stack, and Middleware is ignored.
|
4
|
+
# For this reason testing in the controller must rely on the around filter,
|
5
|
+
# even if you are actually using the Middleware in your actual app
|
6
|
+
# The DummyController in the dummy app includes CacheableFlash to make the helpers testable as a controller spec.
|
7
|
+
|
3
8
|
describe DummyController do
|
4
9
|
|
5
10
|
render_views
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
describe "CacheableFlash::TestHelpers" do
|
13
|
+
describe "#flash_cookie" do
|
14
|
+
describe "not stacking" do
|
15
|
+
# This is default, so, as long as other tests don't bleed, should not need to be set
|
16
|
+
#before(:each) do
|
17
|
+
# CacheableFlash.configure do |config|
|
18
|
+
# config[:stacking] = false
|
19
|
+
# end
|
20
|
+
#end
|
21
|
+
it "should handle multiple keys" do
|
22
|
+
get :multiple_keys
|
23
|
+
flash_cookie['errors'].should == "This is an Error"
|
24
|
+
flash_cookie['notice'].should == "This is a Notice"
|
25
|
+
end
|
26
|
+
it "should handle overriding values" do
|
27
|
+
get :override
|
28
|
+
flash_cookie['notice'].should_not == "original"
|
29
|
+
flash_cookie['notice'].should == "message"
|
30
|
+
end
|
31
|
+
it "should handle stacking values as concatenations" do
|
32
|
+
get :stack
|
33
|
+
flash_cookie['notice'].should == "originalmessageanother"
|
34
|
+
end
|
35
|
+
it "should raise exception when cold booting the flash" do
|
36
|
+
lambda { get :cold_boot }.should raise_exception
|
37
|
+
end
|
38
|
+
end
|
39
|
+
describe "stacking" do
|
40
|
+
before(:each) do
|
41
|
+
CacheableFlash::Config.configure do |config|
|
42
|
+
config[:stacking] = true
|
43
|
+
end
|
44
|
+
end
|
45
|
+
after(:each) do
|
46
|
+
StackableFlash.stacking = false
|
47
|
+
end
|
48
|
+
it "should handle multiple keys" do
|
49
|
+
get :multiple_keys
|
50
|
+
flash_cookie['errors'].should == ["This is an Error"]
|
51
|
+
flash_cookie['notice'].should == ["This is a Notice"]
|
52
|
+
end
|
53
|
+
it "should handle overriding values" do
|
54
|
+
get :override
|
55
|
+
flash_cookie['notice'].should_not == ["original"]
|
56
|
+
flash_cookie['notice'].should == ["message"]
|
57
|
+
end
|
58
|
+
it "should handle stacking values" do
|
59
|
+
get :stack
|
60
|
+
flash_cookie['notice'].should == ["original","message","another"]
|
61
|
+
end
|
62
|
+
it "should handle cold booting the flash" do
|
63
|
+
get :cold_boot
|
64
|
+
flash_cookie['notice'].should == ["original","message","another"]
|
65
|
+
end
|
66
|
+
end
|
19
67
|
end
|
20
68
|
end
|
21
69
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class ComparisonController < ApplicationController
|
2
|
+
|
3
|
+
include CacheableFlash
|
4
|
+
|
5
|
+
def single_key_string
|
6
|
+
flash[:notice] = 'message'
|
7
|
+
render :text => 'Foo'
|
8
|
+
end
|
9
|
+
|
10
|
+
def single_key_array
|
11
|
+
flash[:notice] = ['message']
|
12
|
+
render :text => 'Foo'
|
13
|
+
end
|
14
|
+
|
15
|
+
def single_key_hash
|
16
|
+
flash[:notice] = {:hello => 'asdf'} # NOTE: Keys of hashes are always strings on the other side of JSON
|
17
|
+
render :text => 'Foo'
|
18
|
+
end
|
19
|
+
|
20
|
+
def single_key_number
|
21
|
+
flash[:notice] = 1
|
22
|
+
render :text => 'Foo'
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DummyController do
|
4
|
+
before(:each) do
|
5
|
+
CacheableFlash::Config.configure do |config|
|
6
|
+
config[:stacking] = true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
after(:each) do
|
10
|
+
StackableFlash.stacking = false
|
11
|
+
end
|
4
12
|
|
5
13
|
describe "cookie flash is sticky" do
|
6
14
|
it "should not clear after request" do # because they are only cleared out by javascripts
|
@@ -55,4 +63,10 @@ describe DummyController do
|
|
55
63
|
get "/dummy/cold_boot"
|
56
64
|
response.should have_flash_cookie('notice',['original','message','another'])
|
57
65
|
end
|
66
|
+
|
67
|
+
it "should allow use of have_cacheable_flash matcher" do
|
68
|
+
get "/dummy/cold_boot"
|
69
|
+
lambda {response.should have_cacheable_flash('notice',['original','message','another'])}.should_not raise_exception
|
70
|
+
end
|
71
|
+
|
58
72
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cacheable_flash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.0.
|
22
|
+
version: 0.0.7
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -27,7 +27,7 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ! '>='
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
version: 0.0.
|
30
|
+
version: 0.0.7
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
32
|
name: json
|
33
33
|
requirement: !ruby/object:Gem::Requirement
|
@@ -195,11 +195,13 @@ files:
|
|
195
195
|
- spec/cacheable_flash/cacheable_flash_spec.rb
|
196
196
|
- spec/cacheable_flash/install_spec.rb
|
197
197
|
- spec/cacheable_flash/test_helpers_spec.rb
|
198
|
+
- spec/controllers/comparison_cotroller_spec.rb
|
198
199
|
- spec/controllers/dummy_controller_spec.rb
|
199
200
|
- spec/dummy/Rakefile
|
200
201
|
- spec/dummy/app/assets/javascripts/application.js
|
201
202
|
- spec/dummy/app/assets/stylesheets/application.css
|
202
203
|
- spec/dummy/app/controllers/application_controller.rb
|
204
|
+
- spec/dummy/app/controllers/comparison_controller.rb
|
203
205
|
- spec/dummy/app/controllers/dummy_controller.rb
|
204
206
|
- spec/dummy/app/helpers/application_helper.rb
|
205
207
|
- spec/dummy/app/mailers/.gitkeep
|
@@ -268,11 +270,13 @@ test_files:
|
|
268
270
|
- spec/cacheable_flash/cacheable_flash_spec.rb
|
269
271
|
- spec/cacheable_flash/install_spec.rb
|
270
272
|
- spec/cacheable_flash/test_helpers_spec.rb
|
273
|
+
- spec/controllers/comparison_cotroller_spec.rb
|
271
274
|
- spec/controllers/dummy_controller_spec.rb
|
272
275
|
- spec/dummy/Rakefile
|
273
276
|
- spec/dummy/app/assets/javascripts/application.js
|
274
277
|
- spec/dummy/app/assets/stylesheets/application.css
|
275
278
|
- spec/dummy/app/controllers/application_controller.rb
|
279
|
+
- spec/dummy/app/controllers/comparison_controller.rb
|
276
280
|
- spec/dummy/app/controllers/dummy_controller.rb
|
277
281
|
- spec/dummy/app/helpers/application_helper.rb
|
278
282
|
- spec/dummy/app/mailers/.gitkeep
|