lita-locker 1.0.8 → 1.0.9
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/.rspec +1 -0
- data/.rubocop.yml +1 -1
- data/lib/lita/handlers/locker.rb +5 -4
- data/lib/lita/handlers/locker_labels.rb +10 -10
- data/lib/lita/handlers/locker_misc.rb +1 -1
- data/lib/locker/label.rb +8 -8
- data/lib/locker/resource.rb +3 -3
- data/lita-locker.gemspec +1 -1
- data/locales/en.yml +1 -0
- data/spec/lita/handlers/locker_http_spec.rb +2 -2
- data/spec/lita/handlers/locker_spec.rb +8 -0
- data/spec/spec_helper.rb +18 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee0b2b2211b4a8e374e294510a405ede0a492d50
|
4
|
+
data.tar.gz: a84b6149da9dd9a6ac46d9f9c9590efab1ff4650
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6c2a8cbbc6dd91c1b3ef652c44c21c0b31d83d6bb1c9c855ae43c6c85cc8283b234f71080f9445549430590eb64b6a056f4649ef50c16a2791fb7540199faf2
|
7
|
+
data.tar.gz: 2580987de7715041491d3523471bdaf37d55692ca0bddc5f1724c4b87af0d8a7a30a2425775c03eaeca3b7649259ce8918bf186bfd5e0c6453171e8a7c7ef449
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --profile 5
|
data/.rubocop.yml
CHANGED
data/lib/lita/handlers/locker.rb
CHANGED
@@ -90,10 +90,10 @@ module Lita
|
|
90
90
|
|
91
91
|
return if l.locked?
|
92
92
|
mention_names = l.observers
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
.map { |observer| render_template('mention', name: observer.mention_name, id: observer.id) }
|
94
|
+
.reject { |mention| mention == '' }
|
95
|
+
.sort
|
96
|
+
.join(' ')
|
97
97
|
response.reply(t('label.unlocked_no_queue', name: name, mention: mention_names)) unless mention_names.empty?
|
98
98
|
end
|
99
99
|
|
@@ -132,6 +132,7 @@ module Lita
|
|
132
132
|
|
133
133
|
return response.reply(failed(t('subject.does_not_exist', name: name))) unless Label.exists?(name)
|
134
134
|
l = Label.new(name)
|
135
|
+
return response.reply(failed(t('give.not_owned', label: name))) unless l.locked?
|
135
136
|
owner_mention = render_template('mention', name: l.owner.mention_name, id: l.owner.id)
|
136
137
|
return response.reply(t('give.not_owner',
|
137
138
|
label: name,
|
@@ -75,11 +75,11 @@ module Lita
|
|
75
75
|
results = []
|
76
76
|
|
77
77
|
names.each do |name|
|
78
|
-
if !Label.exists?(name) && Label.create(name)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
78
|
+
results <<= if !Label.exists?(name) && Label.create(name)
|
79
|
+
t('label.created', name: name)
|
80
|
+
else
|
81
|
+
t('label.exists', name: name)
|
82
|
+
end
|
83
83
|
end
|
84
84
|
|
85
85
|
response.reply(results.join(', '))
|
@@ -90,11 +90,11 @@ module Lita
|
|
90
90
|
results = []
|
91
91
|
|
92
92
|
names.each do |name|
|
93
|
-
if Label.exists?(name) && Label.delete(name)
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
93
|
+
results <<= if Label.exists?(name) && Label.delete(name)
|
94
|
+
t('label.deleted', name: name)
|
95
|
+
else
|
96
|
+
failed(t('label.does_not_exist', name: name))
|
97
|
+
end
|
98
98
|
end
|
99
99
|
|
100
100
|
response.reply(results.join(', '))
|
@@ -79,7 +79,7 @@ module Lita
|
|
79
79
|
user = Lita::User.fuzzy_find(username)
|
80
80
|
return response.reply(t('user.unknown', user: username)) unless user
|
81
81
|
l = user_locks(user)
|
82
|
-
return response.reply(t('user.no_active_locks', user: user.name))
|
82
|
+
return response.reply(t('user.no_active_locks', user: user.name)) if l.empty?
|
83
83
|
composed = ''
|
84
84
|
l.each do |label_name|
|
85
85
|
composed += "Label: #{label_name}\n"
|
data/lib/locker/label.rb
CHANGED
@@ -20,7 +20,7 @@ module Locker
|
|
20
20
|
attr_reader :id
|
21
21
|
|
22
22
|
def initialize(key)
|
23
|
-
|
23
|
+
raise 'Unknown label key' unless Label.exists?(key)
|
24
24
|
@id = Label.normalize(key)
|
25
25
|
end
|
26
26
|
|
@@ -29,7 +29,7 @@ module Locker
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def self.create(key)
|
32
|
-
|
32
|
+
raise 'Label key already exists' if Label.exists?(key)
|
33
33
|
redis.sadd('label-list', Label.normalize(key))
|
34
34
|
l = Label.new(key)
|
35
35
|
l.state = 'unlocked'
|
@@ -39,7 +39,7 @@ module Locker
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def self.delete(key)
|
42
|
-
|
42
|
+
raise 'Unknown label key' unless Label.exists?(key)
|
43
43
|
%w(state, owner_id, membership, wait_queue, journal, observer_ids).each do |item|
|
44
44
|
redis.del("label:#{key}:#{item}")
|
45
45
|
end
|
@@ -95,7 +95,7 @@ module Locker
|
|
95
95
|
# FIXME: Possible race condition where resources become unavailable between unlock and relock
|
96
96
|
if wait_queue.count > 0
|
97
97
|
next_user = wait_queue.shift
|
98
|
-
|
98
|
+
lock!(next_user)
|
99
99
|
end
|
100
100
|
true
|
101
101
|
end
|
@@ -103,15 +103,15 @@ module Locker
|
|
103
103
|
def steal!(owner_id)
|
104
104
|
log("Stolen from #{owner.id} to #{owner_id}")
|
105
105
|
wait_queue.unshift(owner_id)
|
106
|
-
|
107
|
-
|
106
|
+
dedupe!
|
107
|
+
unlock!
|
108
108
|
end
|
109
109
|
|
110
110
|
def give!(recipient_id)
|
111
111
|
log("Given from #{owner.id} to #{recipient_id}")
|
112
112
|
wait_queue.unshift(recipient_id)
|
113
|
-
|
114
|
-
|
113
|
+
dedupe!
|
114
|
+
unlock!
|
115
115
|
end
|
116
116
|
|
117
117
|
def dedupe!
|
data/lib/locker/resource.rb
CHANGED
@@ -15,7 +15,7 @@ module Locker
|
|
15
15
|
attr_reader :id
|
16
16
|
|
17
17
|
def initialize(key)
|
18
|
-
|
18
|
+
raise 'Unknown resource key' unless Resource.exists?(key)
|
19
19
|
@id = key
|
20
20
|
end
|
21
21
|
|
@@ -24,7 +24,7 @@ module Locker
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def self.create(key)
|
27
|
-
|
27
|
+
raise 'Resource key already exists' if Resource.exists?(key)
|
28
28
|
redis.sadd('resource-list', key)
|
29
29
|
r = Resource.new(key)
|
30
30
|
r.state = 'unlocked'
|
@@ -33,7 +33,7 @@ module Locker
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.delete(key)
|
36
|
-
|
36
|
+
raise 'Unknown resource key' unless Resource.exists?(key)
|
37
37
|
%w(state, owner_id).each do |item|
|
38
38
|
redis.del("resource:#{key}:#{item}")
|
39
39
|
end
|
data/lita-locker.gemspec
CHANGED
data/locales/en.yml
CHANGED
@@ -7,6 +7,7 @@ en:
|
|
7
7
|
already_unlocked: "%{label} was already unlocked"
|
8
8
|
self: "%{user}, why are you stealing the lock from yourself?"
|
9
9
|
give:
|
10
|
+
not_owned: "%{label} is not currently locked, so it cannot be given"
|
10
11
|
not_owner: "The lock on %{label} can only be given by its current owner: %{owner} %{mention}"
|
11
12
|
given: "%{giver} gave %{label} to %{recipient} %{mention}"
|
12
13
|
self: "%{user}, why are you giving the lock to yourself?"
|
@@ -24,7 +24,7 @@ describe Lita::Handlers::LockerHttp, lita_handler: true do
|
|
24
24
|
it 'shows json if the label exists' do
|
25
25
|
send_command('locker label create foo')
|
26
26
|
subject.label_show(request, response)
|
27
|
-
expect(response.body).to eq([
|
27
|
+
expect(response.body).to eq(['{"id":"foo","state":"unlocked","membership":""}'])
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'shows 404 if the label does not exist' do
|
@@ -38,7 +38,7 @@ describe Lita::Handlers::LockerHttp, lita_handler: true do
|
|
38
38
|
robot.auth.add_user_to_group!(user, :locker_admins)
|
39
39
|
send_command('locker resource create foo')
|
40
40
|
subject.resource_show(request, response)
|
41
|
-
expect(response.body).to eq([
|
41
|
+
expect(response.body).to eq(['{"id":"foo","state":"unlocked","owner_id":""}'])
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'shows 404 if the resource does not exist' do
|
@@ -325,6 +325,14 @@ describe Lita::Handlers::Locker, lita_handler: true do
|
|
325
325
|
expect(replies.last).to match(/^bazbat is locked by Charlie \(taken \d seconds? ago\)\. Next up: Bob, Charlie$/)
|
326
326
|
end
|
327
327
|
|
328
|
+
it 'shows a warning when a give is attempted on an unlocked resource' do
|
329
|
+
send_command('locker resource create foobar')
|
330
|
+
send_command('locker label create bazbat')
|
331
|
+
send_command('locker label add foobar to bazbat')
|
332
|
+
send_command('locker give bazbat to @alice # with a comment', as: bob)
|
333
|
+
expect(replies.last).to eq('bazbat is not currently locked, so it cannot be given')
|
334
|
+
end
|
335
|
+
|
328
336
|
it 'shows a warning when the owner attempts to give the label to herself' do
|
329
337
|
send_command('locker resource create foobar')
|
330
338
|
send_command('locker label create bazbat')
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
require 'coveralls'
|
3
|
-
SimpleCov.
|
3
|
+
SimpleCov.formatters = [
|
4
4
|
SimpleCov::Formatter::HTMLFormatter,
|
5
5
|
Coveralls::SimpleCov::Formatter
|
6
6
|
]
|
@@ -20,3 +20,20 @@ RSpec.configure do |config|
|
|
20
20
|
registry.register_handler(Lita::Handlers::LockerResources)
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
RSpec.configure do |config|
|
25
|
+
config.expect_with :rspec do |expectations|
|
26
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
27
|
+
end
|
28
|
+
|
29
|
+
config.mock_with :rspec do |mocks|
|
30
|
+
mocks.verify_partial_doubles = true
|
31
|
+
end
|
32
|
+
|
33
|
+
config.filter_run :focus
|
34
|
+
config.run_all_when_everything_filtered = true
|
35
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
36
|
+
config.order = :random
|
37
|
+
|
38
|
+
Kernel.srand config.seed
|
39
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-locker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Sigler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -144,6 +144,7 @@ extensions: []
|
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
146
|
- ".gitignore"
|
147
|
+
- ".rspec"
|
147
148
|
- ".rubocop.yml"
|
148
149
|
- ".travis.yml"
|
149
150
|
- CONTRIBUTING.md
|