lita-conferenz 1.0.1 → 1.0.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: b4b5b603523ab6945ca312403138be66d58bb927
4
- data.tar.gz: 94583855cb7b7a9a8545ece100e7db0b8202f8bf
3
+ metadata.gz: c01edae6597a11d821cb3584499b884aea18bd30
4
+ data.tar.gz: d9def971f5d6708a941621b1adbd9d3b3717b4ae
5
5
  SHA512:
6
- metadata.gz: 6e3089bc86479ea11ee2da7a1b1ba80594883bd9b443481ae74d6cb482426f30b6d6741cf4d788b0c19672b4851bb98c1d069858e440666953a0b54e99ba2454
7
- data.tar.gz: b54af757417eff2d669d94fe99b6b4e2092375d9c78a3bcb69a801c4ec7d2cf94eac855d5ed1cd6d76356dd63c0b2776968c071e039a814d6d3951f14eb5c355
6
+ metadata.gz: 940ae2080b798b0dccde2859f84bc8ef737ebb518d145cfdc6c038040f8202761162a99d8dfc417bc716b358815023791aae827d5335d3728da1ee8a8cc6d7b2
7
+ data.tar.gz: 177610688810155fb8acbe14e6e8d64777a6fe14490998854c79969102136b16f97b5383edffae217d1fdc837ca92806c3e1e400e7ae73b6b2629d734974a9b5
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "lita-conferenz"
3
- spec.version = "1.0.1"
3
+ spec.version = "1.0.2"
4
4
  spec.authors = ["Piotr Limanowski"]
5
5
  spec.email = ["plimanowski+conferenz@gmail.com"]
6
6
  spec.description = %q{A Lita handler for tracking conferences attendance.}
data/locales/en.yml CHANGED
@@ -1,7 +1,7 @@
1
1
  en:
2
2
  lita:
3
3
  handlers:
4
- karma:
4
+ conferenz:
5
5
  already_linked: "%{source} is already linked to %{target}."
6
6
  already_unlinked: "%{source} is not linked to %{target}."
7
7
  callable_required: must be a callable object
@@ -15,18 +15,18 @@ en:
15
15
  decrement_key: TERM--
16
16
  decrement_value: Decrements TERM by one.
17
17
  check_key: TERM~~
18
- check_value: Shows the current karma of TERM.
18
+ check_value: Shows the current conferenz of TERM.
19
19
  link_key: TERM1 += TERM2
20
20
  link_value: Links TERM2 to TERM1.
21
21
  unlink_key: TERM1 -= TERM2
22
22
  unlink_value: Unlinks TERM2 from TERM1.
23
- list_worst_key: "karma worst [N]"
24
- list_worst_value: Lists the bottom N terms by karma. N defaults to 5.
25
- list_best_key: "karma best [N]"
26
- list_best_value: Lists the top N terms by karma. N defaults to 5.
27
- modified_key: karma modified TERM
23
+ list_worst_key: "conferenz worst [N]"
24
+ list_worst_value: Lists the bottom N terms by conferenz. N defaults to 5.
25
+ list_best_key: "conferenz best [N]"
26
+ list_best_value: Lists the top N terms by conferenz. N defaults to 5.
27
+ modified_key: conferenz modified TERM
28
28
  modified_value: Lists the names of users who have upvoted or downvoted TERM.
29
- delete_key: karma delete TERM
29
+ delete_key: conferenz delete TERM
30
30
  delete_value: >-
31
31
  Permanently removes TERM and all its link information. TERM is matched
32
32
  exactly as typed and does not adhere to the usual pattern for terms.
@@ -36,5 +36,5 @@ en:
36
36
  no_terms: There are no terms being tracked yet.
37
37
  threshold_not_satisfied: >-
38
38
  Terms must have less than or equal to -%{threshold} or greater than or equal to
39
- %{threshold} karma to be linked or linked to.
39
+ %{threshold} conferenz to be linked or linked to.
40
40
  unlink_success: "%{source} has been unlinked from %{target}."
