lita-locker 0.7.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,49 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Lita::Handlers::LockerHttp, lita_handler: true do
4
+ let(:request) do
5
+ request = double('Rack::Request')
6
+ allow(request).to receive(:env).and_return(params)
7
+ request
8
+ end
9
+
10
+ let(:params) do
11
+ { 'router.params' => { name: 'foo' } }
12
+ end
13
+
14
+ let(:response) do
15
+ Rack::Response.new
16
+ end
17
+
4
18
  it do
5
- is_expected.to route_http(:get, '/locker/label/foobar')
6
- .to(:http_label_show)
19
+ is_expected.to route_http(:get, '/locker/label/foobar').to(:label_show)
20
+ is_expected.to route_http(:get, '/locker/resource/foobar').to(:resource_show)
21
+ end
22
+
23
+ describe '#label_show' do
24
+ it 'shows json if the label exists' do
25
+ send_command('locker label create foo')
26
+ subject.label_show(request, response)
27
+ expect(response.body).to eq(["{\"id\":\"foo\",\"state\":\"unlocked\",\"membership\":\"\"}"])
28
+ end
29
+
30
+ it 'shows 404 if the label does not exist' do
31
+ subject.label_show(request, response)
32
+ expect(response.status).to eq(404)
33
+ end
34
+ end
35
+
36
+ describe '#resource_show' do
37
+ it 'shows json if the resource exists' do
38
+ robot.auth.add_user_to_group!(user, :locker_admins)
39
+ send_command('locker resource create foo')
40
+ subject.resource_show(request, response)
41
+ expect(response.body).to eq(["{\"id\":\"foo\",\"state\":\"unlocked\",\"owner_id\":\"\"}"])
42
+ end
7
43
 
8
- is_expected.to route_http(:get, '/locker/resource/foobar')
9
- .to(:http_resource_show)
44
+ it 'shows 404 if the resource does not exist' do
45
+ subject.resource_show(request, response)
46
+ expect(response.status).to eq(404)
47
+ end
10
48
  end
11
49
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe Lita::Handlers::LockerLabels, lita_handler: true do
4
4
  before do
5
5
  robot.auth.add_user_to_group!(user, :locker_admins)
6
+ Lita.config.robot.adapter = :hipchat
6
7
  end
7
8
 
8
9
  label_examples = ['foobar', 'foo bar', 'foo-bar', 'foo_bar']
@@ -13,7 +14,18 @@ describe Lita::Handlers::LockerLabels, lita_handler: true do
13
14
  is_expected.to route_command("locker label delete #{l}").to(:delete)
14
15
  is_expected.to route_command("locker label show #{l}").to(:show)
15
16
  is_expected.to route_command("locker label add resource to #{l}").to(:add)
17
+ is_expected.to route_command("locker label add foo, bar to #{l}").to(:add)
16
18
  is_expected.to route_command("locker label remove resource from #{l}").to(:remove)
19
+ is_expected.to route_command("locker label remove foo, bar from #{l}").to(:remove)
20
+ end
21
+ end
22
+
23
+ multi_label_examples = ['foo, bar', 'foo,bar']
24
+
25
+ multi_label_examples.each do |l|
26
+ it do
27
+ is_expected.to route_command("locker label create #{l}").to(:create)
28
+ is_expected.to route_command("locker label delete #{l}").to(:delete)
17
29
  end
18
30
  end
19
31
 
@@ -24,8 +36,8 @@ describe Lita::Handlers::LockerLabels, lita_handler: true do
24
36
  send_command('locker label create foobar')
25
37
  send_command('locker label create bazbat')
26
38
  send_command('locker label list')
27
- expect(replies.include?('Label: foobar, state: unlocked')).to eq(true)
28
- expect(replies.include?('Label: bazbat, state: unlocked')).to eq(true)
39
+ expect(replies.include?('foobar is unlocked')).to eq(true)
40
+ expect(replies.include?('bazbat is unlocked')).to eq(true)
29
41
  end
30
42
  end
31
43
 
@@ -41,11 +53,22 @@ describe Lita::Handlers::LockerLabels, lita_handler: true do
41
53
  expect(replies.last).to eq('foobar already exists')
42
54
  end
43
55
 
