lita-totems 0.2.0 → 0.3.0

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: fcebd655b6abfd2ae0fffb0e2477455a847b24fd
4
- data.tar.gz: 078b012853bfc626e605eb8d7f20c128b99e9187
3
+ metadata.gz: 4c08d38dab66a89133a326195a7a3284c383e95e
4
+ data.tar.gz: 67e50f44222b2e993aec07811c178a868cf31a24
5
5
  SHA512:
6
- metadata.gz: 53da90a7de19a6d7143b77dc7ab7716cb6749b8acc130210b4f86f3a3463b0541637b5c4d43a459b02539a890be51f2308825774bf8a004dd72f909404beba1f
7
- data.tar.gz: 2d4c22bc113044b5e75d4a4df7f2b97681a44c737d032dd7f383cc0d5cc6c8a73e48ca5cc34a7c52cd129ece6d430afabfee9e04ef42360225745d72444cbabb
6
+ metadata.gz: 80179d6ebc67dd3ff465b7fb0636b9cab74665b0ca9d8ce564b6eb183c06cb5cefbca6d62039dd1baa4259366e7b21f883527543395bc5b5f91ee60af3c3179c
7
+ data.tar.gz: b6fcd10085bdc4fc04ceceb5faf7c2bd2ddd5a8cbab5b6c206d923e23629a11182fd583b446cd9b19627e0c801113092df467b33c019caa5fd377520a9ff52aa
@@ -10,13 +10,14 @@ module Lita
10
10
  %r{
11
11
  ^totems?\s+
12
12
  (#{action_capture_group})\s+
13
- (?<totem>\w+)
13
+ (?<totem>\w+)\s*
14
+ (?<message>.*)?
14
15
  }x
15
16
  end
16
17
 
17
18
  route(route_regex("add|join|take|queue"), :add,
18
19
  help: {
19
- 'totems add TOTEM' => "Adds yourself to the TOTEM queue, or assigns yourself to the TOTEM if it's unassigned"
20
+ 'totems add TOTEM <MESSAGE>' => "Adds yourself to the TOTEM queue, or assigns yourself to the TOTEM if it's unassigned. Includes optional MESSAGE."
20
21
  })
21
22
 
22
23
  route(
@@ -108,9 +109,12 @@ module Lita
108
109
  return
109
110
  end
110
111
 
112
+ message = response.match_data[:message]
113
+
111
114
  token_acquired = false
112
115
  queue_size = nil
113
116
  Redis::Semaphore.new("totem/#{totem}", redis: redis).lock do
117
+ redis.hset("totem/#{totem}/message", user_id, message) if message && message != ""
114
118
  if redis.llen("totem/#{totem}/list") == 0 && redis.get("totem/#{totem}/owning_user_id").nil?
115
119
  # take it:
116
120
  token_acquired = true
@@ -176,6 +180,7 @@ module Lita
176
180
 
177
181
  redis.srem("user/#{past_owning_user_id}/totems", totem)
178
182
  redis.hdel("totem/#{totem}/waiting_since", past_owning_user_id)
183
+ redis.hdel("totem/#{totem}/message", past_owning_user_id)
179
184
  robot.send_messages(Lita::Source.new(user: Lita::User.find_by_id(past_owning_user_id)), %{You have been kicked from totem "#{totem}".})
180
185
  next_user_id = redis.lpop("totem/#{totem}/list")
181
186
  if next_user_id
@@ -215,10 +220,13 @@ module Lita
215
220
  first_id = redis.get("totem/#{totem}/owning_user_id")
216
221
  if first_id
217
222
  waiting_since_hash = redis.hgetall("totem/#{totem}/waiting_since")
223
+ message_hash = redis.hgetall("totem/#{totem}/message")
218
224
  str += "#{prefix}1. #{users_cache[first_id].name} (held for #{waiting_duration(waiting_since_hash[first_id])})\n"
225
+ str += "\s\s\s\s#{message_hash[first_id]}\n" if message_hash[first_id]
219
226
  rest = redis.lrange("totem/#{totem}/list", 0, -1)
220
227
  rest.each_with_index do |user_id, index|
221
228
  str += "#{prefix}#{index+2}. #{users_cache[user_id].name} (waiting for #{waiting_duration(waiting_since_hash[user_id])})\n"
229
+ str += "\s\s\s\s#{message_hash[user_id]}\n" if message_hash[user_id]
222
230
  end
223
231
  end
224
232
  str
@@ -231,6 +239,7 @@ module Lita
231
239
  def yield_totem(totem, user_id, response)
232
240
  redis.srem("user/#{user_id}/totems", totem)
233
241
  redis.hdel("totem/#{totem}/waiting_since", user_id)
242
+ redis.hdel("totem/#{totem}/message", user_id)
234
243
  next_user_id = redis.lpop("totem/#{totem}/list")
235
244
  if next_user_id
236
245
  redis.set("totem/#{totem}/owning_user_id", next_user_id)
data/lita-totems.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-totems"
3
- spec.version = "0.2.0"
3
+ spec.version = "0.3.0"
4
4
  spec.authors = ["Charles Finkel", "Vijay Ramesh"]
5
5
  spec.email = ["cf@dropbox.com", "vijay@change.org"]
6
6
  spec.description = %q{Totems handler for Lita)}
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
14
14
  spec.require_paths = ["lib"]
15
15
 
16
- spec.add_runtime_dependency "lita", ">= 2.4"
16
+ spec.add_runtime_dependency "lita", ">= 4.0"
17
17
  spec.add_runtime_dependency "chronic_duration"
18
18
  spec.add_runtime_dependency "redis-semaphore"
19
19
 
@@ -1,16 +1,18 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Lita::Handlers::Totems, lita_handler: true do
4
- it { routes("totems add foo").to(:add) }
5
- it { routes("totem add foo").to(:add) }
6
- it { routes("totem join foo").to(:add) }
7
- it { doesnt_route("totems add ").to(:add) }
8
- it { doesnt_route("tote add foo").to(:add) }
9
- it { routes("totems kick foo").to(:kick) }
10
- it { routes("totems kick foo bob").to(:kick) }
11
- it { routes("totems").to(:info) }
12
- it { routes("totems info").to(:info) }
13
- it { routes("totems info chicken").to(:info) }
4
+ it { is_expected.to route("totems add foo").to(:add) }
5
+ it { is_expected.to route("totem add foo").to(:add) }
6
+ it { is_expected.to route("totem join foo").to(:add) }
7
+ it { is_expected.to route("totems add foo message").to(:add) }
8
+ it { is_expected.not_to route("totems add ").to(:add) }
9
+ it { is_expected.not_to route("tote add foo").to(:add) }
10
+ it { is_expected.to route("totems kick foo").to(:kick) }
11
+ it { is_expected.to route("totems kick foo bob").to(:kick) }
12
+ it { is_expected.to route("totems").to(:info) }
13
+ it { is_expected.to route("totems info").to(:info) }
14
+ it { is_expected.to route("totems info chicken").to(:info) }
15
+
14
16
 
15
17
  let(:totem_creator) { Class.new do
16
18
  def initialize
@@ -121,6 +123,25 @@ describe Lita::Handlers::Totems, lita_handler: true do
121
123
  end
122
124
  end
123
125
 
126
+ context "with a message" do
127
+ before do
128
+ Timecop.freeze("2014-03-01 12:00:00") do
129
+ send_message("totems add chicken message", as: carl)
130
+ send_message("totems add chicken other message", as: another_user)
131
+ end
132
+ end
133
+ it "includes the message in the totems' info" do
134
+ Timecop.freeze("2014-03-01 13:00:00") do
135
+ send_message("totems info chicken")
136
+ expect(replies.last).to eq <<-END
137
+ 1. Carl (held for 1h)
138
+ message
139
+ 2. person_1 (waiting for 1h)
140
+ other message
141
+ END
142
+ end
143
+ end
144
+ end
124
145
  end
125
146
 
126
147
  context "when the totem doesn't exist" do
@@ -152,26 +173,28 @@ describe Lita::Handlers::Totems, lita_handler: true do
152
173
  end
153
174
  end
154
175
  it "yields that totem, gives to the next person in line" do
155
- expect(robot).to receive(:send_messages) do |target, message|
156
- expect(target.user.id).to eq(another_user.id)
157
- expect(message).to eq(%{You are now in possession of totem "chicken."})
176
+ expect(robot).to receive(:send_messages).twice do |target, message|
177
+ expect([another_user.id, carl.id]).to include(target.user.id)
178
+ if target.user.id == another_user.id
179
+ expect(message).to eq(%{You are now in possession of totem "chicken."})
180
+ elsif target.user.id == carl.id
181
+ expect(message).to eq("You have yielded the totem to #{another_user.name}.")
182
+ end
158
183
  end
159
184
  send_message("totems yield", as: carl)
160
- # todo: check for message to other user
161
- expect(replies.last).to eq("You have yielded the totem to #{another_user.name}.")
162
185
  end
163
186
  it "updates the waiting since value for the new holder" do
164
187
  Timecop.freeze("2014-03-01 13:00:00") do
165
188
  send_message("totems info chicken")
166
189
  expect(replies.last).to eq <<-END
167
190
  1. Carl (held for 2h)
168
- 2. Test User (waiting for 1h)
191
+ 2. person_1 (waiting for 1h)
169
192
  3. person_2 (waiting for 1h)
170
193
  END
171
194
  send_message("totems yield", as: carl)
172
195
  send_message("totems info chicken")
173
196
  expect(replies.last).to eq <<-END
174
- 1. Test User (held for 0s)
197
+ 1. person_1 (held for 0s)
175
198
  2. person_2 (waiting for 1h)
176
199
  END
177
200
  end
@@ -240,7 +263,7 @@ describe Lita::Handlers::Totems, lita_handler: true do
240
263
  send_message("totems yield chicken", as: carl)
241
264
  expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.})