@@ -0,0 +1,339 @@
1
+ # -*- coding: utf-8 -*-
2
+ require "spec_helper"
3
+
4
+ describe Lita::Handlers::Conferenz::Chat, lita_handler: true do
5
+ let(:payload) { double("payload") }
6
+
7
+ prepend_before { registry.register_handler(Lita::Handlers::Conferenz::Config) }
8
+
9
+ before do
10
+ registry.config.handlers.conferenz.cooldown = nil
11
+ registry.config.handlers.conferenz.link_karma_threshold = nil
12
+ described_class.routes.clear
13
+ subject.define_routes(payload)
14
+ end
15
+
16
+ it { is_expected.to route("foo++").to(:increment) }
17
+ it { is_expected.to route("foo--").to(:decrement) }
18
+ it { is_expected.to route("foo++ bar").to(:increment) }
19
+ it { is_expected.to route("foo-- bar").to(:decrement) }
20
+ it { is_expected.to route("foo~~").to(:check) }
21
+ it { is_expected.to route_command("conferenz best").to(:list_best) }
22
+ it { is_expected.to route_command("conferenz worst").to(:list_worst) }
23
+ it { is_expected.to route_command("conferenz modified foo").to(:modified) }
24
+ it do
25
+ is_expected.to route_command("conferenz delete").with_authorization_for(:karma_admins).to(:delete)
26
+ end
27
+ it { is_expected.to route_command("conferenz").to(:list_best) }
28
+ it { is_expected.to route_command("foo += bar").to(:link) }
29
+ it { is_expected.to route_command("foo += bar++").to(:link) }
30
+ it { is_expected.to route_command("foo += bar--").to(:link) }
31
+ it { is_expected.to route_command("foo += bar~~").to(:link) }
32
+ it { is_expected.to route_command("foo -= bar").to(:unlink) }
33
+ it { is_expected.to route_command("foo -= bar++").to(:unlink) }
34
+ it { is_expected.to route_command("foo -= bar--").to(:unlink) }
35
+ it { is_expected.to route_command("foo -= bar~~").to(:unlink) }
36
+ it { is_expected.not_to route("+++++").to(:increment) }
37
+ it { is_expected.not_to route("-----").to(:decrement) }
38
+ it { is_expected.not_to route("foo++bar").to(:increment) }
39
+ it { is_expected.not_to route("foo--bar").to(:decrement) }
40
+
41
+ describe "#increment" do
42
+ it "increases the term's score by one and says the new score" do
43
+ send_message("foo++")
44
+ expect(replies.last).to eq("foo: 1")
45
+ end
46
+
47
+ it "matches multiple terms in one message" do
48
+ send_message("foo++ bar++")
49
+ expect(replies.last).to eq("foo: 1; bar: 1")
50
+ end
51
+
52
+ it "doesn't start from zero if the term already has a positive score" do
53
+ send_message("foo++")
54
+ send_message("foo++")
55
+ expect(replies.last).to eq("foo: 2")
56
+ end
57
+
58
+ it "replies with a warning if term increment is on cooldown" do
59
+ registry.config.handlers.karma.cooldown = 10
60
+ send_message("foo++")
61
+ send_message("foo++")
62
+ expect(replies.last).to match(/cannot modify foo/)
63
+ end
64
+
65
+ it "is case insensitive" do
66
+ send_message("foo++")
67
+ send_message("FOO++")
68
+ expect(replies.last).to eq("foo: 2")
69
+ end
70
+
71
+ it "handles Unicode word characters" do
72
+ send_message("föö++")
73
+ expect(replies.last).to eq("föö: 1")
74
+ end
75
+ end
76
+
77
+ describe "#decrement" do
78
+ it "decreases the term's score by one and says the new score" do
79
+ send_message("foo--")
80
+ expect(replies.last).to eq("foo: -1")
81
+ end
82
+
83
+ it "matches multiple terms in one message" do
84
+ send_message("foo-- bar--")
85
+ expect(replies.last).to eq("foo: -1; bar: -1")
86
+ end
87
+
88
+ it "doesn't start from zero if the term already has a positive score" do
89
+ send_message("foo++")
90
+ send_message("foo--")
91
+ expect(replies.last).to eq("foo: 0")
92
+ end
93
+
94
+ it "replies with a warning if term increment is on cooldown" do
95
+ registry.config.handlers.karma.cooldown = 10
96
+ send_message("foo--")
97
+ send_message("foo--")
98
+ expect(replies.last).to match(/cannot modify foo/)
99
+ end
100
+ end
101
+
102
+ describe "#check" do
103
+ it "says the term's current score" do
104
+ send_message("foo~~")
105
+ expect(replies.last).to eq("foo: 0")
106
+ end
107
+
108
+ it "matches multiple terms in one message" do
109
+ send_message("foo~~ bar~~")
110
+ expect(replies.last).to eq("foo: 0; bar: 0")
111
+ end
112
+
113
+ it "doesn't match the same term multiple times in one message" do
114
+ send_message("foo~~ foo~~")
115
+ expect(replies.size).to eq(1)
116
+ end
117
+ end
118
+
119
+ describe "#list" do
120
+ it "replies with a warning if there are no terms" do
121
+ send_command("conferenz")
122
+ expect(replies.last).to match(/no terms being tracked/)
123
+ end
124
+
125
+ context "with modified terms" do
126
+ before do
127
+ send_message(
128
+ "one++ one++ one++ two++ two++ three++ four++ four-- five--"
129
+ )
130
+ end
131
+
132
+ it "lists the top 5 terms by default" do
133
+ send_command("conferenz")
134
+ expect(replies.last).to eq <<-MSG.chomp
135
+ 1. one (3)
136
+ 2. two (2)
137
+ 3. three (1)
138
+ 4. four (0)
139
+ 5. five (-1)
140
+ MSG
141
+ end
142
+
143
+ it 'lists the bottom 5 terms when passed "worst"' do
144
+ send_command("conferenz worst")
145
+ expect(replies.last).to eq <<-MSG.chomp
146
+ 1. five (-1)
147
+ 2. four (0)
148
+ 3. three (1)
149
+ 4. two (2)
150
+ 5. one (3)
151
+ MSG
152
+ end
153
+
154
+ it "limits the list to the count passed as the second argument" do
155
+ send_command("conferenz best 2")
156
+ expect(replies.last).to eq <<-MSG.chomp
157
+ 1. one (3)
158
+ 2. two (2)
159
+ MSG
160
+ end
161
+ end
162
+ end
163
+
164
+ describe "#link" do
165
+ it "says that it's linked term 2 to term 1" do
166
+ send_command("foo += bar")
167
+ expect(replies.last).to eq("bar has been linked to foo.")
168
+ end
169
+
170
+ it "says that term 2 was already linked to term 1 if it was" do
171
+ send_command("foo += bar")
172
+ send_command("foo += bar")
173
+ expect(replies.last).to eq("bar is already linked to foo.")
174
+ end
175
+
176
+ it "causes term 1's score to be modified by term 2's" do
177
+ send_message("foo++ bar++ baz++")
178
+ send_command("foo += bar")
179
+ send_command("foo += baz")
180
+ send_message("foo~~")
181
+ expect(replies.last).to match(
182
+ /foo: 3 \(1\), linked to: ba[rz]: 1, ba[rz]: 1/
183
+ )
184
+ end
185
+
186
+ context "when link_karma_threshold is set" do
187
+ before do
188
+ registry.config.handlers.karma.link_karma_threshold = 1
189
+ end
190
+
191
+ it "doesn't allow a term to be linked if both are below the threshold" do
192
+ send_command("foo += bar")
193
+ expect(replies.last).to include("must have less than")
194
+ end
195
+
196
+ it "doesn't allow a term to be linked if it's below the threshold" do
197
+ send_command("foo++")
198
+ send_command("foo += bar")
199
+ expect(replies.last).to include("must have less than")
200
+ end
201
+
202
+ it "doesn't allow a term to be linked to another term below the threshold" do
203
+ send_command("bar++")
204
+ send_command("foo += bar")
205
+ expect(replies.last).to include("must have less than")
206
+ end
207
+
208
+ it "allows links if both terms meet the threshold" do
209
+ send_command("foo++ bar++")
210
+ send_command("foo += bar")
211
+ expect(replies.last).to include("has been linked")
212
+ send_command("bar += foo")
213
+ expect(replies.last).to include("has been linked")
214
+ end
215
+
216
+ it "uses the absolute value for terms with negative karma" do
217
+ send_command("foo-- bar--")
218
+ send_command("foo += bar")
219
+ expect(replies.last).to include("has been linked")
220
+ send_command("bar += foo")
221
+ expect(replies.last).to include("has been linked")
222
+ end
223
+ end
224
+ end
225
+
226
+ describe "#unlink" do
227
+ it "says that it's unlinked term 2 from term 1" do
228
+ send_command("foo += bar")
229
+ send_command("foo -= bar")
230
+ expect(replies.last).to eq("bar has been unlinked from foo.")
231
+ end
232
+
233
+ it "says that term 2 was not linked to term 1 if it wasn't" do
234
+ send_command("foo -= bar")
235
+ expect(replies.last).to eq("bar is not linked to foo.")
236
+ end
237
+
238
+ it "causes term 1's score to stop being modified by term 2's" do
239
+ send_message("foo++ bar++")
240
+ send_command("foo += bar")
241
+ send_command("foo -= bar")
242
+ send_message("foo~~")
243
+ expect(replies.last).to eq("foo: 1")
244
+ end
245
+ end
246
+
247
+ describe "#modified" do
248
+ it "replies with a message if the term hasn't been modified" do
249
+ send_command("conferenz modified foo")
250
+ expect(replies.last).to match(/never been modified/)
251
+ end
252
+
253
+ it "lists users who have modified the given term in count order" do
254
+ other_user = Lita::User.create("2", name: "Other User")
255
+ send_message("foo++", as: user)
256
+ send_message("foo++", as: user)
257
+ send_message("foo++", as: other_user)
258
+ send_command("conferenz modified foo")
259
+ expect(replies.last).to eq("#{user.name}, #{other_user.name}")
260
+ end
261
+ end
262
+
263
+ describe "#delete" do
264
+ before do
265
+ robot.auth.add_user_to_group!(user, :karma_admins)
266
+ end
267
+
268
+ it "deletes the term" do
269
+ send_message("foo++")
270
+ send_command("conferenz delete foo")
271
+ expect(replies.last).to eq("foo has been deleted.")
272
+ send_message("foo~~")
273
+ expect(replies.last).to eq("foo: 0")
274
+ end
275
+
276
+ it "matches terms exactly, including leading whitespace" do
277
+ term = " 'foo bar* 'baz''/ :"
278
+ subject.redis.zincrby("terms", 1, term)
279
+ send_command("conferenz delete #{term}")
280
+ expect(replies.last).to include("has been deleted")
281
+ end
282
+
283
+ it "clears the modification list" do
284
+ send_message("foo++")
285
+ send_command("conferenz delete foo")
286
+ send_command("conferenz modified foo")
287
+ expect(replies.last).to eq("foo has never been modified.")
288
+ end
289
+
290
+ it "clears the deleted term's links" do
291
+ send_command("foo += bar")
292
+ send_command("foo += baz")
293
+ send_command("conferenz delete foo")
294
+ send_message("foo++")
295
+ expect(replies.last).to eq("foo: 1")
296
+ end
297
+
298
+ it "clears links from other terms connected to the deleted term" do
299
+ send_command("bar += foo")
300
+ send_command("baz += foo")
301
+ send_command("conferenz delete foo")
302
+ send_message("bar++")
303
+ expect(replies.last).to eq("bar: 1")
304
+ send_message("baz++")
305
+ expect(replies.last).to eq("baz: 1")
306
+ end
307
+ end
308
+
309
+ describe "custom term patterns and normalization" do
310
+ before do
311
+ registry.config.handlers.karma.term_pattern = /[<:]([^>:]+)[>:]/
312
+ registry.config.handlers.karma.term_normalizer = lambda do |term|
313
+ term.to_s.downcase.strip.sub(/[<:]([^>:]+)[>:]/, '\1')
314
+ end
315
+ described_class.routes.clear
316
+ subject.define_routes(payload)
317
+ end
318
+
319
+ it "increments multi-word terms bounded by delimeters" do
320
+ send_message(":Some Thing:++")
321
+ expect(replies.last).to eq("some thing: 1")
322
+ end
323
+
324
+ it "increments terms with symbols that are bounded by delimeters" do
325
+ send_message("<C++>++")
326
+ expect(replies.last).to eq("c++: 1")
327
+ end
328
+
329
+ it "decrements multi-word terms bounded by delimeters" do
330
+ send_message(":Some Thing:--")
331
+ expect(replies.last).to eq("some thing: -1")
332
+ end
333
+
334
+ it "checks multi-word terms bounded by delimeters" do
335
+ send_message(":Some Thing:~~")
336
+ expect(replies.last).to eq("some thing: 0")
337
+ end
338
+ end
339
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-conferenz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Limanowski
@@ -111,6 +111,7 @@ files:
111
111
  - lita-conferenz.gemspec
112
112
  - locales/en.yml
113
113
  - spec/lita/handlers/conferenz/chat_spec.rb
114
+ - spec/lita/handlers/karma/chat_spec.rb
114
115
  - spec/spec_helper.rb
115
116
  homepage: https://github.com/peel/conferenz
116
117
  licenses:
@@ -139,4 +140,5 @@ specification_version: 4
139
140
  summary: A Lita handler for tracking conferences attendance.
140
141
  test_files:
141
142
  - spec/lita/handlers/conferenz/chat_spec.rb
143
+ - spec/lita/handlers/karma/chat_spec.rb
142
144
  - spec/spec_helper.rb