44
- it 'shows a warning when the <name> already exists as a resource' do
45
- send_command('locker resource create foobar')
46
- send_command('locker label create foobar')
47
- expect(replies.last).to eq('foobar already exists')
56
+ it 'accepts a comma-separated list of labels' do
57
+ send_command('locker label create foo, bar,baz')
58
+ expect(replies.last).to eq('Label foo created, Label bar created, Label baz created')
48
59
  end
60
+
61
+ it 'handles comma-separated labels nicely when a label already exists' do
62
+ send_command('locker label create bar')
63
+ send_command('locker label create foo, bar,baz')
64
+ expect(replies.last).to eq('Label foo created, bar already exists, Label baz created')
65
+ end
66
+
67
+ # it 'shows a warning when the <name> already exists as a resource' do
68
+ # send_command('locker resource create foobar')
69
+ # send_command('locker label create foobar')
70
+ # expect(replies.last).to eq('foobar already exists')
71
+ # end
49
72
  end
50
73
 
51
74
  describe '#label_delete' do
@@ -59,6 +82,12 @@ describe Lita::Handlers::LockerLabels, lita_handler: true do
59
82
  send_command('locker label delete foobar')
60
83
  expect(replies.last).to eq('Label foobar does not exist. To create it: "!locker label create foobar"')
61
84
  end
85
+
86
+ it 'accepts a comma-separated list of labels' do
87
+ send_command('locker label create foo, bar, baz')
88
+ send_command('locker label delete foo, bar,baz')
89
+ expect(replies.last).to eq('Label foo deleted, Label bar deleted, Label baz deleted')
90
+ end
62
91
  end
63
92
 
64
93
  describe '#label_show' do
@@ -104,6 +133,14 @@ describe Lita::Handlers::LockerLabels, lita_handler: true do
104
133
  expect(replies.last).to match(/baz/)
105
134
  end
106
135
 
136
+ it 'adds multiple resources to a label when given as a comma-separated list' do
137
+ send_command('locker resource create foo')
138
+ send_command('locker resource create bar')
139
+ send_command('locker label create baz')
140
+ send_command('locker label add foo, bar to baz')
141
+ expect(replies.last).to eq('Resource foo has been added to baz, Resource bar has been added to baz')
142
+ end
143
+
107
144
  it 'shows an error if the label does not exist' do
108
145
  send_command('locker label add foo to bar')
109
146
  expect(replies.last).to eq('Label bar does not exist. To create it: "!locker label create bar"')
@@ -133,15 +170,36 @@ describe Lita::Handlers::LockerLabels, lita_handler: true do
133
170
  expect(replies.last).to eq('Label bar does not have Resource foo')
134
171
  end
135
172
 
173
+ it 'removes multiple resources to a label when given as a comma-separated list' do
174
+ send_command('locker resource create foo')
175
+ send_command('locker resource create bar')
176
+ send_command('locker label create baz')
177
+ send_command('locker label add foo, bar to baz')
178
+ send_command('locker label remove foo, bar from baz')
179
+ expect(replies.last).to eq('Resource foo has been removed from baz, Resource bar has been removed from baz')
180
+ end
181
+
136
182
  it 'shows an error if the label does not exist' do
137
183
  send_command('locker label add foo to bar')
138
184
  expect(replies.last).to eq('Label bar does not exist. To create it: "!locker label create bar"')
139
185
  end
140
186
 
187
+ it 'shows an error if the label does not exist when given a list of resources' do
188
+ send_command('locker label add foo, baz to bar')
189
+ expect(replies.last).to eq('Label bar does not exist. To create it: "!locker label create bar"')
190
+ end
191
+
141
192
  it 'shows an error if the resource does not exist' do
142
193
  send_command('locker label create bar')
143
194
  send_command('locker label add foo to bar')
144
195
  expect(replies.last).to eq('Resource foo does not exist')
145
196
  end
197
+
198
+ it 'shows an error if a resource in a list does not exist' do
199
+ send_command('locker label create bar')
200
+ send_command('locker resource create baz')
201
+ send_command('locker label add foo, baz to bar')
202
+ expect(replies.last).to eq('Resource foo does not exist, Resource baz has been added to bar')
203
+ end
146
204
  end
147
205
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe Lita::Handlers::LockerMisc, lita_handler: true do
4
4
  before do