242
265
  send_message("totems info chicken")
243
- expect(replies.last).to eq("1. Test User (held for 1h)\n")
266
+ expect(replies.last).to eq("1. person_1 (held for 1h)\n")
244
267
  end
245
268
  end
246
269
  end
@@ -251,7 +274,7 @@ describe Lita::Handlers::Totems, lita_handler: true do
251
274
  send_message("totems yield", as: carl)
252
275
  expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.})
253
276
  send_message("totems info chicken")
254
- expect(replies.last).to eq("1. Test User (held for 1h)\n")
277
+ expect(replies.last).to eq("1. person_1 (held for 1h)\n")
255
278
  end
256
279
  end
257
280
  end
@@ -274,7 +297,7 @@ describe Lita::Handlers::Totems, lita_handler: true do
274
297
  send_message("totems yield chicken", as: carl)
275
298
  expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.})
276
299
  send_message("totems info chicken")
277
- expect(replies.last).to eq("1. Test User (held for 1h)\n2. person_2 (waiting for 1h)\n")
300
+ expect(replies.last).to eq("1. person_1 (held for 1h)\n2. person_2 (waiting for 1h)\n")
278
301
  end
279
302
  end
280
303
  end
@@ -306,7 +329,7 @@ describe Lita::Handlers::Totems, lita_handler: true do
306
329
  send_message("totems yield chicken", as: carl)
