lita-locker 0.5.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lita-locker.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-locker'
3
- spec.version = '0.5.3'
3
+ spec.version = '0.7.0'
4
4
  spec.authors = ['Eric Sigler']
5
5
  spec.email = ['me@esigler.com']
6
6
  spec.description = '"lock" and "unlock" arbitrary subjects'
@@ -14,12 +14,12 @@ Gem::Specification.new do |spec|
14
14
  spec.test_files = spec.files.grep(/^(test|spec|features)\//)
15
15
  spec.require_paths = ['lib']
16
16
 
17
- spec.add_runtime_dependency 'lita', '>= 3.2'
17
+ spec.add_runtime_dependency 'lita', '>= 4.0.1'
18
18
 
19
19
  spec.add_development_dependency 'bundler', '~> 1.3'
20
+ spec.add_development_dependency 'coveralls'
20
21
  spec.add_development_dependency 'rake'
21
22
  spec.add_development_dependency 'rspec', '>= 3.0.0'
22
- spec.add_development_dependency 'simplecov'
23
- spec.add_development_dependency 'coveralls'
24
23
  spec.add_development_dependency 'rubocop'
24
+ spec.add_development_dependency 'simplecov'
25
25
  end
data/locales/en.yml CHANGED
@@ -2,6 +2,10 @@ en:
2
2
  lita:
3
3
  handlers:
4
4
  locker:
5
+ steal:
6
+ stolen: "%{label} stolen from %{old_owner} %{mention}"
7
+ already_unlocked: "%{label} was already unlocked"
8
+ self: Why are you stealing the lock from yourself?
5
9
  help:
6
10
  lock:
7
11
  syntax: lock <subject>
@@ -15,6 +19,9 @@ en:
15
19
  status:
16
20
  syntax: locker status <label or resource>
17
21
  desc: Show the current state of <label or resource>
22
+ list:
23
+ syntax: locker list <username>
24
+ desc: Show what locks a user currently holds
18
25
  resource:
19
26
  list:
20
27
  syntax: locker resource list
@@ -80,4 +87,4 @@ en:
80
87
  resources: "Label %{name} has: %{resources}"
81
88
  does_not_have_resource: "Label %{label} does not have Resource %{resource}"
82
89
  no_resources: "%{name} has no resources, so it cannot be locked"
83
- dependency: 'Label unable to be locked, blocked on a dependency'
90
+ dependency: 'Label unable to be locked, blocked on:'
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::LockerEvents, lita_handler: true do
4
+ it { is_expected.to route_event(:lock_attempt).to(:lock_attempt) }
5
+ it { is_expected.to route_event(:unlock_attempt).to(:unlock_attempt) }
6
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::LockerHttp, lita_handler: true do
4
+ it do
5
+ is_expected.to route_http(:get, '/locker/label/foobar')
6
+ .to(:http_label_show)
7
+
8
+ is_expected.to route_http(:get, '/locker/resource/foobar')
9
+ .to(:http_resource_show)
10
+ end
11
+ end
@@ -0,0 +1,147 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::LockerLabels, lita_handler: true do
4
+ before do
5
+ robot.auth.add_user_to_group!(user, :locker_admins)
6
+ end
7
+
8
+ label_examples = ['foobar', 'foo bar', 'foo-bar', 'foo_bar']
9
+
10
+ label_examples.each do |l|
11
+ it do
12
+ is_expected.to route_command("locker label create #{l}").to(:create)
13
+ is_expected.to route_command("locker label delete #{l}").to(:delete)
14
+ is_expected.to route_command("locker label show #{l}").to(:show)
15
+ is_expected.to route_command("locker label add resource to #{l}").to(:add)
16
+ is_expected.to route_command("locker label remove resource from #{l}").to(:remove)
17
+ end
18
+ end
19
+
20
+ it { is_expected.to route_command('locker label list').to(:list) }
21
+
22
+ describe '#label_list' do
23
+ it 'shows a list of labels if there are any' do
24
+ send_command('locker label create foobar')
25
+ send_command('locker label create bazbat')
26
+ 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)
29
+ end
30
+ end
31
+
32
+ describe '#label_create' do
33
+ it 'creates a label with <name>' do
34
+ send_command('locker label create foobar')
35
+ expect(replies.last).to eq('Label foobar created')
36
+ end
37
+
38
+ it 'shows a warning when the <name> already exists as a label' do
39
+ send_command('locker label create foobar')
40
+ send_command('locker label create foobar')
41
+ expect(replies.last).to eq('foobar already exists')
42
+ end
43
+
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')
48
+ end
49
+ end
50
+
51
+ describe '#label_delete' do
52
+ it 'deletes a label with <name>' do
53
+ send_command('locker label create foobar')
54
+ send_command('locker label delete foobar')
55
+ expect(replies.last).to eq('Label foobar deleted')
56
+ end
57
+
58
+ it 'shows a warning when <name> does not exist' do
59
+ send_command('locker label delete foobar')
60
+ expect(replies.last).to eq('Label foobar does not exist. To create it: "!locker label create foobar"')
61
+ end
62
+ end
63
+
64
+ describe '#label_show' do
65
+ it 'shows a list of resources for a label if there are any' do
66
+ send_command('locker resource create whatever')
67
+ send_command('locker label create foobar')
68
+ send_command('locker label add whatever to foobar')
69
+ send_command('locker label show foobar')
70
+ expect(replies.last).to eq('Label foobar has: whatever')
71
+ end
72
+
73
+ it 'shows a warning if there are no resources for the label' do
74
+ send_command('locker label create foobar')
75
+ send_command('locker label show foobar')
76
+ expect(replies.last).to eq('Label foobar has no resources')
77
+ end
78
+
79
+ it 'shows an error if the label does not exist' do
80
+ send_command('locker label show foobar')
81
+ expect(replies.last).to eq('Label foobar does not exist. To create it: "!locker label create foobar"')
82
+ end
83
+ end
84
+
85
+ describe '#label_add' do
86
+ it 'adds a resource to a label if both exist' do
87
+ send_command('locker resource create foo')
88
+ send_command('locker label create bar')
89
+ send_command('locker label add foo to bar')
90
+ expect(replies.last).to eq('Resource foo has been added to bar')
91
+ send_command('locker label show bar')
92
+ expect(replies.last).to eq('Label bar has: foo')
93
+ end
94
+
95
+ it 'adds multiple resources to a label if all exist' do
96
+ send_command('locker resource create foo')
97
+ send_command('locker resource create baz')
98
+ send_command('locker label create bar')
99
+ send_command('locker label add foo to bar')
100
+ send_command('locker label add baz to bar')
101
+ send_command('locker label show bar')
102
+ expect(replies.last).to match(/Label bar has:/)
103
+ expect(replies.last).to match(/foo/)
104
+ expect(replies.last).to match(/baz/)
105
+ end
106
+
107
+ it 'shows an error if the label does not exist' do
108
+ send_command('locker label add foo to bar')
109
+ expect(replies.last).to eq('Label bar does not exist. To create it: "!locker label create bar"')
110
+ end
111
+
112
+ it 'shows an error if the resource does not exist' do
113
+ send_command('locker label create bar')
114
+ send_command('locker label add foo to bar')
115
+ expect(replies.last).to eq('Resource foo does not exist')
116
+ end
117
+ end
118
+
119
+ describe '#label_remove' do
120
+ it 'removes a resource from a label if both exist and are related' do
121
+ send_command('locker resource create foo')
122
+ send_command('locker label create bar')
123
+ send_command('locker label add foo to bar')
124
+ send_command('locker label remove foo from bar')
125
+ send_command('locker label show bar')
126
+ expect(replies.last).to eq('Label bar has no resources')
127
+ end
128
+
129
+ it 'shows an error if they both exist but are not related' do
130
+ send_command('locker resource create foo')
131
+ send_command('locker label create bar')
132
+ send_command('locker label remove foo from bar')
133
+ expect(replies.last).to eq('Label bar does not have Resource foo')
134
+ end
135
+
136
+ it 'shows an error if the label does not exist' do
137
+ send_command('locker label add foo to bar')
138
+ expect(replies.last).to eq('Label bar does not exist. To create it: "!locker label create bar"')
139
+ end
140
+
141
+ it 'shows an error if the resource does not exist' do
142
+ send_command('locker label create bar')
143
+ send_command('locker label add foo to bar')
144
+ expect(replies.last).to eq('Resource foo does not exist')
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::LockerMisc, lita_handler: true do
4
+ before do
5
+ robot.auth.add_user_to_group!(user, :locker_admins)
6
+ end
7
+
8
+ label_examples = ['foobar', 'foo bar', 'foo-bar', 'foo_bar']
9
+ resource_examples = ['foobar', 'foo.bar', 'foo-bar', 'foo_bar']
10
+
11
+ label_examples.each do |l|
12
+ it { is_expected.to route_command("locker status #{l}").to(:status) }
13
+ end
14
+
15
+ resource_examples.each do |r|
16
+ it { is_expected.to route_command("locker status #{r}").to(:status) }
17
+ end
18
+
19
+ it { is_expected.to route_command('locker list @alice').to(:list) }
20
+ it { is_expected.to route_command('locker list Alice').to(:list) }
21
+
22
+ describe '#status' do
23
+ it 'shows the status of a label' do
24
+ send_command('locker resource create bar')
25
+ send_command('locker label create foo')
26
+ send_command('locker label add bar to foo')
27
+ send_command('locker status foo')
28
+ expect(replies.last).to eq('Label: foo, state: unlocked')
29
+ send_command('lock foo')
30
+ send_command('locker status foo')
31
+ expect(replies.last).to eq('Label: foo, state: locked, owner: Test User')
32
+ end
33
+
34
+ it 'shows the status of a resource' do
35
+ send_command('locker resource create bar')
36
+ send_command('locker label create foo')
37
+ send_command('locker label add bar to foo')
38
+ send_command('locker status bar')
39
+ expect(replies.last).to eq('Resource: bar, state: unlocked')
40
+ send_command('lock foo')
41
+ send_command('locker status bar')
42
+ expect(replies.last).to eq('Resource: bar, state: locked')
43
+ end
44
+
45
+ it 'shows an error if nothing exists with that name' do
46
+ send_command('locker status foo')
47
+ expect(replies.last).to eq('Sorry, that does not exist')
48
+ end
49
+ end
50
+
51
+ describe '#user_locks' do
52
+ it 'shows if a user has taken any locks' do
53
+ send_command('locker resource create foobar')
54
+ send_command('locker label create bazbat')
55
+ send_command('locker label add foobar to bazbat')
56
+ alice = Lita::User.create('9001@hipchat', name: 'Alice Alpha', mention_name: 'alice')
57
+ send_command('lock bazbat', as: alice)
58
+ send_command('locker list Alice Alpha')
59
+ expect(replies.last).to eq("Label: bazbat\n")
60
+ end
61
+
62
+ it 'shows if a mention name has taken any locks' do
63
+ send_command('locker resource create foobar')
64
+ send_command('locker label create bazbat')
65
+ send_command('locker label add foobar to bazbat')
66
+ alice = Lita::User.create('9001@hipchat', name: 'Alice Alpha', mention_name: 'alice')
67
+ send_command('lock bazbat', as: alice)
68
+ send_command('locker list @alice')
69
+ expect(replies.last).to eq("Label: bazbat\n")
70
+ end
71
+
72
+ it 'shows an empty set if the user has not taken any locks' do
73
+ send_command('locker resource create foobar')
74
+ send_command('locker label create bazbat')
75
+ send_command('locker label add foobar to bazbat')
76
+ alice = Lita::User.create('9001@hipchat', name: 'Alice', mention_name: 'alice')
77
+ send_command('locker list Alice', as: alice)
78
+ expect(replies.last).to eq('That user has no active locks')
79
+ send_command('lock bazbat', as: alice)
80
+ send_command('unlock bazbat', as: alice)
81
+ send_command('locker list Alice', as: alice)
82
+ expect(replies.last).to eq('That user has no active locks')
83
+ end
84
+
85
+ it 'shows a warning when the user does not exist' do
86
+ send_command('locker list foobar')
87
+ expect(replies.last).to eq('Unknown user')
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::LockerResources, lita_handler: true do
4
+ before do
5
+ robot.auth.add_user_to_group!(user, :locker_admins)
6
+ end
7
+
8
+ resource_examples = ['foobar', 'foo.bar', 'foo-bar', 'foo_bar']
9
+
10
+ resource_examples.each do |r|
11
+ it do
12
+ is_expected.to route_command("locker resource create #{r}").to(:create)
13
+ is_expected.to route_command("locker resource delete #{r}").to(:delete)
14
+ is_expected.to route_command("locker resource show #{r}").to(:show)
15
+ end
16
+ end
17
+
18
+ it { is_expected.to route_command('locker resource list').to(:list) }
19
+
20
+ describe '#resource_list' do
21
+ it 'shows a list of resources if there are any' do
22
+ send_command('locker resource create foobar')
23
+ send_command('locker resource create bazbat')
24
+ 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/)
27
+ end
28
+ end
29
+
30
+ describe '#resource_create' do
31
+ it 'creates a resource with <name>' do
32
+ send_command('locker resource create foobar')
33
+ expect(replies.last).to eq('Resource foobar created')
34
+ end
35
+
36
+ it 'shows a warning when the <name> already exists as a resource' do
37
+ send_command('locker resource create foobar')
38
+ send_command('locker resource create foobar')
39
+ expect(replies.last).to eq('foobar already exists')
40
+ end
41
+
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')
46
+ end
47
+ end
48
+
49
+ describe '#resource_delete' do
50
+ it 'deletes a resource with <name>' do
51
+ send_command('locker resource create foobar')
52
+ send_command('locker resource delete foobar')
53
+ expect(replies.last).to eq('Resource foobar deleted')
54
+ end
55
+
56
+ it 'shows a warning when <name> does not exist' do
57
+ send_command('locker resource delete foobar')
58
+ expect(replies.last).to eq('Resource foobar does not exist')
59
+ end
60
+ end
61
+
62
+ describe '#resource_show' do
63
+ it 'shows the state of a <name> if it exists' do
64
+ send_command('locker resource create foobar')
65
+ send_command('locker resource show foobar')
66
+ expect(replies.last).to eq('Resource: foobar, state: unlocked')
67
+ end
68
+
69
+ it 'shows a warning when <name> does not exist' do
70
+ send_command('locker resource show foobar')
71
+ expect(replies.last).to eq('Resource foobar does not exist')
72
+ end
73
+ end
74
+ end
@@ -1,60 +1,33 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Lita::Handlers::Locker, lita_handler: true do
4
- label_examples = ['foobar', 'foo bar', 'foo-bar', 'foo_bar']
5
- resource_examples = ['foobar', 'foo.bar', 'foo-bar', 'foo_bar']
6
-
7
- label_examples.each do |l|
8
- it { routes("(lock) #{l}").to(:lock) }
9
- it { routes("(unlock) #{l}").to(:unlock) }
10
- it { routes("(release) #{l}").to(:unlock) }
11
-
12
- it { routes("(lock) #{l} #this is a comment").to(:lock) }
13
- it { routes("(unlock) #{l} #this is a comment").to(:unlock) }
14
- it { routes("(release) #{l} #this is a comment").to(:unlock) }
15
-
16
- it { routes_command("lock #{l}").to(:lock) }
17
- it { routes_command("lock #{l} #this is a comment").to(:lock) }
18
- it { routes_command("unlock #{l}").to(:unlock) }
19
- it { routes_command("unlock #{l} #this is a comment").to(:unlock) }
20
- it { routes_command("steal #{l}").to(:steal) }
21
- it { routes_command("steal #{l} #this is a comment").to(:steal) }
22
- end
23
-
24
- label_examples.each do |l|
25
- it { routes_command("locker status #{l}").to(:status) }
26
- end
27
-
28
- resource_examples.each do |r|
29
- it { routes_command("locker status #{r}").to(:status) }
30
- end
31
-
32
- it { routes_command('locker resource list').to(:resource_list) }
33
-
34
- resource_examples.each do |r|
35
- it { routes_command("locker resource create #{r}").to(:resource_create) }
36
- it { routes_command("locker resource delete #{r}").to(:resource_delete) }
37
- it { routes_command("locker resource show #{r}").to(:resource_show) }
4
+ before do
5
+ robot.auth.add_user_to_group!(user, :locker_admins)
38
6
  end
