redness 0.1.0 → 0.1.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/lib/redness/red.rb CHANGED
@@ -26,12 +26,14 @@ class Red
26
26
  end
27
27
 
28
28
  def multi_with_caution(fail_return = [])
29
- redis.multi
30
- yield
31
- redis.exec
32
- rescue
33
- redis.discard
34
- fail_return
29
+ redis.multi rescue return
30
+ begin
31
+ yield
32
+ redis.exec
33
+ rescue
34
+ redis.discard
35
+ fail_return
36
+ end
35
37
  end
36
38
 
37
39
  def method_missing(method, *args)
@@ -1,4 +1,4 @@
1
1
  module Redness
2
- VERSION="0.1.0"
2
+ VERSION="0.1.1"
3
3
  MAJOR, MINOR, TINY = VERSION.split(".")
4
4
  end
@@ -0,0 +1,31 @@
1
+ require_relative '../spec_integration_helper'
2
+
3
+ describe Red do
4
+ describe "#multi_with_caution" do
5
+ it "should not try call discard if the multi fails" do
6
+ Red.redis.stub(:multi).and_raise(Redis::TimeoutError)
7
+ red = Red.new
8
+ lambda do
9
+ red.multi_with_caution{}
10
+ end.should_not raise_error
11
+ end
12
+
13
+ it "should exec the transaction if the block does not raise an exception" do
14
+ Red.redis.should_receive(:multi)
15
+ Red.redis.should_receive(:exec)
16
+ Red.redis.should_not_receive(:discard)
17
+ Red.new.multi_with_caution{}
18
+ end
19
+
20
+ it "should discard the transaction if the block raises an exception" do
21
+ error_class = Class.new(RuntimeError)
22
+ Red.redis.should_receive(:multi)
23
+ Red.redis.should_not_receive(:exec)
24
+ Red.redis.should_receive(:discard)
25
+ begin
26
+ Red.new.multi_with_caution{raise error_class}
27
+ rescue error_class
28
+ end
29
+ end
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -148,6 +148,7 @@ files:
148
148
  - spec/redness/red_set_multi_spec.rb
149
149
  - spec/redness/red_set_spec.rb
150
150
  - spec/redness/red_set_union_spec.rb
151
+ - spec/redness/red_spec.rb
151
152
  - spec/redness/timed_red_set_spec.rb
152
153
  - spec/spec_integration_helper.rb
153
154
  homepage: http://github.com/howaboutwe/redness