307
330
  expect(replies.last).to eq(%{You are no longer in line for the "chicken" totem.})
308
331
  send_message("totems info chicken")
309
- expect(replies.last).to eq("1. Test User (held for 1h)\n2. person_2 (waiting for 1h)\n")
332
+ expect(replies.last).to eq("1. person_1 (held for 1h)\n2. person_2 (waiting for 1h)\n")
310
333
  end
311
334
  end
312
335
  end
@@ -333,16 +356,16 @@ describe Lita::Handlers::Totems, lita_handler: true do
333
356
  send_message("totems add chicken", as: another_user)
334
357
  send_message("totems add chicken", as: carl)
335
358
  end
336
- it "should notify that user that she has been kicked" do
337
- expect(robot).to receive(:send_messages) do |target, message|
338
- expect(target.user.id).to eq(another_user.id)
339
- expect(message).to eq(%{You have been kicked from totem "chicken".})
340
- end
341
- send_message("totems kick chicken")
342
- end
343
- it "should notify next user in line that she now has the totem" do
344
- send_message("totems kick chicken")
345
- expect(replies.last).to eq(%{You are now in possession of totem "chicken".})
359
+ it "should notify that user that she has been kicked, and notify the next user she now has the totem" do
360
+ expect(robot).to receive(:send_messages).twice do |target, message|
361
+ expect([another_user.id, carl.id]).to include(target.user.id)
362
+ if target.user.id == carl.id
363
+ expect(message).to eq(%{You are now in possession of totem "chicken".})
364
+ elsif target.user.id == another_user.id
365
+ expect(message).to eq(%{You have been kicked from totem "chicken".})
366
+ end
367
+ end
368
+ send_message("totems kick chicken", as: carl)
346
369
  end