5
5
  robot.auth.add_user_to_group!(user, :locker_admins)
6
+ Lita.config.robot.adapter = :hipchat
6
7
  end
7
8
 
8
9
  label_examples = ['foobar', 'foo bar', 'foo-bar', 'foo_bar']
@@ -16,8 +17,54 @@ describe Lita::Handlers::LockerMisc, lita_handler: true do
16
17
  it { is_expected.to route_command("locker status #{r}").to(:status) }
17
18
  end
18
19
 
19
- it { is_expected.to route_command('locker list @alice').to(:list) }
20
- it { is_expected.to route_command('locker list Alice').to(:list) }
20
+ it do
21
+ is_expected.to route_command('locker list @alice').to(:list)
22
+ is_expected.to route_command('locker list Alice').to(:list)
23
+ end
24
+
25
+ it do
26
+ is_expected.to route_command('locker log something').to(:log)
27
+ end
28
+
29
+ let(:alice) do
30
+ Lita::User.create('9001@hipchat', name: 'Alice', mention_name: 'alice')
31
+ end
32
+
33
+ let(:bob) do
34
+ Lita::User.create('9002@hipchat', name: 'Bob', mention_name: 'bob')
35
+ end
36
+
37
+ let(:doris) do
38
+ Lita::User.create('9004@hipchat', name: 'Doris Da-Awesome', mention_name: 'doris')
39
+ end
40
+
41
+ describe '#log' do
42
+ it 'shows an activity log for labels if one exists' do
43
+ send_command('locker resource create bar')
44
+ send_command('locker label create foo')
45
+ send_command('locker label add bar to foo')
46
+ send_command('lock foo', as: alice)
47
+ send_command('locker log foo')
48
+ expect(replies.count).to eq(7)
49
+ end
50
+
51
+ it 'shows a warning if the label does not exist' do
52
+ send_command('locker log something')
53
+ expect(replies.last).to eq('Sorry, that does not exist')
54
+ end
55
+ end
56
+
57
+ describe '#dequeue' do
58
+ it 'shows a successful dequeue' do
59
+ send_command('locker resource create bar')
60
+ send_command('locker label create foo')
61
+ send_command('locker label add bar to foo')
62
+ send_command('lock foo', as: alice)
63
+ send_command('lock foo', as: bob)
64
+ send_command('locker dequeue foo', as: bob)
65
+ expect(replies.last).to eq('You have been removed from the queue for foo')
66
+ end
67
+ end
21
68
 
22
69
  describe '#status' do
23
70
  it 'shows the status of a label' do
@@ -25,10 +72,16 @@ describe Lita::Handlers::LockerMisc, lita_handler: true do
25
72
  send_command('locker label create foo')
26
73
  send_command('locker label add bar to foo')
27
74
  send_command('locker status foo')
28
- expect(replies.last).to eq('Label: foo, state: unlocked')
75
+ expect(replies.last).to eq('foo is unlocked')
29
76
  send_command('lock foo')
30
77
  send_command('locker status foo')
31
- expect(replies.last).to eq('Label: foo, state: locked, owner: Test User')
78
+ expect(replies.last).to eq('foo is locked by Test User (taken 1 second ago)')
79
+ send_command('lock foo', as: alice)
80
+ send_command('locker status foo')
81
+ expect(replies.last).to eq('foo is locked by Test User (taken 1 second ago). Next up: Alice')
82
+ send_command('lock foo', as: bob)
83
+ send_command('locker status foo')
84
+ expect(replies.last).to eq('foo is locked by Test User (taken 1 second ago). Next up: Alice, Bob')
32
85
  end
33
86
 
34
87
  it 'shows the status of a resource' do
@@ -53,9 +106,8 @@ describe Lita::Handlers::LockerMisc, lita_handler: true do
53
106
  send_command('locker resource create foobar')
54
107
  send_command('locker label create bazbat')
55
108
  send_command('locker label add foobar to bazbat')
56
- alice = Lita::User.create('9001@hipchat', name: 'Alice Alpha', mention_name: 'alice')
57
109
  send_command('lock bazbat', as: alice)
58
- send_command('locker list Alice Alpha')
110
+ send_command('locker list Alice')
59
111
  expect(replies.last).to eq("Label: bazbat\n")