39
7
 
40
- it { routes_command('locker label list').to(:label_list) }
8
+ label_examples = ['foobar', 'foo bar', 'foo-bar', 'foo_bar']
41
9
 
42
10
  label_examples.each do |l|
43
- it { routes_command("locker label create #{l}").to(:label_create) }
44
- it { routes_command("locker label delete #{l}").to(:label_delete) }
45
- it { routes_command("locker label show #{l}").to(:label_show) }
46
- it { routes_command("locker label add resource to #{l}").to(:label_add) }
47
- it { routes_command("locker label remove resource from #{l}").to(:label_remove) }
48
- end
11
+ it do
12
+ is_expected.to route("(lock) #{l}").to(:lock)
13
+ is_expected.to route("(unlock) #{l}").to(:unlock)
14
+ is_expected.to route("(release) #{l}").to(:unlock)
49
15
 
50
- it { routes_http(:get, '/locker/label/foobar').to(:http_label_show) }
51
- it { routes_http(:get, '/locker/resource/foobar').to(:http_resource_show) }
16
+ is_expected.to route("(Lock) #{l}").to(:lock)
17
+ is_expected.to route("(Unlock) #{l}").to(:unlock)
18
+ is_expected.to route("(Release) #{l}").to(:unlock)
52
19
 