347
370
  end
348
371
 
@@ -351,13 +374,16 @@ describe Lita::Handlers::Totems, lita_handler: true do
351
374
  send_message("totems add chicken", as: carl)
352
375
  end
353
376
  it "should notify that user that she has been kicked and clear the owning_user_id" do
354
- expect(robot).to receive(:send_messages) do |target, message|
355
- expect(target.user.id).to eq(carl.id)
356
- expect(message).to eq(%{You have been kicked from totem "chicken".})
377
+ expect(robot).to receive(:send_messages).twice do |target, message|
378
+ expect([another_user.id, carl.id]).to include(target.user.id)
379
+ if target.user.id == carl.id
380
+ expect(message).to eq(%{You have been kicked from totem "chicken".})
381
+ elsif target.user.id == another_user.id
382
+ expect(message).to eq("")
383
+ end
357
384
  end
358
385
  send_message("totems kick chicken")
359
386
  send_message("totems info chicken")
360
- expect(replies.last).to eq ""
361
387
  end
362
388
  end
363
389
 
@@ -388,7 +414,7 @@ describe Lita::Handlers::Totems, lita_handler: true do
388
414
  send_message("totems info chicken")
389
415
  expect(replies.last).to eq <<-END
390
416
  1. Carl (held for 1h)
391
- 2. Test User (waiting for 1h)
417
+ 2. person_1 (waiting for 1h)
392
418
  3. person_2 (waiting for 1h)
393
419
  END
394
420
  end
@@ -402,7 +428,7 @@ describe Lita::Handlers::Totems, lita_handler: true do
402
428
  expect(replies.last).to include <<-END
403
429
  - chicken
404
430
  1. Carl (held for 1d 1h)
405
- 2. Test User (waiting for 1d 1h)
431
+ 2. person_1 (waiting for 1d 1h)
406
432
  3. person_2 (waiting for 1d 1h)
407
433
  END
408
434
  expect(replies.last).to include <<-END
data/spec/spec_helper.rb CHANGED
@@ -9,3 +9,4 @@ SimpleCov.start { add_filter "/spec/" }
9
9
 
10
10
  require "lita-totems"
11
11
  require "lita/rspec"
12
+ Lita.version_3_compatibility_mode = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-totems
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Finkel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-07 00:00:00.000000000 Z
12
+ date: 2015-09-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: lita
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '2.4'
20
+ version: '4.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '2.4'
27
+ version: '4.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: chronic_duration
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  version: '0'
177
177
  requirements: []
178
178
  rubyforge_project:
179
- rubygems_version: 2.2.2
179
+ rubygems_version: 2.4.5
180
180
  signing_key:
181
181
  specification_version: 4
182
182
  summary: Adds support to Lita for Totems