60
112
  end
61
113
 
@@ -63,17 +115,24 @@ describe Lita::Handlers::LockerMisc, lita_handler: true do
63
115
  send_command('locker resource create foobar')
64
116
  send_command('locker label create bazbat')
65
117
  send_command('locker label add foobar to bazbat')
66
- alice = Lita::User.create('9001@hipchat', name: 'Alice Alpha', mention_name: 'alice')
67
118
  send_command('lock bazbat', as: alice)
68
119
  send_command('locker list @alice')
69
120
  expect(replies.last).to eq("Label: bazbat\n")
70
121
  end
71
122
 
123
+ it 'shows if a name with dashes has taken any locks' do
124
+ send_command('locker resource create foobar')
125
+ send_command('locker label create bazbat')
126
+ send_command('locker label add foobar to bazbat')
127
+ send_command('lock bazbat', as: doris)
128
+ send_command('locker list Doris Da-Awesome')
129
+ expect(replies.last).to eq("Label: bazbat\n")
130
+ end
131
+
72
132
  it 'shows an empty set if the user has not taken any locks' do
73
133
  send_command('locker resource create foobar')
74
134
  send_command('locker label create bazbat')
75
135
  send_command('locker label add foobar to bazbat')
76
- alice = Lita::User.create('9001@hipchat', name: 'Alice', mention_name: 'alice')
77
136
  send_command('locker list Alice', as: alice)
78
137
  expect(replies.last).to eq('That user has no active locks')
79
138
  send_command('lock bazbat', as: alice)
@@ -15,6 +15,15 @@ describe Lita::Handlers::LockerResources, lita_handler: true do
15
15
  end
16
16
  end
17
17
 
18
+ multi_resource_examples = ['foo, bar', 'foo,bar']
19
+
20
+ multi_resource_examples.each do |r|
21
+ it do
22
+ is_expected.to route_command("locker resource create #{r}").to(:create)
23
+ is_expected.to route_command("locker resource delete #{r}").to(:delete)
24
+ end
25
+ end
26
+
18
27
  it { is_expected.to route_command('locker resource list').to(:list) }
19
28
 
20
29
  describe '#resource_list' do
@@ -22,8 +31,8 @@ describe Lita::Handlers::LockerResources, lita_handler: true do
22
31
  send_command('locker resource create foobar')
23
32
  send_command('locker resource create bazbat')
24
33
  send_command('locker resource list')
25
- expect(replies.last).to match(/Resource: foobar, state: unlocked/)
26
- expect(replies.last).to match(/Resource: bazbat, state: unlocked/)
34
+ expect(replies).to include('Resource: foobar, state: unlocked')
35
+ expect(replies).to include('Resource: bazbat, state: unlocked')
27
36
  end
28
37
  end
29
38
 
@@ -39,11 +48,22 @@ describe Lita::Handlers::LockerResources, lita_handler: true do
39
48
  expect(replies.last).to eq('foobar already exists')
40
49
  end
41
50
 
42
- it 'shows a warning when the <name> already exists as a label' do
43
- send_command('locker label create foobar')
44
- send_command('locker resource create foobar')
45
- expect(replies.last).to eq('foobar already exists')
51
+ it 'creates multiple resources when given a comma-separated list' do
52
+ send_command('locker resource create foo, bar,baz')
53
+ expect(replies.last).to eq('Resource foo created, Resource bar created, Resource baz created')
46
54
  end
55
+
56
+ it 'shows a warning when a resource in a comma-separated list exists' do
57
+ send_command('locker resource create bar')
58
+ send_command('locker resource create foo, bar,baz')
59
+ expect(replies.last).to eq('Resource foo created, bar already exists, Resource baz created')
60
+ end
61
+
62
+ # it 'shows a warning when the <name> already exists as a label' do
63
+ # send_command('locker label create foobar')
64
+ # send_command('locker resource create foobar')
65
+ # expect(replies.last).to eq('foobar already exists')
66
+ # end
47
67
  end
48
68
 
49
69
  describe '#resource_delete' do
@@ -57,6 +77,21 @@ describe Lita::Handlers::LockerResources, lita_handler: true do
57
77
  send_command('locker resource delete foobar')
58
78
  expect(replies.last).to eq('Resource foobar does not exist')
