stackable_flash 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/README.md +3 -3
- data/lib/stackable_flash/rspec_matchers.rb +21 -0
- data/lib/stackable_flash/test_helpers.rb +15 -0
- data/lib/stackable_flash/version.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- data/spec/stackable_flash/rspec_matchers_spec.rb +217 -0
- metadata +5 -1
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
Version 0.0.5 - AUG.22.2012
|
2
|
+
- Added Rspec Matchers and Test::Unit helpers.
|
3
|
+
|
4
|
+
Version 0.0.4 - AUG.21.2012
|
5
|
+
- Refactoring
|
6
|
+
- Added ability to cold boot a flash so you can call flash[:notice] << 'Hello' without initializing it first
|
7
|
+
|
8
|
+
Version 0.0.3 - AUG.20.2012
|
9
|
+
- Switch to proper Railtie
|
10
|
+
|
1
11
|
Version 0.0.2 - AUG.18.2012
|
2
12
|
- Added rake dependency
|
3
13
|
- Expanded README
|
data/README.md
CHANGED
@@ -3,7 +3,7 @@ stackable_flash
|
|
3
3
|
|
4
4
|
Allows flashes to stack intelligently, while preserving existing behavior of Rails' FlashHash.
|
5
5
|
|
6
|
-
Stackable Flash overrides the
|
6
|
+
Stackable Flash overrides the `:[]=` method of Rails' FlashHash with the result being that each flash key is an array.
|
7
7
|
It is designed following the "Principle of least surprise", so in most ways the flash works as it always has.
|
8
8
|
Only now you can push things onto the array with `:<<`, and generally interact with the flash as an array.
|
9
9
|
In order to be as compatible as possible with existing implementations of the FlashHash on websites, `:[]=` will still
|
@@ -109,8 +109,8 @@ This gem is used by the cacheable_flash gem to provide stacking flashes. You ca
|
|
109
109
|
5. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
110
110
|
6. Create new Pull Request
|
111
111
|
|
112
|
-
|
112
|
+
## Copyright
|
113
113
|
|
114
114
|
Licensed under the MIT License.
|
115
115
|
|
116
|
-
|
116
|
+
* Copyright (c) 2012 Peter H. Boling (http://peterboling.com). See LICENSE for further details.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'stackable_flash/test_helpers'
|
2
|
+
|
3
|
+
module StackableFlash
|
4
|
+
module RspecMatchers
|
5
|
+
include StackableFlash::TestHelpers
|
6
|
+
RSpec::Matchers.define :have_stackable_flash do |expecting|
|
7
|
+
define_method :has_stackable_flash? do |slash|
|
8
|
+
flash_in_stack(slash, expecting)
|
9
|
+
end
|
10
|
+
|
11
|
+
match{|slash| has_stackable_flash?(slash)}
|
12
|
+
|
13
|
+
failure_message_for_should do |slash|
|
14
|
+
"expected flash to be or include #{expected.inspect}, but got #{slash}"
|
15
|
+
end
|
16
|
+
failure_message_for_should_not do |slash|
|
17
|
+
"expected flash to not be and not include #{expected.inspect}, but got #{slash}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module StackableFlash
|
2
|
+
module TestHelpers
|
3
|
+
|
4
|
+
def flash_in_stack(slash_for_status, expecting)
|
5
|
+
return true if slash_for_status == expecting
|
6
|
+
if slash_for_status.kind_of?(Array)
|
7
|
+
matches = slash_for_status.select do |to_check|
|
8
|
+
to_check == expecting
|
9
|
+
end
|
10
|
+
return matches.length > 0
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,7 @@ require File.expand_path("../dummy/config/environment", __FILE__)
|
|
4
4
|
|
5
5
|
require 'rspec/rails'
|
6
6
|
require 'stackable_flash'
|
7
|
+
require 'stackable_flash/rspec_matchers'
|
7
8
|
|
8
9
|
ENGINE_RAILS_ROOT=File.join(File.dirname(__FILE__), '../')
|
9
10
|
|
@@ -22,4 +23,6 @@ RSpec.configure do |config|
|
|
22
23
|
# --seed 1234
|
23
24
|
config.order = 'random'
|
24
25
|
|
26
|
+
config.include StackableFlash::RspecMatchers
|
27
|
+
|
25
28
|
end
|
@@ -0,0 +1,217 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StackableFlash::StackLayer do
|
4
|
+
before(:each) do
|
5
|
+
@flash = ActionDispatch::Flash::FlashHash.new
|
6
|
+
end
|
7
|
+
describe "tests against strange things" do
|
8
|
+
context "should" do
|
9
|
+
it "should be able to test against odd values like an Object.new" do
|
10
|
+
lambda {@flash[:notice].should have_stackable_flash(Object.new)}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
11
|
+
end
|
12
|
+
it "should be able to test against odd values like {:hello => 'asdf'}" do
|
13
|
+
lambda {@flash[:notice].should have_stackable_flash({:hello => 'asdf'})}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
14
|
+
end
|
15
|
+
end
|
16
|
+
context "should_not" do
|
17
|
+
it "should be able to test against odd values like an Object.new" do
|
18
|
+
lambda {@flash[:notice].should_not have_stackable_flash(Object.new)}.should_not raise_exception
|
19
|
+
end
|
20
|
+
it "should be able to test against odd values like {:hello => 'asdf'}" do
|
21
|
+
lambda {@flash[:notice].should_not have_stackable_flash({:hello => 'asdf'})}.should_not raise_exception
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "have_stackable_flash after using :[]=" do
|
27
|
+
context "a string" do
|
28
|
+
context "when there is not an existing flash message" do
|
29
|
+
context "sets the flash message" do
|
30
|
+
before(:each) do
|
31
|
+
@flash[:notice] = 'message'
|
32
|
+
end
|
33
|
+
it "should match the value itself" do
|
34
|
+
@flash[:notice].should have_stackable_flash('message')
|
35
|
+
end
|
36
|
+
it "should match the entire array" do
|
37
|
+
@flash[:notice].should have_stackable_flash(['message'])
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
context "when there is an existing flash message" do
|
42
|
+
context "overwrite the original string" do
|
43
|
+
before(:each) do
|
44
|
+
@flash[:notice] = 'original'
|
45
|
+
@flash[:notice] = ''
|
46
|
+
end
|
47
|
+
it "should match the value itself" do
|
48
|
+
@flash[:notice].should have_stackable_flash('')
|
49
|
+
end
|
50
|
+
it "should match the entire array" do
|
51
|
+
@flash[:notice].should have_stackable_flash([''])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
context "overwrite the original array" do
|
55
|
+
before(:each) do
|
56
|
+
@flash[:notice] = ['original']
|
57
|
+
@flash[:notice] = ''
|
58
|
+
end
|
59
|
+
it "should match the value itself" do
|
60
|
+
@flash[:notice].should_not have_stackable_flash('original')
|
61
|
+
@flash[:notice].should_not have_stackable_flash(['original'])
|
62
|
+
@flash[:notice].should have_stackable_flash('')
|
63
|
+
end
|
64
|
+
it "should match the entire array" do
|
65
|
+
@flash[:notice].should have_stackable_flash([''])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context "an array" do
|
71
|
+
context "when there is not an existing flash message" do
|
72
|
+
context "sets the flash message" do
|
73
|
+
before(:each) do
|
74
|
+
@flash[:notice] = ['message']
|
75
|
+
end
|
76
|
+
it "should match the value itself" do
|
77
|
+
@flash[:notice].should have_stackable_flash('message')
|
78
|
+
end
|
79
|
+
it "should match the entire array" do
|
80
|
+
@flash[:notice].should have_stackable_flash(['message'])
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
context "when there is an existing flash message" do
|
85
|
+
context "overwrite the original string" do
|
86
|
+
before(:each) do
|
87
|
+
@flash[:notice] = 'original'
|
88
|
+
@flash[:notice] = ['message']
|
89
|
+
end
|
90
|
+
it "should match the value itself" do
|
91
|
+
@flash[:notice].should_not have_stackable_flash('original')
|
92
|
+
@flash[:notice].should have_stackable_flash('message')
|
93
|
+
end
|
94
|
+
it "should match the entire array" do
|
95
|
+
@flash[:notice].should have_stackable_flash(['message'])
|
96
|
+
end
|
97
|
+
end
|
98
|
+
context "overwrite the original array" do
|
99
|
+
before(:each) do
|
100
|
+
@flash[:notice] = ['original']
|
101
|
+
@flash[:notice] = ['message']
|
102
|
+
end
|
103
|
+
it "should match the value itself" do
|
104
|
+
@flash[:notice].should_not have_stackable_flash(['original'])
|
105
|
+
@flash[:notice].should_not have_stackable_flash('original')
|
106
|
+
@flash[:notice].should have_stackable_flash('message')
|
107
|
+
end
|
108
|
+
it "should match the entire array" do
|
109
|
+
@flash[:notice].should have_stackable_flash(['message'])
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
# Actually testing how it interacts with Array's :<< method
|
116
|
+
describe "have_stackable_flash after using :<<" do
|
117
|
+
context "a string" do
|
118
|
+
context "should build a stack" do
|
119
|
+
before(:each) do
|
120
|
+
@flash[:notice] = 'original'
|
121
|
+
@flash[:notice] << 'message'
|
122
|
+
end
|
123
|
+
it "should match the value itself" do
|
124
|
+
@flash[:notice].should have_stackable_flash('original')
|
125
|
+
@flash[:notice].should have_stackable_flash('message')
|
126
|
+
end
|
127
|
+
it "should match the entire array" do
|
128
|
+
@flash[:notice].should have_stackable_flash(['original','message'])
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
context "an array" do
|
133
|
+
context "should build a stack" do
|
134
|
+
before(:each) do
|
135
|
+
@flash[:notice] = ['original']
|
136
|
+
@flash[:notice] << 'message'
|
137
|
+
end
|
138
|
+
it "should match the value itself" do
|
139
|
+
@flash[:notice].should_not have_stackable_flash(['original'])
|
140
|
+
@flash[:notice].should have_stackable_flash('original')
|
141
|
+
@flash[:notice].should have_stackable_flash('message')
|
142
|
+
end
|
143
|
+
it "should match the entire array" do
|
144
|
+
@flash[:notice].should have_stackable_flash(['original','message'])
|
145
|
+
end
|
146
|
+
end
|
147
|
+
context "should allow any data type" do
|
148
|
+
before(:each) do
|
149
|
+
@flash[:notice] = ['original']
|
150
|
+
@flash[:notice] << ['nested']
|
151
|
+
@flash[:notice] << 123
|
152
|
+
end
|
153
|
+
it "should match the value itself" do
|
154
|
+
@flash[:notice].should have_stackable_flash('original')
|
155
|
+
@flash[:notice].should_not have_stackable_flash(['original'])
|
156
|
+
@flash[:notice].should have_stackable_flash(['nested'])
|
157
|
+
@flash[:notice].should_not have_stackable_flash('nested')
|
158
|
+
@flash[:notice].should have_stackable_flash(123)
|
159
|
+
end
|
160
|
+
it "should match the entire array" do
|
161
|
+
@flash[:notice].should have_stackable_flash(['original',['nested'],123])
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "mixed use" do
|
168
|
+
after(:each) do
|
169
|
+
StackableFlash.stacking = true
|
170
|
+
end
|
171
|
+
context "when StackableFlash is turned off and on" do
|
172
|
+
it "should not fail for strings" do
|
173
|
+
StackableFlash.stacking = false
|
174
|
+
@flash[:notice] = 'original'
|
175
|
+
StackableFlash.stacking = true
|
176
|
+
@flash[:notice] << 'message'
|
177
|
+
@flash[:notice].should have_stackable_flash('originalmessage')
|
178
|
+
end
|
179
|
+
it "should not fail for an array" do
|
180
|
+
StackableFlash.stacking = false
|
181
|
+
@flash[:notice] = ['original']
|
182
|
+
StackableFlash.stacking = true
|
183
|
+
@flash[:notice] << 'message'
|
184
|
+
@flash[:notice].should have_stackable_flash('original')
|
185
|
+
@flash[:notice].should have_stackable_flash('message')
|
186
|
+
@flash[:notice].should have_stackable_flash(['original','message'])
|
187
|
+
end
|
188
|
+
end
|
189
|
+
context "when StackableFlash is turned on and off" do
|
190
|
+
it "should not fail for strings" do
|
191
|
+
StackableFlash.stacking = true
|
192
|
+
@flash[:notice] = 'original'
|
193
|
+
StackableFlash.stacking = false
|
194
|
+
@flash[:notice] << 'message'
|
195
|
+
@flash[:notice].should have_stackable_flash('original')
|
196
|
+
@flash[:notice].should have_stackable_flash('message')
|
197
|
+
@flash[:notice].should have_stackable_flash(['original','message'])
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
describe "when stackable_flash is off" do
|
203
|
+
context "StackableFlash.not_stacked" do
|
204
|
+
it "should not fail for strings" do
|
205
|
+
StackableFlash.not_stacked do
|
206
|
+
@flash[:notice] = 'original'
|
207
|
+
@flash[:notice] << 'message'
|
208
|
+
@flash[:notice].should have_stackable_flash('originalmessage')
|
209
|
+
@flash[:notice].should_not have_stackable_flash('original')
|
210
|
+
@flash[:notice].should_not have_stackable_flash('message')
|
211
|
+
@flash[:notice].should_not have_stackable_flash(['original','message'])
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
end
|
217
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stackable_flash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -126,7 +126,9 @@ files:
|
|
126
126
|
- lib/stackable_flash/config.rb
|
127
127
|
- lib/stackable_flash/flash_stack.rb
|
128
128
|
- lib/stackable_flash/railtie.rb
|
129
|
+
- lib/stackable_flash/rspec_matchers.rb
|
129
130
|
- lib/stackable_flash/stack_layer.rb
|
131
|
+
- lib/stackable_flash/test_helpers.rb
|
130
132
|
- lib/stackable_flash/version.rb
|
131
133
|
- spec/controllers/dummy_controller_spec.rb
|
132
134
|
- spec/dummy/Rakefile
|
@@ -165,6 +167,7 @@ files:
|
|
165
167
|
- spec/dummy/script/rails
|
166
168
|
- spec/spec_helper.rb
|
167
169
|
- spec/stackable_flash/flash_stack_spec.rb
|
170
|
+
- spec/stackable_flash/rspec_matchers_spec.rb
|
168
171
|
- stackable_flash.gemspec
|
169
172
|
homepage: https://github.com/pboling/stackable_flash
|
170
173
|
licenses: []
|
@@ -228,3 +231,4 @@ test_files:
|
|
228
231
|
- spec/dummy/script/rails
|
229
232
|
- spec/spec_helper.rb
|
230
233
|
- spec/stackable_flash/flash_stack_spec.rb
|
234
|
+
- spec/stackable_flash/rspec_matchers_spec.rb
|