simple_queues 1.0.1 → 1.0.2

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.
@@ -1,4 +1,4 @@
1
- autoload :Redis, "redis"
1
+ require "redis"
2
2
  require 'json'
3
3
 
4
4
  module SimpleQueues
@@ -47,8 +47,8 @@ module SimpleQueues
47
47
  # @raise ArgumentError If +queue_name+ is nil or the empty String.
48
48
  def dequeue_with_timeout(queue_name, timeout)
49
49
  raise ArgumentError, "Queue name argument was nil - must not be" if queue_name.nil? || queue_name.to_s.empty?
50
-
51
- unserialize(@redis.blpop(queue_name.to_s, timeout))
50
+ r = @redis.blpop(queue_name.to_s, timeout)
51
+ unserialize(r && r[1])
52
52
  end
53
53
  end
54
54
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleQueues
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
@@ -48,4 +48,9 @@ describe SimpleQueues::Redis, "dequeue_with_timeout" do
48
48
  lambda { queue.dequeue_with_timeout(nil) }.should raise_error(ArgumentError)
49
49
  lambda { queue.dequeue_with_timeout("") }.should raise_error(ArgumentError)
50
50
  end
51
+
52
+ it "returns the unserialized object" do
53
+ redis.should_receive(:blpop).with("test", 5).and_return(["test", "{\"hello\":\"world\",\"x\":42}"] )
54
+ queue.dequeue_with_timeout(:test, 5).should == {"hello" => "world", "x" => 42}
55
+ end
51
56
  end
@@ -39,5 +39,8 @@ describe SimpleQueues::Redis, "enqueue" do
39
39
 
40
40
  redis.should_receive(:rpush).with("ops", '[1,2,3]')
41
41
  queue.enqueue :ops, [1, 2, 3]
42
+
43
+ redis.should_receive(:rpush).with("ops", "{\"hello\":\"world\",\"x\":42}")
44
+ queue.enqueue :ops, {:hello => "world", :x => 42}
42
45
  end
43
46
  end
@@ -0,0 +1,15 @@
1
+ require "spec_helper"
2
+
3
+ describe SimpleQueues::Redis, "enqueue" do
4
+ let :queue do
5
+ SimpleQueues::Redis.new
6
+ end
7
+
8
+ it "communicates with Redis as expected" do
9
+ obj = {"hello" => 42}
10
+ queue.enqueue(:test, obj)
11
+ queue.dequeue_with_timeout(:test, 2).should == obj
12
+ queue.dequeue_with_timeout(:test, 2).should == nil
13
+ end
14
+
15
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - "Fran\xC3\xA7ois Beausoleil"
@@ -105,6 +105,7 @@ files:
105
105
  - simple_queues.gemspec
106
106
  - spec/dequeueing_spec.rb
107
107
  - spec/enqueueing_spec.rb
108
+ - spec/redis_integration_spec.rb
108
109
  - spec/spec_helper.rb
109
110
  has_rdoc: true
110
111
  homepage: https://github.com/francois/simple_queues
@@ -141,4 +142,5 @@ summary: Simple enqueue/dequeue API for working with queues
141
142
  test_files:
142
143
  - spec/dequeueing_spec.rb
143
144
  - spec/enqueueing_spec.rb
145
+ - spec/redis_integration_spec.rb
144
146
  - spec/spec_helper.rb