59
79
  end
80
+
81
+ it 'deletes multiple resources when given a comma-separated list' do
82
+ send_command('locker resource create foo')
83
+ send_command('locker resource create bar')
84
+ send_command('locker resource create baz')
85
+ send_command('locker resource delete foo, bar,baz')
86
+ expect(replies.last).to eq('Resource foo deleted, Resource bar deleted, Resource baz deleted')
87
+ end
88
+
89
+ it 'shows a warning when a resource in a comma-separated list does not exist' do
90
+ send_command('locker resource create foo')
91
+ send_command('locker resource create baz')
92
+ send_command('locker resource delete foo, bar,baz')
93
+ expect(replies.last).to eq('Resource foo deleted, Resource bar does not exist, Resource baz deleted')
94
+ end
60
95
  end
61
96
 
62
97
  describe '#resource_show' do
@@ -66,6 +101,18 @@ describe Lita::Handlers::LockerResources, lita_handler: true do
66
101
  expect(replies.last).to eq('Resource: foobar, state: unlocked')
67
102
  end
68
103
 
104
+ it 'shows what labels use a resource' do
105
+ send_command('locker resource create foobar')
106
+ send_command('locker resource show foobar')
107
+ send_command('locker label create l1')
108
+ send_command('locker label add foobar to l1')
109
+ send_command('locker resource show foobar')
110
+ expect(replies.last).to eq('Resource: foobar, state: unlocked, used by: l1')
111
+ send_command('locker label remove foobar from l1')
112
+ send_command('locker resource show foobar')
113
+ expect(replies.last).to eq('Resource: foobar, state: unlocked')
114
+ end
115
+
69
116
  it 'shows a warning when <name> does not exist' do
70
117
  send_command('locker resource show foobar')
71
118
  expect(replies.last).to eq('Resource foobar does not exist')
@@ -5,7 +5,7 @@ describe Lita::Handlers::Locker, lita_handler: true do
5
5
  robot.auth.add_user_to_group!(user, :locker_admins)
6
6
  end
7
7
 
8
- label_examples = ['foobar', 'foo bar', 'foo-bar', 'foo_bar']
8
+ label_examples = ['foobar', 'foo bar', 'foo-bar', 'foo_bar', 'foobar ']
9
9
 
10
10
  label_examples.each do |l|
11
11
  it do
@@ -38,22 +38,53 @@ describe Lita::Handlers::Locker, lita_handler: true do
38
38
  Lita::User.create('9002@hipchat', name: 'Bob', mention_name: 'bob')
39
39
  end
40
40
 
41
+ let(:charlie) do
42
+ Lita::User.create('9003@hipchat', name: 'Charlie', mention_name: 'charlie')
43
+ end
44
+
41
45
  describe '#lock' do
42
46
  it 'locks a label when it is available and has resources' do
43
47
  send_command('locker resource create foobar')
44
48
  send_command('locker label create bazbat')
45
49
  send_command('locker label add foobar to bazbat')
46
50
  send_command('lock bazbat # with a comment')
47
- expect(replies.last).to eq('(successful) bazbat locked')
51
+ expect(replies.last).to eq('bazbat locked')
48
52
  send_command('locker resource show foobar')
49
- expect(replies.last).to eq('Resource: foobar, state: locked')
53
+ expect(replies.last).to eq('Resource: foobar, state: locked, used by: bazbat')
54
+ end
55
+
56
+ it 'locks the same label with spaces after the name' do
57
+ send_command('locker resource create foobar')
58
+ send_command('locker label create bazbat')
59
+ send_command('locker label add foobar to bazbat')
60
+ send_command('lock bazbat ')
61
+ expect(replies.last).to eq('bazbat locked')
62
+ end
63
+
64
+ it 'does not enqueue the user that currently has a lock' do
65
+ send_command('locker resource create foobar')
66
+ send_command('locker label create bazbat')
67
+ send_command('locker label add foobar to bazbat')
68
+ send_command('lock bazbat')
69
+ send_command('lock bazbat')
70
+ expect(replies.last).to eq('You already have the lock on bazbat')
71
+ end
72
+
73
+ it 'does not add a user multiple times to the end of a queue' do
74
+ send_command('locker resource create foobar')
75
+ send_command('locker label create bazbat')
76
+ send_command('locker label add foobar to bazbat')
77
+ send_command('lock bazbat', as: alice)
78
+ send_command('lock bazbat', as: bob)
79
+ send_command('lock bazbat', as: bob)
80
+ send_command('locker status bazbat')
81
+ expect(replies.last).to eq('bazbat is locked by Alice (taken 1 second ago). Next up: Bob')
50
82
  end
