lita-poll 1.0.1 → 1.0.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/pollHandler.rb +4 -4
- data/lita-poll.gemspec +2 -2
- data/spec/lita/handlers/poll_spec.rb +137 -1
- data/spec/spec_helper.rb +2 -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: a841e0cca4684cbda447fbda0c3d5160c8194c38
|
4
|
+
data.tar.gz: 350e0171517ccebd1dab8fff1dfdfff676da9fb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc9eeff602562d8f6b9d2e97e673d106af10c977290659de47e8f8e75838e7b6ec18bf4956faa1d48b2af76928bd35e15cd867d1827edb837617ef9b4e455d4c
|
7
|
+
data.tar.gz: 153ec113bf1958ffec3744e03e7ce348369a90301dbcbc802ba4582597a23fcfdf13993ed467e4af335760b42120ba48dcfc974be9e890fdd8723a8c1646a1cd
|
@@ -68,7 +68,7 @@ module Lita
|
|
68
68
|
poll = Poll.json_create(JSON.parse(poll))
|
69
69
|
idx = 0
|
70
70
|
response.reply(t("replies.info.header", poll_topic: poll.topic))
|
71
|
-
every(
|
71
|
+
every(0.5) do |timer|
|
72
72
|
if idx >= poll.options.length
|
73
73
|
timer.stop
|
74
74
|
else
|
@@ -92,7 +92,7 @@ module Lita
|
|
92
92
|
response.reply(t("replies.general.poll_not_found", id: id))
|
93
93
|
else
|
94
94
|
poll = Poll.json_create(JSON.parse(poll))
|
95
|
-
if poll.valid_vote(optNum)
|
95
|
+
if poll.valid_vote?(optNum)
|
96
96
|
poll.vote(response.user, optNum)
|
97
97
|
redis.set(poll.id, poll.to_json)
|
98
98
|
response.reply_privately(t(
|
@@ -123,7 +123,7 @@ module Lita
|
|
123
123
|
|
124
124
|
idx = 0
|
125
125
|
response.reply(t("replies.tally.header"))
|
126
|
-
every(
|
126
|
+
every(0.5) do |timer|
|
127
127
|
if idx >= poll.options.length
|
128
128
|
timer.stop
|
129
129
|
else
|
@@ -148,4 +148,4 @@ module Lita
|
|
148
148
|
|
149
149
|
Lita.register_handler(PollHandler)
|
150
150
|
end
|
151
|
-
end
|
151
|
+
end
|
data/lita-poll.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-poll"
|
3
|
-
spec.version = "1.0.
|
3
|
+
spec.version = "1.0.2"
|
4
4
|
spec.authors = ["Michael Chua"]
|
5
5
|
spec.email = ["chua.mbt@gmail.com"]
|
6
6
|
spec.summary = %q{Plugin that enables polling functionality for a lita bot.}
|
@@ -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", ">=
|
16
|
+
spec.add_runtime_dependency "lita", ">= 4.2.1"
|
17
17
|
|
18
18
|
spec.add_development_dependency "bundler", "~> 1.3"
|
19
19
|
spec.add_development_dependency "rake"
|
@@ -1,4 +1,140 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe Lita::Handlers::
|
3
|
+
describe Lita::Handlers::PollHandler, lita_handler: true do
|
4
|
+
ph = Lita::Handlers::PollHandler
|
5
|
+
topics = ['Topic1', 'Topic2']
|
6
|
+
options = ['Option1', 'Option2', 'Option3']
|
7
|
+
topic1Id = Poll.new(topics.first).id
|
8
|
+
|
9
|
+
let(:poll_admin) do
|
10
|
+
user = Lita::User.create(1, name: "Poll Admin")
|
11
|
+
Lita::Authorization.new(registry.config).add_user_to_group!(user, :poll_admins)
|
12
|
+
user
|
13
|
+
end
|
14
|
+
let(:poll_user1) { Lita::User.create(2, name: "Poll User1") }
|
15
|
+
let(:poll_user2) { Lita::User.create(3, name: "Poll User2") }
|
16
|
+
|
17
|
+
it { is_expected.to route_command("poll list").to(:list) }
|
18
|
+
topics.map { |topic|
|
19
|
+
poll = Poll.new(topic)
|
20
|
+
it { is_expected.to route_command("poll make "+topic).to(:make) }
|
21
|
+
it { is_expected.to route_command("poll option "+poll.id+" Option 1").to(:option) }
|
22
|
+
it { is_expected.to route_command("poll info "+poll.id).to(:info) }
|
23
|
+
it { is_expected.to route_command("poll vote "+poll.id+" 1").to(:vote) }
|
24
|
+
it { is_expected.to route_command("poll tally "+poll.id).to(:tally) }
|
25
|
+
it { is_expected.not_to route_command("poll complete "+poll.id).to(:complete) }
|
26
|
+
it { is_expected.to route_command("poll complete "+poll.id).with_authorization_for(:poll_admins).to(:complete) }
|
27
|
+
|
28
|
+
}
|
29
|
+
it { is_expected.to route_command("poll clear").with_authorization_for(:poll_admins).to(:clear) }
|
30
|
+
it { is_expected.not_to route_command("poll clear").to(:clear) }
|
31
|
+
|
32
|
+
describe "polling for users" do
|
33
|
+
it "no polls" do
|
34
|
+
send_command('poll list', as: poll_user1)
|
35
|
+
expect(replies.last).to eq(ph::translate("replies.list.no_polls"))
|
36
|
+
end
|
37
|
+
|
38
|
+
it "invalid poll" do
|
39
|
+
dummy_topic = 'Dummy'
|
40
|
+
dummy_poll = Poll.new(dummy_topic)
|
41
|
+
send_command('poll option '+dummy_poll.id+' DummyOption', as: poll_user1)
|
42
|
+
send_command('poll vote '+dummy_poll.id+' 1', as: poll_user1)
|
43
|
+
send_command('poll info '+dummy_poll.id, as: poll_user1)
|
44
|
+
send_command('poll tally '+dummy_poll.id, as: poll_user1)
|
45
|
+
replies.map { |reply| expect(reply).to eq(ph::translate("replies.general.poll_not_found", id: dummy_poll.id))
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
it "make and use polls" do
|
50
|
+
# make
|
51
|
+
topics.map { |topic|
|
52
|
+
poll = Poll.new(topic)
|
53
|
+
send_command('poll make '+topic, as: poll_user1)
|
54
|
+
success = ph::translate("replies.make.success", poll_id: poll.id, poll_topic: poll.topic)
|
55
|
+
expect(replies.last).to eq(success)
|
56
|
+
}
|
57
|
+
# list
|
58
|
+
send_command('poll list', as: poll_user2)
|
59
|
+
list_reply = replies.last(topics.length+1)
|
60
|
+
expect(list_reply.first).to eq(ph::translate("replies.list.header"))
|
61
|
+
topics.map { |topic, reply|
|
62
|
+
poll = Poll.new(topic)
|
63
|
+
success = ph::translate("replies.list.poll", poll_id: poll.id, poll_topic: poll.topic)
|
64
|
+
expect(list_reply.drop(1)).to include(success)
|
65
|
+
}
|
66
|
+
# add options
|
67
|
+
options.map { |option|
|
68
|
+
topic = topics.first
|
69
|
+
poll = Poll.new(topic)
|
70
|
+
send_command('poll option '+poll.id+' '+option, as: poll_user1)
|
71
|
+
success = ph::translate("replies.option.success", option: option, poll_id: poll.id)
|
72
|
+
expect(replies.last).to eq(success)
|
73
|
+
}
|
74
|
+
# check poll info
|
75
|
+
send_command('poll info '+topic1Id, as: poll_user2)
|
76
|
+
sleep(2)
|
77
|
+
info_reply = replies.last(options.length+1)
|
78
|
+
expect(info_reply.first).to eq(ph::translate("replies.info.header", poll_topic: topics.first))
|
79
|
+
options.zip(info_reply.drop(1)).each_with_index.map { |pair, idx|
|
80
|
+
option = pair.first
|
81
|
+
reply = pair.last
|
82
|
+
success = ph::translate("replies.info.option", idx: idx+1, option: option)
|
83
|
+
expect(reply).to eq(success)
|
84
|
+
}
|
85
|
+
# voting and tallying
|
86
|
+
send_command('poll vote '+topic1Id+' 1', as: poll_user1)
|
87
|
+
expect(replies.last).to eq(ph::translate("replies.vote.success", option: options[0]))
|
88
|
+
send_command('poll vote '+topic1Id+' 2', as: poll_user2)
|
89
|
+
expect(replies.last).to eq(ph::translate("replies.vote.success", option: options[1]))
|
90
|
+
send_command('poll tally '+topic1Id, as: poll_user2)
|
91
|
+
sleep(2)
|
92
|
+
tally_reply = replies.last(options.length+1)
|
93
|
+
expect(tally_reply[0]).to eq(ph::translate("replies.tally.header"))
|
94
|
+
expect(tally_reply[1]).to eq(ph::translate("replies.tally.option", option: options[0], votes: 1))
|
95
|
+
expect(tally_reply[2]).to eq(ph::translate("replies.tally.option", option: options[1], votes: 1))
|
96
|
+
expect(tally_reply[3]).to eq(ph::translate("replies.tally.option", option: options[2], votes: 0))
|
97
|
+
# change vote
|
98
|
+
send_command('poll vote '+topic1Id+' 3', as: poll_user1)
|
99
|
+
expect(replies.last).to eq(ph::translate("replies.vote.success", option: options[2]))
|
100
|
+
send_command('poll tally '+topic1Id, as: poll_user2)
|
101
|
+
sleep(2)
|
102
|
+
tally_reply = replies.last(options.length+1)
|
103
|
+
expect(tally_reply[0]).to eq(ph::translate("replies.tally.header"))
|
104
|
+
expect(tally_reply[1]).to eq(ph::translate("replies.tally.option", option: options[0], votes: 0))
|
105
|
+
expect(tally_reply[2]).to eq(ph::translate("replies.tally.option", option: options[1], votes: 1))
|
106
|
+
expect(tally_reply[3]).to eq(ph::translate("replies.tally.option", option: options[2], votes: 1))
|
107
|
+
# voting for non-existent options
|
108
|
+
send_command('poll vote '+topic1Id+' 4', as: poll_user1)
|
109
|
+
expect(replies.last).to eq(ph::translate("replies.vote.not_found"))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "poll administration" do
|
114
|
+
it "complete poll" do
|
115
|
+
topics.map { |topic|
|
116
|
+
poll = Poll.new(topic)
|
117
|
+
send_command('poll make '+topic, as: poll_user1)
|
118
|
+
}
|
119
|
+
send_command('poll complete '+topic1Id, as: poll_admin)
|
120
|
+
expect(replies.last).to eq(ph::translate("replies.complete.success"))
|
121
|
+
send_command('poll list', as: poll_user1)
|
122
|
+
sleep(2)
|
123
|
+
list_reply = replies.last(topics.length)
|
124
|
+
expect(list_reply.first).to eq(ph::translate("replies.list.header"))
|
125
|
+
puts list_reply
|
126
|
+
end
|
127
|
+
|
128
|
+
it "clear polls" do
|
129
|
+
topics.map { |topic|
|
130
|
+
poll = Poll.new(topic)
|
131
|
+
send_command('poll make '+topic, as: poll_user1)
|
132
|
+
}
|
133
|
+
send_command('poll clear', as: poll_admin)
|
134
|
+
expect(replies.last).to eq(ph::translate("replies.clear.success"))
|
135
|
+
send_command('poll list', as: poll_user1)
|
136
|
+
expect(replies.last).to eq(ph::translate("replies.list.no_polls"))
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
4
140
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-poll
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Chua
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-09 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.2.1
|
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.2.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
109
|
+
rubygems_version: 2.4.6
|
110
110
|
signing_key:
|
111
111
|
specification_version: 4
|
112
112
|
summary: Plugin that enables polling functionality for a lita bot.
|