lita-queue 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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/lita/handlers/queue.rb +9 -5
- data/lita-queue.gemspec +2 -2
- data/spec/lita/handlers/queue_spec.rb +30 -30
- data/spec/spec_helper.rb +29 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c68bea41fdca6b89d3d91c689a4a2f270204a01
|
4
|
+
data.tar.gz: a46a13c18c6624f7190d9151341b0d95054b00b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82cdd8f102c7d4fa791484b7a0cc8efca7686d3d8498cf1be886ba003d96d6db41ea13c2b45b985fe4039cb062b8b86342856442f746a27baa342164eece9b3f
|
7
|
+
data.tar.gz: 3e84ef189225c3f501f1f95287b38e88f24b921395a5aa2f67cd2fabdae4def1047af8387fb35bbcde3bbfb983de6ba9509c32f7a52a9fc312fdc16e403fd0cd
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,13 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
5
5
|
We follow [Keep a Changelog](http://keepachangelog.com/) format.
|
6
6
|
|
7
|
+
## 0.3.0 - 2015-07-19
|
8
|
+
### Modified
|
9
|
+
- Correctly using Lita::Room object
|
10
|
+
* create queues based on room ID
|
11
|
+
* display queue using room name metadata
|
12
|
+
* modified specs to catch this change
|
13
|
+
|
7
14
|
## 0.2.0 - 2015-06-21
|
8
15
|
### Added
|
9
16
|
- Respond to the following additional command:
|
data/lib/lita/handlers/queue.rb
CHANGED
@@ -13,17 +13,19 @@ module Lita
|
|
13
13
|
# API
|
14
14
|
|
15
15
|
def fetch_queue(room)
|
16
|
-
|
16
|
+
raise ArgumentError, 'must be a Lita::Room object' unless room.is_a? Lita::Room
|
17
|
+
|
18
|
+
serialized = redis.get(room.id)
|
17
19
|
|
18
20
|
if serialized
|
19
|
-
|
21
|
+
MultiJson.load(serialized)
|
20
22
|
else
|
21
23
|
[]
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
25
27
|
def store_queue(room, queue)
|
26
|
-
redis.set room, queue
|
28
|
+
redis.set room.id, MultiJson.dump(queue)
|
27
29
|
end
|
28
30
|
|
29
31
|
# Commands
|
@@ -107,14 +109,16 @@ module Lita
|
|
107
109
|
private
|
108
110
|
|
109
111
|
def room_for(response)
|
110
|
-
response.message.source.
|
112
|
+
response.message.source.room_object
|
111
113
|
end
|
112
114
|
|
113
115
|
def display_queue(queue, room)
|
116
|
+
log.debug "displaying info for queue: #{queue.inspect} at #{room.inspect}"
|
117
|
+
|
114
118
|
if queue.empty?
|
115
119
|
"Queue is empty!"
|
116
120
|
else
|
117
|
-
"Queue for #{room}: #{queue}"
|
121
|
+
"Queue for #{room.name}: #{queue}"
|
118
122
|
end
|
119
123
|
end
|
120
124
|
end
|
data/lita-queue.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-queue"
|
3
|
-
spec.version = "0.
|
3
|
+
spec.version = "0.3.0"
|
4
4
|
spec.authors = ["Gabriel Mazetto"]
|
5
5
|
spec.email = ["brodock@gmail.com"]
|
6
6
|
spec.description = "Lita plugin to manage channel specific queue"
|
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
|
17
|
-
spec.add_runtime_dependency "lita", ">= 4.3"
|
17
|
+
spec.add_runtime_dependency "lita", ">= 4.4.3"
|
18
18
|
|
19
19
|
spec.add_development_dependency "bundler", "~> 1.3"
|
20
20
|
spec.add_development_dependency "pry-byebug"
|
@@ -15,24 +15,24 @@ describe Lita::Handlers::Queue, lita_handler: true do
|
|
15
15
|
it { is_expected.to route_command("queue rotate!").to(:queue_rotate) }
|
16
16
|
#it { is_expected.to route_command("queue = [something,here]").to(:queue_recreate) }
|
17
17
|
|
18
|
-
let(:
|
18
|
+
let(:room) { Lita::Room.new(1, {name: 'my-channel'}) }
|
19
19
|
|
20
20
|
# Commands
|
21
21
|
describe "#queue_list" do
|
22
22
|
context "when queue is empty" do
|
23
|
-
before { subject.store_queue(
|
23
|
+
before { subject.store_queue(room, []) }
|
24
24
|
|
25
25
|
it "replies with an empty queue message" do
|
26
|
-
send_command("queue")
|
26
|
+
send_command("queue", from: room)
|
27
27
|
expect(replies.last).to include("Queue is empty")
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
context "when queue has elements" do
|
32
|
-
before { subject.store_queue(
|
32
|
+
before { subject.store_queue(room, [user1.mention_name, user2.mention_name]) }
|
33
33
|
|
34
34
|
it "replies with a list of queue users" do
|
35
|
-
send_command("queue")
|
35
|
+
send_command("queue", from: room)
|
36
36
|
expect(replies.last).to include(user1.mention_name, user2.mention_name)
|
37
37
|
end
|
38
38
|
end
|
@@ -40,39 +40,39 @@ describe Lita::Handlers::Queue, lita_handler: true do
|
|
40
40
|
|
41
41
|
describe "#queue_me" do
|
42
42
|
context "when I'm already queued" do
|
43
|
-
before { subject.store_queue(
|
43
|
+
before { subject.store_queue(room, [user.mention_name]) }
|
44
44
|
|
45
45
|
it "replies with an error message" do
|
46
|
-
send_command("queue me")
|
46
|
+
send_command("queue me", from: room)
|
47
47
|
expect(replies.last).to include("already on queue")
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
context "when I'm not on queue" do
|
52
52
|
it "replies with a confirmation message" do
|
53
|
-
send_command("queue me")
|
53
|
+
send_command("queue me", from: room)
|
54
54
|
expect(replies.last).to include("#{user.name} have been added to queue")
|
55
|
-
expect(subject.fetch_queue(
|
55
|
+
expect(subject.fetch_queue(room)).to include(user.mention_name)
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
describe "#unqueue_me" do
|
61
61
|
context "when I'm already queued" do
|
62
|
-
before { subject.store_queue(
|
62
|
+
before { subject.store_queue(room, [user.mention_name]) }
|
63
63
|
|
64
64
|
it "replies with a confirmation and remove from queue" do
|
65
|
-
send_command("unqueue me")
|
65
|
+
send_command("unqueue me", from: room)
|
66
66
|
expect(replies.last).to include("#{user.name} have been removed from queue")
|
67
|
-
expect(subject.fetch_queue(
|
67
|
+
expect(subject.fetch_queue(room)).not_to include(user.mention_name)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
71
|
context "when I'm not on queue" do
|
72
|
-
before { subject.store_queue(
|
72
|
+
before { subject.store_queue(room, []) }
|
73
73
|
|
74
74
|
it "replies with an error message" do
|
75
|
-
send_command("unqueue me")
|
75
|
+
send_command("unqueue me", from: room)
|
76
76
|
expect(replies.last).to include("not on queue!")
|
77
77
|
end
|
78
78
|
end
|
@@ -81,26 +81,26 @@ describe Lita::Handlers::Queue, lita_handler: true do
|
|
81
81
|
describe "#queue_list_next" do
|
82
82
|
context "when queue is empty" do
|
83
83
|
it "replies with an error message" do
|
84
|
-
send_command("queue next?")
|
84
|
+
send_command("queue next?", from: room)
|
85
85
|
expect(replies.last).to include("Queue is empty")
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
89
89
|
context "when queue has only one element" do
|
90
|
-
before { subject.store_queue(
|
90
|
+
before { subject.store_queue(room, [user1.mention_name]) }
|
91
91
|
|
92
92
|
it "replies listing current user on queue and warning that's the last one" do
|
93
|
-
send_command("queue next?")
|
93
|
+
send_command("queue next?", from: room)
|
94
94
|
expect(replies.last).to include(user1.mention_name)
|
95
95
|
expect(replies.last).to include("is the last one on queue")
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
context "when queue has more than one elements" do
|
100
|
-
before { subject.store_queue(
|
100
|
+
before { subject.store_queue(room, [user1.mention_name, user2.mention_name]) }
|
101
101
|
|
102
102
|
it "replies listing the next one on the queue" do
|
103
|
-
send_command("queue next?")
|
103
|
+
send_command("queue next?", from: room)
|
104
104
|
expect(replies.last).to include(user2.mention_name)
|
105
105
|
end
|
106
106
|
end
|
@@ -109,29 +109,29 @@ describe Lita::Handlers::Queue, lita_handler: true do
|
|
109
109
|
describe "#queue_change_to_next" do
|
110
110
|
context "when queue is empty" do
|
111
111
|
it "replies with an error message" do
|
112
|
-
send_command("queue next!")
|
112
|
+
send_command("queue next!", from: room)
|
113
113
|
expect(replies.last).to include("Queue is empty")
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
117
|
context "when queue has enough elements" do
|
118
118
|
let(:queue) { [user1.mention_name, user2.mention_name] }
|
119
|
-
before { subject.store_queue(
|
119
|
+
before { subject.store_queue(room, queue) }
|
120
120
|
|
121
121
|
it "remove the first element from the queue" do
|
122
|
-
send_command("queue next!")
|
123
|
-
expect(subject.fetch_queue(
|
122
|
+
send_command("queue next!", from: room)
|
123
|
+
expect(subject.fetch_queue(room)).to eq([user2.mention_name])
|
124
124
|
end
|
125
125
|
|
126
126
|
it "replies informing who was been removed and who is next" do
|
127
|
-
send_command("queue next!")
|
127
|
+
send_command("queue next!", from: room)
|
128
128
|
expect(replies.first).to include("#{user1.mention_name} have been removed from queue")
|
129
129
|
expect(replies[1]).to include("#{user2.mention_name} is the next")
|
130
130
|
|
131
131
|
end
|
132
132
|
|
133
133
|
it "informs the new queue after execution" do
|
134
|
-
send_command("queue next!")
|
134
|
+
send_command("queue next!", from: room)
|
135
135
|
expect(replies.last).to include(user2.mention_name)
|
136
136
|
expect(replies.last).not_to include(user1.mention_name)
|
137
137
|
end
|
@@ -140,7 +140,7 @@ describe Lita::Handlers::Queue, lita_handler: true do
|
|
140
140
|
let(:queue) { [user2.mention_name] }
|
141
141
|
|
142
142
|
it "replies with a notification message when removing the last element from queue" do
|
143
|
-
send_command("queue next!")
|
143
|
+
send_command("queue next!", from: room)
|
144
144
|
expect(replies.first).to include("#{user2.mention_name} have been removed from queue")
|
145
145
|
expect(replies.last).to include("Queue is empty")
|
146
146
|
end
|
@@ -150,15 +150,15 @@ describe Lita::Handlers::Queue, lita_handler: true do
|
|
150
150
|
|
151
151
|
describe "#queue_rotate" do
|
152
152
|
context "when queue has enough elements" do
|
153
|
-
before { subject.store_queue(
|
153
|
+
before { subject.store_queue(room, [user1.mention_name, user2.mention_name, user3.mention_name]) }
|
154
154
|
|
155
155
|
it "removes the first element and add to the end" do
|
156
|
-
send_command("queue rotate!")
|
157
|
-
expect(subject.fetch_queue(
|
156
|
+
send_command("queue rotate!", from: room)
|
157
|
+
expect(subject.fetch_queue(room)).to eq([user2.mention_name, user3.mention_name, user1.mention_name])
|
158
158
|
end
|
159
159
|
|
160
160
|
it "replies mentioning the next user on queue and notifing the rotated one" do
|
161
|
-
send_command("queue rotate!")
|
161
|
+
send_command("queue rotate!", from: room)
|
162
162
|
expect(replies.first).to include("#{user1.mention_name} has been moved to the end of the queue")
|
163
163
|
expect(replies[1]).to include("#{user2.mention_name} is the next")
|
164
164
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "pry"
|
1
2
|
require "simplecov"
|
2
3
|
require "coveralls"
|
3
4
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
@@ -12,3 +13,31 @@ require "lita/rspec"
|
|
12
13
|
# A compatibility mode is provided for older plugins upgrading from Lita 3. Since this plugin
|
13
14
|
# was generated with Lita 4, the compatibility mode should be left disabled.
|
14
15
|
Lita.version_3_compatibility_mode = false
|
16
|
+
|
17
|
+
# Backport / Monkey Patch Lita Spec Handler Helper until a new version > 4.4.3 is released.
|
18
|
+
# More info here: https://github.com/jimmycuadra/lita/pull/129
|
19
|
+
module Lita
|
20
|
+
module RSpec
|
21
|
+
module Handler
|
22
|
+
# Sends a message to the robot.
|
23
|
+
# @param body [String] The message to send.
|
24
|
+
# @param as [Lita::User] The user sending the message.
|
25
|
+
# @param as [Lita::Room] The room where the message is received from.
|
26
|
+
# @return [void]
|
27
|
+
def send_message(body, as: user, from: nil)
|
28
|
+
message = Message.new(robot, body, Source.new(user: as, room: from))
|
29
|
+
|
30
|
+
robot.receive(message)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Sends a "command" message to the robot.
|
34
|
+
# @param body [String] The message to send.
|
35
|
+
# @param as [Lita::User] The user sending the message.
|
36
|
+
# @param as [Lita::Room] The room where the message is received from.
|
37
|
+
# @return [void]
|
38
|
+
def send_command(body, as: user, from: nil)
|
39
|
+
send_message("#{robot.mention_name}: #{body}", as: as, from: from)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-queue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Mazetto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 4.4.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 4.4.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -165,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
165
|
version: '0'
|
166
166
|
requirements: []
|
167
167
|
rubyforge_project:
|
168
|
-
rubygems_version: 2.4.
|
168
|
+
rubygems_version: 2.4.8
|
169
169
|
signing_key:
|
170
170
|
specification_version: 4
|
171
171
|
summary: Lita plugin to manage channel specific queue
|