51
83
 
52
84
  it 'shows a warning when a label has no resources' do
53
85
  send_command('locker label create foobar')
54
86
  send_command('lock foobar')
55
- expect(replies.last).to eq('(failed) foobar has no resources, ' \
56
- 'so it cannot be locked')
87
+ expect(replies.last).to eq('foobar has no resources, so it cannot be locked')
57
88
  end
58
89
 
59
90
  it 'shows a warning when a label is unavailable' do
@@ -64,8 +95,21 @@ describe Lita::Handlers::Locker, lita_handler: true do
64
95
  send_command('locker label add r1 to l2')
65
96
  send_command('lock l1', as: alice)
66
97
  send_command('lock l2', as: alice)
67
- expect(replies.last).to eq('(failed) Label unable to be locked, ' \
68
- "blocked on:\nr1 - Alice")
98
+ expect(replies.last).to eq("Label unable to be locked, blocked on:\nr1 - Alice")
99
+ end
100
+
101
+ it 'does not half-lock underlying resources' do
102
+ send_command('locker resource create r1')
103
+ send_command('locker resource create r2')
104
+ send_command('locker label create l1')
105
+ send_command('locker label create l2')
106
+ send_command('locker label add r1, r2 to l1')
107
+ send_command('locker label add r1 to l2')
108
+ send_command('lock l2', as: alice)
109
+ send_command('lock l1', as: bob)
110
+ send_command('unlock l2', as: alice)
111
+ send_command('lock l1', as: alice)
112
+ expect(replies.last).to eq('l1 locked')
69
113
  end
70
114
 
71
115
  it 'shows a warning when a label is taken by someone else' do
@@ -74,28 +118,14 @@ describe Lita::Handlers::Locker, lita_handler: true do
74
118
  send_command('locker label add foobar to bazbat')
75
119
  send_command('lock bazbat', as: alice)
76
120
  send_command('lock bazbat', as: bob)
77
- expect(replies.last).to eq('(failed) bazbat is locked by Alice (@alice)')
121
+ expect(replies.last).to eq('bazbat is locked by Alice (@alice) (taken 1 second ago), you have been ' \
122
+ 'added to the queue, type \'locker dequeue bazbat\' to be removed')
78
123
  end
79
124
 
80
125
  it 'shows an error when a label does not exist' do
81
126
  send_command('lock foobar')
82
- expect(replies.last).to eq('(failed) Label foobar does not exist. To ' \
83
- 'create it: "!locker label create foobar"')
84
- end
85
-
86
- # it 'locks a resource when it is available for a period of time' do
87
- # send_command('locker resource create foobar')
88
- # send_command('lock foobar 17m')
89
- # expect(replies.last).to eq('foobar locked for 17 minutes')
90
- # send_command('locker resource show foobar')
91
- # expect(replies.last).to eq('Resource: foobar, state: locked')
92
- # send_command('unlock foobar')
93
- # send_command('lock foobar 12s')
94
- # expect(replies.last).to eq('foobar locked for 17 seconds')
95
- # send_command('unlock foobar')
96
- # send_command('lock foobar 14h')
97
- # expect(replies.last).to eq('foobar locked for 14 hours')
98
- # end
127
+ expect(replies.last).to eq('Label foobar does not exist. To create it: "!locker label create foobar"')
128
+ end
99
129
  end
100
130
 
101
131
  describe '#unlock' do
@@ -105,7 +135,17 @@ describe Lita::Handlers::Locker, lita_handler: true do
105
135
  send_command('locker label add foobar to bazbat')
106
136
  send_command('lock bazbat')
107
137
  send_command('unlock bazbat # with a comment')
