stackable_flash 0.0.5 → 0.0.6
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 +5 -0
- data/lib/stackable_flash/stack_layer.rb +31 -29
- data/lib/stackable_flash/version.rb +1 -1
- data/spec/stackable_flash/rspec_matchers_spec.rb +17 -9
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
Version 0.0.6 - AUG.22.2012
|
2
|
+
- Performance - reduce number of calls made in the StackLayer
|
3
|
+
- Added support for hashes, nils, and other object that Array() destroyed (no longer uses Array())
|
4
|
+
- Expanded spec suite
|
5
|
+
|
1
6
|
Version 0.0.5 - AUG.22.2012
|
2
7
|
- Added Rspec Matchers and Test::Unit helpers.
|
3
8
|
|
@@ -25,37 +25,39 @@ module StackableFlash
|
|
25
25
|
return send("[]_without_stacking", key)
|
26
26
|
end
|
27
27
|
|
28
|
+
# Make an array at the key, while providing a seamless upgrade to existing flashes
|
29
|
+
#
|
30
|
+
# Initial set to Array
|
31
|
+
#
|
32
|
+
# Principle of least surprise
|
33
|
+
# flash[:notice] = ['message1','message2']
|
34
|
+
# flash[:notice] # => ['message1','message2']
|
35
|
+
#
|
36
|
+
# Initial set to String
|
37
|
+
#
|
38
|
+
# Principle of least surprise
|
39
|
+
# flash[:notice] = 'original'
|
40
|
+
# flash[:notice] # => ['original']
|
41
|
+
#
|
42
|
+
# Overwrite!
|
43
|
+
#
|
44
|
+
# Principle of least surprise
|
45
|
+
# flash[:notice] = 'original'
|
46
|
+
# flash[:notice] = 'altered'
|
47
|
+
# flash[:notice] # => ['altered']
|
48
|
+
#
|
49
|
+
# The same line of code does all of the above.
|
50
|
+
# Leave existing behavior in place, but send the full array as the value so it doesn't get killed.
|
28
51
|
define_method "[]_with_stacking=" do |key, value|
|
29
52
|
if StackableFlash.stacking
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
# flash[:notice] # => ['message1','message2']
|
39
|
-
#
|
40
|
-
# Initial set to String
|
41
|
-
#
|
42
|
-
# Principle of least surprise
|
43
|
-
# flash[:notice] = 'original'
|
44
|
-
# flash[:notice] # => ['original']
|
45
|
-
#
|
46
|
-
# Overwrite!
|
47
|
-
#
|
48
|
-
# Principle of least surprise
|
49
|
-
# flash[:notice] = 'original'
|
50
|
-
# flash[:notice] = 'altered'
|
51
|
-
# flash[:notice] # => ['altered']
|
52
|
-
#
|
53
|
-
# The same line of code does all of the above:
|
54
|
-
self[key] = StackableFlash::FlashStack.new.replace(value.kind_of?(Array) ? value : Array(value))
|
55
|
-
|
56
|
-
# Leave existing behavior in place, but send the full array as the value so it doesn't get killed.
|
57
|
-
send("[]_without_stacking=", key, self[key])
|
58
|
-
end
|
53
|
+
send("[]_without_stacking=", key,
|
54
|
+
StackableFlash::FlashStack.new.replace(
|
55
|
+
value.kind_of?(Array) ?
|
56
|
+
value :
|
57
|
+
# Preserves nil values in the result... I suppose that's OK, users can compact if needed :)
|
58
|
+
Array.new(1, value)
|
59
|
+
)
|
60
|
+
)
|
59
61
|
else
|
60
62
|
# All StackableFlash functionality is completely bypassed
|
61
63
|
send("[]_without_stacking=", key, value)
|
@@ -1,25 +1,33 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe StackableFlash::
|
3
|
+
describe StackableFlash::RspecMatchers do
|
4
4
|
before(:each) do
|
5
5
|
@flash = ActionDispatch::Flash::FlashHash.new
|
6
6
|
end
|
7
7
|
describe "tests against strange things" do
|
8
8
|
context "should" do
|
9
|
-
it "should
|
10
|
-
lambda {@flash[:notice].should have_stackable_flash(
|
11
|
-
end
|
12
|
-
it "should be able to test against odd values like {:hello => 'asdf'}" do
|
9
|
+
it "should raise error when not a match" do
|
10
|
+
lambda {@flash[:notice].should have_stackable_flash(1)}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
13
11
|
lambda {@flash[:notice].should have_stackable_flash({:hello => 'asdf'})}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
14
12
|
end
|
13
|
+
it "should not raise an error when a match" do
|
14
|
+
lambda { @flash[:notice] = 1
|
15
|
+
@flash[:notice].should have_stackable_flash(1)}.should_not raise_exception
|
16
|
+
lambda { @flash[:notice] = {:hello => 'asdf'}
|
17
|
+
@flash[:notice].should have_stackable_flash({:hello => 'asdf'})}.should_not raise_exception
|
18
|
+
end
|
15
19
|
end
|
16
20
|
context "should_not" do
|
17
|
-
it "should
|
18
|
-
lambda {@flash[:notice].should_not have_stackable_flash(
|
19
|
-
end
|
20
|
-
it "should be able to test against odd values like {:hello => 'asdf'}" do
|
21
|
+
it "should raise error when not a match" do
|
22
|
+
lambda {@flash[:notice].should_not have_stackable_flash(1)}.should_not raise_exception
|
21
23
|
lambda {@flash[:notice].should_not have_stackable_flash({:hello => 'asdf'})}.should_not raise_exception
|
22
24
|
end
|
25
|
+
it "should not raise an error when a match" do
|
26
|
+
lambda { @flash[:notice] = 1
|
27
|
+
@flash[:notice].should_not have_stackable_flash(1)}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
28
|
+
lambda { @flash[:notice] = {:hello => 'asdf'}
|
29
|
+
@flash[:notice].should_not have_stackable_flash({:hello => 'asdf'})}.should raise_error RSpec::Expectations::ExpectationNotMetError
|
30
|
+
end
|
23
31
|
end
|
24
32
|
end
|
25
33
|
|