53
- before do
54
- allow(Lita::Authorization).to receive(:user_in_group?).with(
55
- user,
56
- :locker_admins
57
- ).and_return(true)
20
+ is_expected.to route("(lock) #{l} #this is a comment").to(:lock)
21
+ is_expected.to route("(unlock) #{l} #this is a comment").to(:unlock)
22
+ is_expected.to route("(release) #{l} #this is a comment").to(:unlock)
23
+
24
+ is_expected.to route_command("lock #{l}").to(:lock)
25
+ is_expected.to route_command("lock #{l} #this is a comment").to(:lock)
26
+ is_expected.to route_command("unlock #{l}").to(:unlock)
27
+ is_expected.to route_command("unlock #{l} #this is a comment").to(:unlock)
28
+ is_expected.to route_command("steal #{l}").to(:steal)
29
+ is_expected.to route_command("steal #{l} #this is a comment").to(:steal)
30
+ end
58
31
  end
59
32
 
60
33
  let(:alice) do
@@ -92,7 +65,7 @@ describe Lita::Handlers::Locker, lita_handler: true do
92
65
  send_command('lock l1', as: alice)
93
66
  send_command('lock l2', as: alice)
94
67
  expect(replies.last).to eq('(failed) Label unable to be locked, ' \
95
- 'blocked on a dependency')
68
+ "blocked on:\nr1 - Alice")
96
69
  end