108
- expect(replies.last).to eq('(successful) bazbat unlocked')
138
+ expect(replies.last).to eq('bazbat unlocked')
139
+ end
140
+
141
+ it 'moves to the next queued person when there is one' do
142
+ send_command('locker resource create foobar')
143
+ send_command('locker label create bazbat')
144
+ send_command('locker label add foobar to bazbat')
145
+ send_command('lock bazbat', as: alice)
146
+ send_command('lock bazbat', as: bob)
147
+ send_command('unlock bazbat # with a comment', as: alice)
148
+ expect(replies.last).to eq('bazbat now locked by Bob (@bob)')
109
149
  end
110
150
 
111
151
  it 'does not unlock a label when someone else locked it' do
@@ -114,7 +154,7 @@ describe Lita::Handlers::Locker, lita_handler: true do
114
154
  send_command('locker label add foobar to bazbat')
115
155
  send_command('lock bazbat', as: alice)
116
156
  send_command('unlock bazbat', as: bob)
117
- expect(replies.last).to eq('(failed) bazbat is locked by Alice (@alice)')
157
+ expect(replies.last).to eq('bazbat is locked by Alice (@alice) (taken 1 second ago)')
118
158
  end
119
159
 
120
160
  it 'shows a warning when a label is already unlocked' do
@@ -123,12 +163,12 @@ describe Lita::Handlers::Locker, lita_handler: true do
123
163
  send_command('locker label add foobar to bazbat')
124
164
  send_command('unlock bazbat')
125
165
  send_command('unlock bazbat')
126
- expect(replies.last).to eq('(successful) bazbat is unlocked')
166
+ expect(replies.last).to eq('bazbat is unlocked')
127
167
  end
128
168
 
129
169
  it 'shows an error when a <subject> does not exist' do
130
170
  send_command('unlock foobar')
131
- expect(replies.last).to eq('(failed) Sorry, that does not exist')
171
+ expect(replies.last).to eq('Sorry, that does not exist')
132
172
  end
133
173
  end
134
174
 
@@ -139,8 +179,18 @@ describe Lita::Handlers::Locker, lita_handler: true do
139
179
  send_command('locker label add foobar to bazbat')
140
180
  send_command('lock bazbat', as: alice)
141
181
  send_command('steal bazbat # with a comment', as: bob)
142
- expect(replies.last).to eq('(successful) bazbat stolen from ' \
143
- 'Alice (@alice)')
182
+ expect(replies.last).to eq('bazbat stolen from Alice (@alice)')
183
+ end
184
+
185
+ it 'preserves the state of the queue when there is one' do
186
+ send_command('locker resource create foobar')
187
+ send_command('locker label create bazbat')
188
+ send_command('locker label add foobar to bazbat')
189
+ send_command('lock bazbat', as: alice)
190
+ send_command('lock bazbat', as: bob)
191
+ send_command('steal bazbat', as: charlie)
192
+ send_command('locker status bazbat')
193
+ expect(replies.last).to eq('bazbat is locked by Charlie (taken 1 second ago). Next up: Bob')
144
194
  end
145
195
 
146
196
  it 'shows a warning when the label is already unlocked' do
@@ -162,7 +212,7 @@ describe Lita::Handlers::Locker, lita_handler: true do
162
212
 
163
213
  it 'shows an error when a <subject> does not exist' do
164
214
  send_command('steal foobar')
165
- expect(replies.last).to eq('(failed) Sorry, that does not exist')
215
+ expect(replies.last).to eq('Sorry, that does not exist')
166
216
  end
167
217
  end
168
218
  end
@@ -0,0 +1 @@
1
+ <%= @string %>
@@ -0,0 +1 @@
1
+ (failed) <%= @string %>
@@ -0,0 +1 @@
1
+ :failed: <%= @string %>
@@ -0,0 +1 @@
1
+ <%= @string %>
@@ -0,0 +1 @@
1
+ (lock) <%= @string %>
@@ -0,0 +1 @@
1
+ :lock: <%= @string %>
@@ -0,0 +1 @@
1
+ <%= @string %>
@@ -0,0 +1 @@
1
+ (successful) <%= @string %>
@@ -0,0 +1 @@
1
+ :successful: <%= @string %>
@@ -0,0 +1 @@
1
+ <%= @string %>
@@ -0,0 +1 @@
1
+ (unlock) <%= @string %>
@@ -0,0 +1 @@
1
+ :unlock: <%= @string %>