lita-envy 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fefb7d9332f5bba20cfcf815f152d9c08543d13e
4
- data.tar.gz: 79bb292a9a52240e40f50a213a867a95680df83a
3
+ metadata.gz: 1771ca4a7139bb295de5a3f34643749b612f5f69
4
+ data.tar.gz: 7d16778ffb99417dbdcea91d498bb95a2d9f94b7
5
5
  SHA512:
6
- metadata.gz: 9ff2ddd4e7d3eff8bb6b905cbecd05a34dcb877d7a880dd4d427070ae4f8de869689ff74c7a5933131d58a566887009dab7ae3640973d2bb07f119ad8a6d2b6d
7
- data.tar.gz: bea1f158534a2d257cd8ede909fb9d4b76e332b8b37ddef3639a995c8e9949dcef4aca1599cc684b51ccd525b2a7f843ca9ccb0ef3ea785e74eb278ba32dcadf
6
+ metadata.gz: 5be321f0ef3ad3df62d7c173164c0c8974c449a8a2eba2581fabccc78345b62138c192e23dfb26db9dded90dbe25ac8e68f2ffcf329173443c202d7fc7de1cc2
7
+ data.tar.gz: 089233c504f022a389b9d6702fca600327c04dc5d6e452b831db5856ff65511e408a7f64729434611b1d9cc490e75b45f6a752fd2b1f9e611af800fc5ae30ee5
@@ -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.hset(['environments', env_id].join(':'), 'user', nil)
27
- response.reply('ok')
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.del(['environments', env_id].join(':'))
45
- response.reply('ok')
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)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-envy"
3
- spec.version = "0.1.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 'routing' do
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 'start using environment' do
15
+ describe 'User claiming environment' do
16
16
 
17
- it "should mark environment as in use" do
18
- carl = Lita::User.create(123, name: "Carl")
19
- send_command('started using env ENV123', :as => carl)
20
- expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Carl")
21
- end
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
- it "should not change the user if the environment is already in use" do
29
- subject.redis.hset('environments:ENV123', 'user', 'Alicia')
30
- carl = Lita::User.create(123, name: "Carl")
31
- send_command('started using env ENV123', :as => carl)
32
- expect(subject.redis.hget('environments:ENV123', 'user')).to eq("Alicia")
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
- it "should notify the user if the environment is already in use" do
36
- subject.redis.hset('environments:ENV123', 'user', 'Alicia')
37
- carl = Lita::User.create(123, name: "Carl")
38
- send_command('started using env ENV123', :as => carl)
39
- expect(replies.first).to eq("Sorry, ENV123 is currently in use by Alicia")
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
- it "should notify the user if the environment is already marked as in use by user" do
43
- subject.redis.hset('environments:ENV123', 'user', 'Carl')
44
- carl = Lita::User.create(123, name: "Carl")
45
- send_command('started using env ENV123', :as => carl)
46
- expect(replies.first).to eq("You are already using ENV123")
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 'stop using environment' do
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
- it "should confirm" do
60
- send_command('stopped using env ENV123')
61
- expect(replies.first).to eq("ok")
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 'list environments' do
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', nil)
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 'remove environment' do
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
- it "should confirm" do
91
- send_command('remove env ENV123')
92
- expect(replies.first).to eq("ok")
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 'wrestle environment from user' do
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 confirm" do
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 not mark environment" do
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 notify the user" do
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 not mark environment" do
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 notify the user" do
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 not mark environment" do
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 notify the user" do
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.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-01 00:00:00.000000000 Z
11
+ date: 2016-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita