lita-envy 0.1.1 → 0.1.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.
- checksums.yaml +4 -4
- data/lib/lita/handlers/envy.rb +22 -5
- data/lita-envy.gemspec +1 -1
- data/spec/lita/handlers/envy_spec.rb +227 -51
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1771ca4a7139bb295de5a3f34643749b612f5f69
|
4
|
+
data.tar.gz: 7d16778ffb99417dbdcea91d498bb95a2d9f94b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5be321f0ef3ad3df62d7c173164c0c8974c449a8a2eba2581fabccc78345b62138c192e23dfb26db9dded90dbe25ac8e68f2ffcf329173443c202d7fc7de1cc2
|
7
|
+
data.tar.gz: 089233c504f022a389b9d6702fca600327c04dc5d6e452b831db5856ff65511e408a7f64729434611b1d9cc490e75b45f6a752fd2b1f9e611af800fc5ae30ee5
|
data/lib/lita/handlers/envy.rb
CHANGED
@@ -11,7 +11,7 @@ module Lita
|
|
11
11
|
def start_using_environment(response)
|
12
12
|
env_id = response.matches.first.first
|
13
13
|
current_user = redis.hget(['environments', env_id].join(':'), 'user')
|
14
|
-
if current_user.nil?
|
14
|
+
if current_user.nil? || current_user.empty?
|
15
15
|
redis.hset(['environments', env_id].join(':'), 'user', response.user.name)
|
16
16
|
response.reply('ok')
|
17
17
|
elsif current_user == response.user.name
|
@@ -23,8 +23,16 @@ module Lita
|
|
23
23
|
|
24
24
|
def stop_using_environment(response)
|
25
25
|
env_id = response.matches.first.first
|
26
|
-
redis.
|
27
|
-
response.
|
26
|
+
current_user = redis.hget(['environments', env_id].join(':'), 'user')
|
27
|
+
if current_user == response.user.name
|
28
|
+
redis.hset(['environments', env_id].join(':'), 'user', nil)
|
29
|
+
response.reply('ok')
|
30
|
+
elsif current_user.nil? || current_user.empty?
|
31
|
+
response.reply("You are not currently using #{env_id}")
|
32
|
+
else
|
33
|
+
response.reply("You are not currently using #{env_id} (#{current_user} is)")
|
34
|
+
end
|
35
|
+
|
28
36
|
end
|
29
37
|
|
30
38
|
def list_environments(response)
|
@@ -41,8 +49,17 @@ module Lita
|
|
41
49
|
|
42
50
|
def remove_environment(response)
|
43
51
|
env_id = response.matches.first.first
|
44
|
-
redis.
|
45
|
-
response.
|
52
|
+
current_user = redis.hget(['environments', env_id].join(':'), 'user')
|
53
|
+
if current_user == response.user.name
|
54
|
+
response.reply("You are currently using #{env_id}")
|
55
|
+
elsif current_user.nil?
|
56
|
+
response.reply("I do not know about environment #{env_id}")
|
57
|
+
elsif current_user.empty?
|
58
|
+
redis.del(['environments', env_id].join(':'))
|
59
|
+
response.reply('ok')
|
60
|
+
else
|
61
|
+
response.reply("Sorry, #{env_id} is currently in use by #{current_user}")
|
62
|
+
end
|
46
63
|
end
|
47
64
|
|
48
65
|
def wrestle_environment_from_user(response)
|
data/lita-envy.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-envy"
|
3
|
-
spec.version = "0.1.
|
3
|
+
spec.version = "0.1.2"
|
4
4
|
spec.authors = ["Ingo Weiss"]
|
5
5
|
spec.email = ["ingo.weiss@lab49.com"]
|
6
6
|
spec.description = "Mark environments as in use. Mark environments as available. List environments"
|
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Lita::Handlers::Envy, lita_handler: true do
|
4
4
|
|
5
|
-
describe '
|
5
|
+
describe 'Routing' do
|
6
6
|
|
7
7
|
it { is_expected.to route_command("started using env ENV123").to(:start_using_environment) }
|
8
8
|
it { is_expected.to route_command("stopped using env ENV123").to(:stop_using_environment) }
|
@@ -12,63 +12,180 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
12
12
|
|
13
13
|
end
|
14
14
|
|
15
|
-
describe '
|
15
|
+
describe 'User claiming environment' do
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
context "when environment is available" do
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
subject.redis.hset('environments:ENV123', 'user', '')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should mark environment as in use by user" do
|
24
|
+
carl = Lita::User.create(123, name: "Carl")
|
25
|
+
send_command('started using env ENV123', :as => carl)
|
26
|
+
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Carl")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should reply with confirmation" do
|
30
|
+
send_command('started using env ENV123')
|
31
|
+
expect(replies.first).to eq("ok")
|
32
|
+
end
|
22
33
|
|
23
|
-
it "should confirm" do
|
24
|
-
send_command('started using env ENV123')
|
25
|
-
expect(replies.first).to eq("ok")
|
26
34
|
end
|
27
35
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
36
|
+
context "when environment is unknown to bot" do
|
37
|
+
|
38
|
+
before(:each) do
|
39
|
+
subject.redis.del('environments:ENV123')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should mark environment as in use by user" do
|
43
|
+
carl = Lita::User.create(123, name: "Carl")
|
44
|
+
send_command('started using env ENV123', :as => carl)
|
45
|
+
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Carl")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should reply with confirmation" do
|
49
|
+
send_command('started using env ENV123')
|
50
|
+
expect(replies.first).to eq("ok")
|
51
|
+
end
|
52
|
+
|
33
53
|
end
|
34
54
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
55
|
+
context "when environment is in use by another user" do
|
56
|
+
|
57
|
+
before(:each) do
|
58
|
+
subject.redis.hset('environments:ENV123', 'user', 'Alicia')
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should leave the environment untouched" do
|
62
|
+
carl = Lita::User.create(123, name: "Carl")
|
63
|
+
send_command('started using env ENV123', :as => carl)
|
64
|
+
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Alicia")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should reply with notification" do
|
68
|
+
subject.redis.hset('environments:ENV123', 'user', 'Alicia')
|
69
|
+
carl = Lita::User.create(123, name: "Carl")
|
70
|
+
send_command('started using env ENV123', :as => carl)
|
71
|
+
expect(replies.first).to eq("Sorry, ENV123 is currently in use by Alicia")
|
72
|
+
end
|
73
|
+
|
40
74
|
end
|
41
75
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
76
|
+
context "when environment is already in use by user" do
|
77
|
+
|
78
|
+
before(:each) do
|
79
|
+
subject.redis.hset('environments:ENV123', 'user', 'Carl')
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should leave the environment untouched" do
|
83
|
+
carl = Lita::User.create(123, name: "Carl")
|
84
|
+
send_command('started using env ENV123', :as => carl)
|
85
|
+
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Carl")
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should reply with notification" do
|
89
|
+
subject.redis.hset('environments:ENV123', 'user', 'Carl')
|
90
|
+
carl = Lita::User.create(123, name: "Carl")
|
91
|
+
send_command('started using env ENV123', :as => carl)
|
92
|
+
expect(replies.first).to eq("You are already using ENV123")
|
93
|
+
end
|
94
|
+
|
47
95
|
end
|
48
96
|
|
49
97
|
end
|
50
98
|
|
51
|
-
describe '
|
99
|
+
describe 'User releasing environment' do
|
100
|
+
|
101
|
+
context "when environment is in use by user" do
|
102
|
+
|
103
|
+
before(:each) do
|
104
|
+
subject.redis.hset('environments:ENV234', 'user', 'Alicia')
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should mark environment as available" do
|
108
|
+
alicia = Lita::User.create(123, name: "Alicia")
|
109
|
+
send_command('stopped using env ENV234', :as => alicia)
|
110
|
+
expect(subject.redis.hget('environments:ENV234', 'user')).to be_empty
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should reply with confirmation" do
|
114
|
+
alicia = Lita::User.create(123, name: "Alicia")
|
115
|
+
send_command('stopped using env ENV234', :as => alicia)
|
116
|
+
expect(replies.first).to eq("ok")
|
117
|
+
end
|
52
118
|
|
53
|
-
it "should mark environment as available" do
|
54
|
-
subject.redis.hset('environments:ENV123', 'user', 'Alicia')
|
55
|
-
send_command('stopped using env ENV123')
|
56
|
-
expect(subject.redis.hget('environments:ENV123', 'user')).to be_empty
|
57
119
|
end
|
58
120
|
|
59
|
-
|
60
|
-
|
61
|
-
|
121
|
+
context "when environment is in use by another user" do
|
122
|
+
|
123
|
+
before(:each) do
|
124
|
+
subject.redis.hset('environments:ENV234', 'user', 'Carl')
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should leave the environment untouched" do
|
128
|
+
alicia = Lita::User.create(123, name: "Alicia")
|
129
|
+
send_command('stopped using env ENV234', :as => alicia)
|
130
|
+
expect(subject.redis.hget('environments:ENV234', 'user')).to eq('Carl')
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should reply with notification" do
|
134
|
+
alicia = Lita::User.create(123, name: "Alicia")
|
135
|
+
send_command('stopped using env ENV234', :as => alicia)
|
136
|
+
expect(replies.first).to eq("You are not currently using ENV234 (Carl is)")
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
context "when environment is not in use" do
|
142
|
+
|
143
|
+
before(:each) do
|
144
|
+
subject.redis.hset('environments:ENV234', 'user', '')
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should leave the environment untouched" do
|
148
|
+
alicia = Lita::User.create(123, name: "Alicia")
|
149
|
+
send_command('stopped using env ENV234', :as => alicia)
|
150
|
+
expect(subject.redis.hget('environments:ENV234', 'user')).to eq('')
|
151
|
+
end
|
152
|
+
|
153
|
+
it "should reply with notification" do
|
154
|
+
alicia = Lita::User.create(123, name: "Alicia")
|
155
|
+
send_command('stopped using env ENV234', :as => alicia)
|
156
|
+
expect(replies.first).to eq("You are not currently using ENV234")
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
context "when environment is unknown to bot" do
|
162
|
+
|
163
|
+
before(:each) do
|
164
|
+
subject.redis.del('environments:ENV234')
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should leave the environment untouched" do
|
168
|
+
alicia = Lita::User.create(123, name: "Alicia")
|
169
|
+
send_command('stopped using env ENV234', :as => alicia)
|
170
|
+
expect(subject.redis.hget('environments:ENV234', 'user')).to be_nil
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should reply with notification" do
|
174
|
+
alicia = Lita::User.create(123, name: "Alicia")
|
175
|
+
send_command('stopped using env ENV234', :as => alicia)
|
176
|
+
expect(replies.first).to eq("You are not currently using ENV234")
|
177
|
+
end
|
178
|
+
|
62
179
|
end
|
63
180
|
|
64
181
|
end
|
65
182
|
|
66
|
-
describe '
|
183
|
+
describe 'User listing environments' do
|
67
184
|
|
68
185
|
it "should list environments" do
|
69
186
|
subject.redis.hset('environments:ENV123', 'user', 'Alicia')
|
70
187
|
subject.redis.hset('environments:ENV234', 'user', 'Carl')
|
71
|
-
subject.redis.hset('environments:ENV345', 'user',
|
188
|
+
subject.redis.hset('environments:ENV345', 'user', '')
|
72
189
|
send_command('environments')
|
73
190
|
expect(replies.first.split("\n")).to eq([
|
74
191
|
"ENV123 (Alicia)",
|
@@ -79,22 +196,81 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
79
196
|
|
80
197
|
end
|
81
198
|
|
82
|
-
describe '
|
199
|
+
describe 'User removing environment' do
|
200
|
+
|
201
|
+
context "when environment is available" do
|
202
|
+
|
203
|
+
before(:each) do
|
204
|
+
subject.redis.hset('environments:ENV345', 'user', '')
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should remove environments" do
|
208
|
+
send_command('remove env ENV345')
|
209
|
+
expect(subject.redis.keys).to_not include('environments:ENV345')
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should confirm" do
|
213
|
+
send_command('remove env ENV345')
|
214
|
+
expect(replies.first).to eq("ok")
|
215
|
+
end
|
83
216
|
|
84
|
-
it "should remove environments" do
|
85
|
-
subject.redis.hset('environments:ENV123', 'user', 'Alicia')
|
86
|
-
send_command('remove env ENV123')
|
87
|
-
expect(subject.redis.keys).to_not include('environments:ENV123')
|
88
217
|
end
|
89
218
|
|
90
|
-
|
91
|
-
|
92
|
-
|
219
|
+
context "when environment is unknown to bot" do
|
220
|
+
|
221
|
+
before(:each) do
|
222
|
+
subject.redis.del('environments:ENV345')
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should reply with notification" do
|
226
|
+
send_command('remove env ENV345')
|
227
|
+
expect(replies.first).to eq("I do not know about environment ENV345")
|
228
|
+
end
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
context "when environment is in use by another user" do
|
233
|
+
|
234
|
+
before(:each) do
|
235
|
+
subject.redis.hset('environments:ENV345', 'user', 'Carl')
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should leave the environment untouched" do
|
239
|
+
alicia = Lita::User.create(123, name: "Alicia")
|
240
|
+
send_command('remove env ENV345', :as => alicia)
|
241
|
+
expect(subject.redis.hget('environments:ENV345', 'user')).to eq('Carl')
|
242
|
+
end
|
243
|
+
|
244
|
+
it "should reply with notification" do
|
245
|
+
send_command('remove env ENV345')
|
246
|
+
expect(replies.first).to eq("Sorry, ENV345 is currently in use by Carl")
|
247
|
+
end
|
248
|
+
|
249
|
+
end
|
250
|
+
|
251
|
+
context "when environment is in use by user" do
|
252
|
+
|
253
|
+
before(:each) do
|
254
|
+
subject.redis.hset('environments:ENV345', 'user', 'Alicia')
|
255
|
+
end
|
256
|
+
|
257
|
+
it "should leave the environment untouched" do
|
258
|
+
alicia = Lita::User.create(123, name: "Alicia")
|
259
|
+
send_command('remove env ENV345', :as => alicia)
|
260
|
+
expect(subject.redis.hget('environments:ENV345', 'user')).to eq('Alicia')
|
261
|
+
end
|
262
|
+
|
263
|
+
it "should reply with notification" do
|
264
|
+
alicia = Lita::User.create(123, name: "Alicia")
|
265
|
+
send_command('remove env ENV345', :as => alicia)
|
266
|
+
expect(replies.first).to eq("You are currently using ENV345")
|
267
|
+
end
|
268
|
+
|
93
269
|
end
|
94
270
|
|
95
271
|
end
|
96
272
|
|
97
|
-
describe '
|
273
|
+
describe 'User claiming environment from other user' do
|
98
274
|
|
99
275
|
context "when environment is currently in use by specified user" do
|
100
276
|
|
@@ -108,7 +284,7 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
108
284
|
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Carl")
|
109
285
|
end
|
110
286
|
|
111
|
-
it "should
|
287
|
+
it "should reply with confirmation" do
|
112
288
|
send_command('wrestle env ENV123 from Alicia')
|
113
289
|
expect(replies.first).to eq("ok")
|
114
290
|
end
|
@@ -121,13 +297,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
121
297
|
subject.redis.hset('environments:ENV123', 'user', 'Alicia')
|
122
298
|
end
|
123
299
|
|
124
|
-
it "should
|
300
|
+
it "should leave the environment untouched" do
|
125
301
|
carl = Lita::User.create(123, name: "Carl")
|
126
302
|
send_command('wrestle env ENV123 from Ben', :as => carl)
|
127
303
|
expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Alicia")
|
128
304
|
end
|
129
305
|
|
130
|
-
it "should
|
306
|
+
it "should reply with notification" do
|
131
307
|
send_command('wrestle env ENV123 from Ben')
|
132
308
|
expect(replies.first).to eq("Sorry, ENV123 is currently in use by Alicia, not Ben")
|
133
309
|
end
|
@@ -140,13 +316,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
140
316
|
subject.redis.hset('environments:ENV123', 'user', nil)
|
141
317
|
end
|
142
318
|
|
143
|
-
it "should
|
319
|
+
it "should leave the environment untouched" do
|
144
320
|
carl = Lita::User.create(123, name: "Carl")
|
145
321
|
send_command('wrestle env ENV123 from Ben', :as => carl)
|
146
322
|
expect(subject.redis.hget('environments:ENV123', 'user')).to be_empty
|
147
323
|
end
|
148
324
|
|
149
|
-
it "should
|
325
|
+
it "should reply with notification" do
|
150
326
|
send_command('wrestle env ENV123 from Ben')
|
151
327
|
expect(replies.first).to eq("Sorry, ENV123 is not currently in use")
|
152
328
|
end
|
@@ -159,13 +335,13 @@ describe Lita::Handlers::Envy, lita_handler: true do
|
|
159
335
|
subject.redis.hset('environments:ENV123', 'user', 'Carl')
|
160
336
|
end
|
161
337
|
|
162
|
-
it "should
|
338
|
+
it "should leave the environment untouched" do
|
163
339
|
carl = Lita::User.create(123, name: "Carl")
|
164
340
|
send_command('wrestle env ENV123 from Ben', :as => carl)
|
165
341
|
expect(subject.redis.hget('environments:ENV123', 'user')).to eq('Carl')
|
166
342
|
end
|
167
343
|
|
168
|
-
it "should
|
344
|
+
it "should reply with notification" do
|
169
345
|
carl = Lita::User.create(123, name: "Carl")
|
170
346
|
send_command('wrestle env ENV123 from Ben', :as => carl)
|
171
347
|
expect(replies.first).to eq("You are already using ENV123")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-envy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ingo Weiss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|