97
70
 
98
71
  it 'shows a warning when a label is taken by someone else' do
@@ -166,226 +139,30 @@ describe Lita::Handlers::Locker, lita_handler: true do
166
139
  send_command('locker label add foobar to bazbat')
167
140
  send_command('lock bazbat', as: alice)
168
141
  send_command('steal bazbat # with a comment', as: bob)
169
- expect(replies.last).to eq('(successful) bazbat unlocked')
170
- end
171
-
172
- it 'shows an error when a <subject> does not exist' do
173
- send_command('steal foobar')
174
- expect(replies.last).to eq('(failed) Sorry, that does not exist')
175
- end
176
- end
177
-
178
- describe '#status' do
179
- it 'shows the status of a label' do
180
- send_command('locker resource create bar')
181
- send_command('locker label create foo')
182
- send_command('locker label add bar to foo')
183
- send_command('locker status foo')
184
- expect(replies.last).to eq('Label: foo, state: unlocked')
185
- send_command('lock foo')
186
- send_command('locker status foo')
187
- expect(replies.last).to eq('Label: foo, state: locked, owner: Test User')
188
- end
189
-
190
- it 'shows the status of a resource' do
191
- send_command('locker resource create bar')
192
- send_command('locker label create foo')
193
- send_command('locker label add bar to foo')
194
- send_command('locker status bar')
195
- expect(replies.last).to eq('Resource: bar, state: unlocked')
196
- send_command('lock foo')
197
- send_command('locker status bar')
198
- expect(replies.last).to eq('Resource: bar, state: locked')
199
- end
200
-
201
- it 'shows an error if nothing exists with that name' do
202
- send_command('locker status foo')
203
- expect(replies.last).to eq('Sorry, that does not exist')
204
- end
205
- end
206
-
207
- describe '#label_list' do
208
- it 'shows a list of labels if there are any' do
209
- send_command('locker label create foobar')
210
- send_command('locker label create bazbat')
211
- send_command('locker label list')
212
- expect(replies.include?('Label: foobar, state: unlocked')).to eq(true)
213
- expect(replies.include?('Label: bazbat, state: unlocked')).to eq(true)
214
- end
215
- end
216
-
217
- describe '#label_create' do
218
- it 'creates a label with <name>' do
219
- send_command('locker label create foobar')
220
- expect(replies.last).to eq('Label foobar created')
221
- end
222
-
223
- it 'shows a warning when the <name> already exists as a label' do
224
- send_command('locker label create foobar')
225
- send_command('locker label create foobar')
226
- expect(replies.last).to eq('foobar already exists')
227
- end
228
-
229
- it 'shows a warning when the <name> already exists as a resource' do
230
- send_command('locker resource create foobar')
231
- send_command('locker label create foobar')
232
- expect(replies.last).to eq('foobar already exists')
233
- end
234
- end
235
-
236
- describe '#label_delete' do
237
- it 'deletes a label with <name>' do
238
- send_command('locker label create foobar')
239
- send_command('locker label delete foobar')
240
- expect(replies.last).to eq('Label foobar deleted')
241
- end
242
-
243
- it 'shows a warning when <name> does not exist' do
244
- send_command('locker label delete foobar')
245
- expect(replies.last).to eq('Label foobar does not exist. To create ' \
246
- 'it: "!locker label create foobar"')
247
- end
248
- end
249
-
250
- describe '#label_show' do
251
- it 'shows a list of resources for a label if there are any' do
252
- send_command('locker resource create whatever')
253
- send_command('locker label create foobar')
254
- send_command('locker label add whatever to foobar')
255
- send_command('locker label show foobar')
256
- expect(replies.last).to eq('Label foobar has: whatever')
257
- end
258
-
259
- it 'shows a warning if there are no resources for the label' do
260
- send_command('locker label create foobar')
261
- send_command('locker label show foobar')
262
- expect(replies.last).to eq('Label foobar has no resources')
263
- end
264
-
265
- it 'shows an error if the label does not exist' do
266
- send_command('locker label show foobar')
267
- expect(replies.last).to eq('Label foobar does not exist. To create ' \
268
- 'it: "!locker label create foobar"')
269
- end
270
- end
271
-
272
- describe '#label_add' do
273
- it 'adds a resource to a label if both exist' do
274
- send_command('locker resource create foo')
275
- send_command('locker label create bar')
276
- send_command('locker label add foo to bar')
277
- expect(replies.last).to eq('Resource foo has been added to bar')
278
- send_command('locker label show bar')
279
- expect(replies.last).to eq('Label bar has: foo')
280
- end
281
-
282
- it 'adds multiple resources to a label if all exist' do
283
- send_command('locker resource create foo')
284
- send_command('locker resource create baz')
285
- send_command('locker label create bar')
286
- send_command('locker label add foo to bar')
287
- send_command('locker label add baz to bar')
288
- send_command('locker label show bar')
289
- expect(replies.last).to match(/Label bar has:/)
290
- expect(replies.last).to match(/foo/)
291
- expect(replies.last).to match(/baz/)
292
- end
293
-
294
- it 'shows an error if the label does not exist' do
295
- send_command('locker label add foo to bar')
296
- expect(replies.last).to eq('Label bar does not exist. To create ' \
297
- 'it: "!locker label create bar"')
298
- end
299
-
300
- it 'shows an error if the resource does not exist' do
301
- send_command('locker label create bar')
302
- send_command('locker label add foo to bar')
303
- expect(replies.last).to eq('Resource foo does not exist')
304
- end
305
- end
306
-
307
- describe '#label_remove' do
308
- it 'removes a resource from a label if both exist and are related' do
309
- send_command('locker resource create foo')
310
- send_command('locker label create bar')
311
- send_command('locker label add foo to bar')
312
- send_command('locker label remove foo from bar')
313
- send_command('locker label show bar')
314
- expect(replies.last).to eq('Label bar has no resources')
315
- end
316
-
317
- it 'shows an error if they both exist but are not related' do
318
- send_command('locker resource create foo')
319
- send_command('locker label create bar')
320
- send_command('locker label remove foo from bar')
321
- expect(replies.last).to eq('Label bar does not have Resource foo')
322
- end
323
-
324
- it 'shows an error if the label does not exist' do
325
- send_command('locker label add foo to bar')
326
- expect(replies.last).to eq('Label bar does not exist. To create ' \
327
- 'it: "!locker label create bar"')
328
- end
329
-
330
- it 'shows an error if the resource does not exist' do
331
- send_command('locker label create bar')
332
- send_command('locker label add foo to bar')
333
- expect(replies.last).to eq('Resource foo does not exist')
334
- end
335
- end
336
-
337
- describe '#resource_list' do
338
- it 'shows a list of resources if there are any' do
339
- send_command('locker resource create foobar')
340
- send_command('locker resource create bazbat')
341
- send_command('locker resource list')
342
- expect(replies.last).to match(/Resource: foobar, state: unlocked/)
343
- expect(replies.last).to match(/Resource: bazbat, state: unlocked/)
344
- end
345
- end
346
-
347
- describe '#resource_create' do
348
- it 'creates a resource with <name>' do
349
- send_command('locker resource create foobar')
350
- expect(replies.last).to eq('Resource foobar created')
351
- end
352
-
353
- it 'shows a warning when the <name> already exists as a resource' do
354
- send_command('locker resource create foobar')
355
- send_command('locker resource create foobar')
356
- expect(replies.last).to eq('foobar already exists')
357
- end
358
-
359
- it 'shows a warning when the <name> already exists as a label' do
360
- send_command('locker label create foobar')
361
- send_command('locker resource create foobar')
362
- expect(replies.last).to eq('foobar already exists')
142
+ expect(replies.last).to eq('(successful) bazbat stolen from ' \
143
+ 'Alice (@alice)')
363
144
  end
