requeue 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/requeue.rb +3 -3
- data/lib/requeue/version.rb +1 -1
- data/spec/requeue_spec.rb +21 -25
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a50634423a9b4983dabf590dec78f667453341d6
|
4
|
+
data.tar.gz: a0cc2ce7e7b85502f94aac32e8d961f27f908fe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7fbb67b2d91a065672e78c609b3071dae7a501233e447b4de713de8a9ef2c4481dfeedea9d3179ea362e8474fc992f66535de1b3160cd390ff341977d933d61
|
7
|
+
data.tar.gz: d5b8e45fc3d90c7a904a09ccdaa0b57775301dfb7ce589c07521b132f17cbe0fb0689a97decbf4feea416133207bf5a61cfa769bd2e07fa0535d7683e7827019
|
data/README.md
CHANGED
data/lib/requeue.rb
CHANGED
@@ -45,7 +45,7 @@ module Requeue
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def remove!(value)
|
48
|
-
@redis.lrem(name,0,value)
|
48
|
+
@redis.lrem(name, 0, value)
|
49
49
|
end
|
50
50
|
|
51
51
|
def owner
|
@@ -53,7 +53,7 @@ module Requeue
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def first
|
56
|
-
@redis.lrange(name,0,1).first
|
56
|
+
@redis.lrange(name, 0, 1).first
|
57
57
|
end
|
58
58
|
|
59
59
|
def owned?
|
@@ -61,7 +61,7 @@ module Requeue
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def steal!(value)
|
64
|
-
@redis.lpush(name,value)
|
64
|
+
@redis.lpush(name, value)
|
65
65
|
end
|
66
66
|
|
67
67
|
def as_json
|
data/lib/requeue/version.rb
CHANGED
data/spec/requeue_spec.rb
CHANGED
@@ -9,27 +9,25 @@ describe Requeue::Queue do
|
|
9
9
|
@queue.clear!
|
10
10
|
end
|
11
11
|
|
12
|
-
describe '.
|
12
|
+
describe '.name' do
|
13
13
|
it { expect(@queue.name).to eq("test:queue") }
|
14
14
|
end
|
15
15
|
|
16
|
-
describe '.
|
16
|
+
describe '.clear!' do
|
17
17
|
before { @queue.enqueue!('eric') }
|
18
|
-
before { @queue.clear! }
|
19
18
|
|
20
19
|
it 'should empty the queue' do
|
21
|
-
expect
|
20
|
+
expect{ @queue.clear! }.to change { @queue.length }.from(1).to(0)
|
22
21
|
end
|
23
22
|
|
24
23
|
it 'should see an empty queue' do
|
25
|
-
|
24
|
+
expect {@queue.clear! }.to change { @queue.owned? }.from(true).to(false)
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
28
|
describe '.enqueue' do
|
30
29
|
context 'when no users are enqueued' do
|
31
|
-
|
32
|
-
it 'should return 1' do
|
30
|
+
it 'returns the number of users in the queue' do
|
33
31
|
expect(@queue.enqueue!('eric')).to eq(1)
|
34
32
|
end
|
35
33
|
end
|
@@ -37,7 +35,6 @@ describe Requeue::Queue do
|
|
37
35
|
context 'when some users are enqueued' do
|
38
36
|
before { @queue.enqueue!('bob') }
|
39
37
|
before { @queue.enqueue!('eric') }
|
40
|
-
after { @queue.clear! }
|
41
38
|
it 'should have a length of 2' do
|
42
39
|
expect(@queue.length).to eq(2)
|
43
40
|
end
|
@@ -50,8 +47,7 @@ describe Requeue::Queue do
|
|
50
47
|
it 'should add non-unique values if the queue is set to non-unique' do
|
51
48
|
nonunique = Requeue::Queue.new(unique:false)
|
52
49
|
nonunique.enqueue!('eric')
|
53
|
-
nonunique.enqueue!('eric')
|
54
|
-
expect(nonunique.length).to eq(2)
|
50
|
+
expect{ nonunique.enqueue!('eric') }.to change { nonunique.length }.from(1).to(2)
|
55
51
|
end
|
56
52
|
end
|
57
53
|
end
|
@@ -66,22 +62,25 @@ describe Requeue::Queue do
|
|
66
62
|
context 'when some users are enqueued' do
|
67
63
|
before { @queue.enqueue!('bob') }
|
68
64
|
before { @queue.enqueue!('eric') }
|
69
|
-
|
65
|
+
|
70
66
|
it 'should have the current users' do
|
71
67
|
expect(@queue.list).to eq(['bob', 'eric'])
|
72
68
|
end
|
73
69
|
end
|
74
70
|
end
|
71
|
+
|
75
72
|
describe '.user_queued?' do
|
76
73
|
before { @queue.enqueue!('bob') }
|
77
74
|
before { @queue.enqueue!('eric') }
|
78
|
-
|
75
|
+
|
79
76
|
it 'should show eric as queued' do
|
80
77
|
expect(@queue.queued? 'eric').to eq(true)
|
81
78
|
end
|
79
|
+
|
82
80
|
it 'should show bob as queued' do
|
83
81
|
expect(@queue.queued? 'bob').to eq(true)
|
84
82
|
end
|
83
|
+
|
85
84
|
it 'should not show an unqueued user as queued' do
|
86
85
|
expect(@queue.queued? 'jim').to eq(false)
|
87
86
|
end
|
@@ -90,7 +89,7 @@ describe Requeue::Queue do
|
|
90
89
|
describe '.user_position' do
|
91
90
|
before { @queue.enqueue!('bob') }
|
92
91
|
before { @queue.enqueue!('eric') }
|
93
|
-
|
92
|
+
|
94
93
|
it 'eric should be in position 1 (the second place)' do
|
95
94
|
expect(@queue.position 'eric').to eq(1)
|
96
95
|
expect(@queue.position 'bob').to eq(0)
|
@@ -100,14 +99,14 @@ describe Requeue::Queue do
|
|
100
99
|
describe '.dequeue' do
|
101
100
|
before { @queue.enqueue!('bob') }
|
102
101
|
before { @queue.enqueue!('eric') }
|
103
|
-
|
102
|
+
|
104
103
|
it 'eric should be in position 1 (the second place)' do
|
105
|
-
expect
|
104
|
+
expect{ @queue.dequeue! }.to change {@queue.position 'eric'}.from(1).to(0)
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
109
108
|
describe '.owner' do
|
110
|
-
|
109
|
+
context 'when no users are enqueued' do
|
111
110
|
it 'should return empty string' do
|
112
111
|
expect(@queue.owner).to eq(nil)
|
113
112
|
end
|
@@ -124,28 +123,26 @@ describe Requeue::Queue do
|
|
124
123
|
describe '.remove!' do
|
125
124
|
before { @queue.enqueue!('bob') }
|
126
125
|
before { @queue.enqueue!('eric') }
|
127
|
-
before { @queue.remove!('eric') }
|
128
126
|
|
129
127
|
it 'should not contain eric anymore' do
|
130
|
-
expect
|
131
|
-
expect
|
128
|
+
expect { @queue.remove!('eric') }.to change {@queue.queued?('eric')}
|
129
|
+
expect { @queue.remove!('eric') }.to_not change {@queue.queued?('bob')}
|
132
130
|
end
|
133
131
|
end
|
134
132
|
|
135
133
|
describe '.steal!' do
|
136
134
|
before { @queue.enqueue!('bob') }
|
137
135
|
before { @queue.enqueue!('eric') }
|
138
|
-
before { @queue.steal!('jim') }
|
139
136
|
|
140
137
|
it 'jim should own the queue' do
|
141
|
-
expect(@queue.owner()
|
142
|
-
expect(@queue.list).to eq(['jim','bob','eric'])
|
138
|
+
expect { @queue.steal!('jim') }.to change { @queue.owner }.from('bob').to('jim')
|
143
139
|
end
|
144
140
|
|
145
141
|
it 'the queue should still have everyone else in it' do
|
146
|
-
expect(@queue.length).to
|
142
|
+
expect { @queue.steal!('jim') }.to change { @queue.length }.from(2).to(3)
|
147
143
|
end
|
148
144
|
end
|
145
|
+
|
149
146
|
describe '.owned?' do
|
150
147
|
context 'when no users are enqueued' do
|
151
148
|
it 'should start unowned' do
|
@@ -154,9 +151,8 @@ describe Requeue::Queue do
|
|
154
151
|
end
|
155
152
|
|
156
153
|
context 'when a user is enqueued' do
|
157
|
-
before { @queue.enqueue!('eric') }
|
158
154
|
it 'should be owned' do
|
159
|
-
expect
|
155
|
+
expect { @queue.enqueue!('eric') }.to change { @queue.owned? }
|
160
156
|
end
|
161
157
|
end
|
162
158
|
end
|