364
- end
365
145
 
366
- describe '#resource_delete' do
367
- it 'deletes a resource with <name>' do
146
+ it 'shows a warning when the label is already unlocked' do
368
147
  send_command('locker resource create foobar')
369
- send_command('locker resource delete foobar')
370
- expect(replies.last).to eq('Resource foobar deleted')
371
- end
372
-
373
- it 'shows a warning when <name> does not exist' do
374
- send_command('locker resource delete foobar')
375
- expect(replies.last).to eq('Resource foobar does not exist')
148
+ send_command('locker label create bazbat')
149
+ send_command('locker label add foobar to bazbat')
150
+ send_command('steal bazbat # with a comment', as: alice)
151
+ expect(replies.last).to eq('bazbat was already unlocked')
376
152
  end
377
- end
378
153
 
379
- describe '#resource_show' do
380
- it 'shows the state of a <name> if it exists' do
154
+ it 'shows a warning when the label is being stolen by the owner' do
381
155
  send_command('locker resource create foobar')
382
- send_command('locker resource show foobar')
383
- expect(replies.last).to eq('Resource: foobar, state: unlocked')
156
+ send_command('locker label create bazbat')
157
+ send_command('locker label add foobar to bazbat')
158
+ send_command('lock bazbat', as: alice)
159
+ send_command('steal bazbat # with a comment', as: alice)
160
+ expect(replies.last).to eq('Why are you stealing the lock from yourself?')
384
161
  end
385
162
 
386
- it 'shows a warning when <name> does not exist' do
387
- send_command('locker resource show foobar')
388
- expect(replies.last).to eq('Resource foobar does not exist')
163
+ it 'shows an error when a <subject> does not exist' do
164
+ send_command('steal foobar')
165
+ expect(replies.last).to eq('(failed) Sorry, that does not exist')
389
166
  end
390
167
  end
391
168
  end