lita-who_has 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b641dd28ceee6d94ec4a6e59444b9c4d3c3a366b
4
+ data.tar.gz: d8106e4e2ac59dfc0a9ef58cc608bd4076c82fb6
5
+ SHA512:
6
+ metadata.gz: 7ef8fb5e3b24242db232b1a989c2c0b30defc4c9e14f81ba85f81262b51bd54b1bf2c2b0724de1b3db73d67b60a93377cea674d5c6b11955d08ef934215b48c4
7
+ data.tar.gz: fd19f91356ae134e0188f99a28c5becd11a9cc1ebd779f5c0df457ea93999d7bb2a0dc57158613cb6fa8633b893f9ce65b8773a7dc56ef4b4443e71a2ed4cda7
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rubocop.yml ADDED
@@ -0,0 +1,27 @@
1
+ Documentation:
2
+ Exclude:
3
+ - lib/lita/handlers/who_has.rb
4
+
5
+ FileName:
6
+ Exclude:
7
+ - lib/lita-who_has.rb
8
+
9
+ Metrics/LineLength:
10
+ Max: 100
11
+
12
+ Metrics/AbcSize:
13
+ Max: 26
14
+
15
+ Metrics/MethodLength:
16
+ Max: 30
17
+
18
+ Metrics/ClassLength:
19
+ Max: 200
20
+
21
+ Metrics/BlockLength:
22
+ Max: 30
23
+ Exclude:
24
+ - '*.gemspec'
25
+ - Rakefile
26
+ - 'spec/**/*_spec.rb'
27
+ - 'spec/spec_helper.rb'
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ sudo: required
3
+ rvm:
4
+ - 2.3.3
5
+ script: bundle exec rake
6
+ before_install:
7
+ - gem update --system
8
+ services:
9
+ - redis-server
10
+ deploy:
11
+ provider: rubygems
12
+ api_key:
13
+ secure: FyB5zrDHH4umVnmvClHcVfjH+nswGWtzfFWt5SQUHbbLFUn/IxRPb098Lmzho4N9oldRZx2u+9j/wZMEM/65MUmg+RjmUQTmSWd2hs2Ms0azRZDib52cTS7tk/Pga0wbiY6Gx8MAmg9cKHTQlJ/RsgSKo/URHiuiGukQwkHY8bs6nggM62GLOrrJqgxAWaRRvjHVs2srpvSlQTAfA6WjJtmfm3apl/pkNnyTvCtoPUhq2iPJuyByuGBl1SQA5Noj3wKAQ/29q6iEPd7KYYx5sRHsFMfuo8pXwENba1SiERXNBb7f9P3Rcg6i4102DaNIDtTt3cwW1xjKMWIkCxodgiLkqt/PdMmdHL4nT6wNg76/joZJmwLA+w764evugRD7TWAs1pSHdC0IMZUawxBI9PZOGzXd77gY/aPK99f9qAVs9d+za0XY30AbRAcLHLAVBuRTUGRCbxyPLR8GgZtJ7ePrnQ8QjnRf1R8+888M3cI8EXOO0ssFxXwkIUjZBp1MrHMeu88Yy9iy8YK6SIIKOnoGEtCHmIncdzLsFnITLhu9RAnXNbxjOtUGEx294ntXgTgZ0fGWTHON//pYhpkAmfz4rm06i6AtPKf2ejKY4QQhkp2m+m8u6QzqqqTZaIQr340BvGaxPjdVP9bTMC4k1Svj2zc38lIxaJYRgFt3lMc=
14
+ gem: lita-who_has
15
+ on:
16
+ tags: true
17
+ repo: knuedge/lita-who_has
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # lita-who_has
2
+
3
+ [![Build Status](https://travis-ci.org/knuedge/lita-who_has.png?branch=master)](https://travis-ci.org/knuedge/lita-who_has)
4
+ [![Coverage Status](https://coveralls.io/repos/knuedge/lita-who_has/badge.png)](https://coveralls.io/r/knuedge/lita-who_has)
5
+
6
+ Record and retrieve information about environment usage
7
+
8
+ ## Installation
9
+
10
+ Add lita-who_has to your Lita instance's Gemfile:
11
+
12
+ ``` ruby
13
+ gem 'lita-who_has'
14
+ ```
15
+
16
+ ## Configuration
17
+
18
+ ``` ruby
19
+ config.handlers.who_has.namespace = 'my_project'
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ``` bash
25
+ @bot claim thing1
26
+ @bot release thing1
27
+ @bot forget thing1
28
+ @bot claimables
29
+ @bot claimables thing.*
30
+ @bot wrestle thing2 from Jon Doe
31
+ ```
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:rubocop)
7
+
8
+ task default: %i[spec rubocop]
@@ -0,0 +1,12 @@
1
+ require 'lita'
2
+
3
+ Lita.load_locales Dir[File.expand_path(
4
+ File.join('..', '..', 'locales', '*.yml'), __FILE__
5
+ )]
6
+
7
+ require 'lita/handlers/who_has'
8
+
9
+ Lita::Handlers::WhoHas.template_root File.expand_path(
10
+ File.join('..', '..', 'templates'),
11
+ __FILE__
12
+ )
@@ -0,0 +1,182 @@
1
+ module Lita
2
+ module Handlers
3
+ # The main handler for the WhoHas plugin
4
+ class WhoHas < Handler
5
+ route(
6
+ /\Aclaim ([A-Za-z0-9_]+)\Z/,
7
+ :claim_thing,
8
+ help: { 'claim [THING ID]' => 'Mark thing as in use by you' },
9
+ command: true
10
+ )
11
+
12
+ route(
13
+ /\Arelease ([A-Za-z0-9_]+)\Z/,
14
+ :release_thing,
15
+ help: { 'release [THING ID]' => 'Mark thing as available' },
16
+ command: true
17
+ )
18
+
19
+ route(
20
+ /\Aclaimables(\s+(\S+))?\Z/,
21
+ :list_things,
22
+ help: { 'claimables <optional glob>' => 'List things' },
23
+ command: true
24
+ )
25
+
26
+ route(
27
+ /\Aforget ([A-Za-z0-9_]+)\Z/,
28
+ :forget_thing,
29
+ help: { 'forget [THING ID]' => 'Forget thing' },
30
+ command: true
31
+ )
32
+
33
+ route(
34
+ /\Awrestle ([A-Za-z0-9_]+) from (.*)\Z/,
35
+ :claim_used_thing,
36
+ help: { 'wrestle [THING ID] from [USER]' => 'Steal a thing' },
37
+ command: true
38
+ )
39
+
40
+ config :namespace, required: true do
41
+ validate do |value|
42
+ unless value =~ /\A[a-z0-9_]+\Z/
43
+ 'can only contain lowercase letters, numbers and underscores'
44
+ end
45
+ end
46
+ end
47
+
48
+ def claim_thing(response)
49
+ thing_id = response.matches.first.first
50
+ case current_user(thing_id)
51
+ when nil
52
+ redis.hset(key(thing_id), 'user', response.user.name)
53
+ response.reply t('claim_thing.success')
54
+ when ''
55
+ redis.hset(key(thing_id), 'user', response.user.name)
56
+ response.reply t('claim_thing.success')
57
+ when response.user.name
58
+ response.reply t(
59
+ 'claim_thing.failure.thing_in_use_by_user', thing_id: thing_id
60
+ )
61
+ else
62
+ response.reply t(
63
+ 'claim_thing.failure.thing_in_use_by_other_user',
64
+ thing_id: thing_id,
65
+ user: current_user(thing_id)
66
+ )
67
+ end
68
+ end
69
+
70
+ def release_thing(response)
71
+ thing_id = response.matches.first.first
72
+ case current_user(thing_id)
73
+ when nil
74
+ response.reply t(
75
+ 'release_thing.failure.thing_unknown',
76
+ thing_id: thing_id
77
+ )
78
+ when ''
79
+ response.reply t(
80
+ 'release_thing.failure.thing_not_in_use_by_user',
81
+ thing_id: thing_id
82
+ )
83
+ when response.user.name
84
+ redis.hset(key(thing_id), 'user', nil)
85
+ response.reply t('release_thing.success')
86
+ else
87
+ response.reply t(
88
+ 'release_thing.failure.thing_in_use_by_other_user',
89
+ thing_id: thing_id,
90
+ user: current_user(thing_id)
91
+ )
92
+ end
93
+ end
94
+
95
+ def list_things(response)
96
+ list_regex = response.matches.first.last
97
+ list_regex ||= /.*/
98
+ lines = []
99
+ redis.keys(key('*')).sort.each do |key|
100
+ thing_id = key.split(':').last
101
+ user = redis.hget(key, 'user')
102
+ line = thing_id
103
+ line += " (#{user})" unless user.empty?
104
+ lines << line if thing_id.match(list_regex)
105
+ end
106
+ if lines.any?
107
+ response.reply(lines.join("\n"))
108
+ else
109
+ response.reply t('list_things.failure.no_things')
110
+ end
111
+ end
112
+
113
+ def forget_thing(response)
114
+ thing_id = response.matches.first.first
115
+ case current_user(thing_id)
116
+ when nil
117
+ response.reply t(
118
+ 'forget_thing.failure.thing_unknown',
119
+ thing_id: thing_id
120
+ )
121
+ when ''
122
+ redis.del(key(thing_id))
123
+ response.reply t('forget_thing.success')
124
+ when response.user.name
125
+ response.reply t(
126
+ 'forget_thing.failure.thing_in_use_by_user',
127
+ thing_id: thing_id
128
+ )
129
+ else
130
+ response.reply t(
131
+ 'forget_thing.failure.thing_in_use_by_other_user',
132
+ thing_id: thing_id,
133
+ user: current_user(thing_id)
134
+ )
135
+ end
136
+ end
137
+
138
+ def claim_used_thing(response)
139
+ thing_id, specified_user = response.matches.first
140
+ case current_user(thing_id)
141
+ when nil
142
+ response.reply t(
143
+ 'claim_used_thing.failure.thing_unknown',
144
+ thing_id: thing_id
145
+ )
146
+ when ''
147
+ response.reply t(
148
+ 'claim_used_thing.failure.thing_not_in_use',
149
+ thing_id: thing_id
150
+ )
151
+ when response.user.name
152
+ response.reply t(
153
+ 'claim_used_thing.failure.thing_in_use_by_user',
154
+ thing_id: thing_id
155
+ )
156
+ when specified_user
157
+ redis.hset(key(thing_id), 'user', response.user.name)
158
+ response.reply t('claim_used_thing.success')
159
+ else
160
+ response.reply t(
161
+ 'claim_used_thing.failure.thing_in_use_by_user_other',
162
+ thing_id: thing_id,
163
+ user: current_user(thing_id),
164
+ specified_user: specified_user
165
+ )
166
+ end
167
+ end
168
+
169
+ private
170
+
171
+ def key(thing_id)
172
+ ['whohas_things', config.namespace, thing_id].join(':')
173
+ end
174
+
175
+ def current_user(thing_id)
176
+ redis.hget(key(thing_id), 'user')
177
+ end
178
+
179
+ Lita.register_handler(self)
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,31 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = 'lita-who_has'
3
+ spec.version = '0.2.0'
4
+ spec.authors = ['Jonathan Gnagy']
5
+ spec.email = ['jgnagy@knuedge.com']
6
+ spec.description = 'A more generic lita-envy for who owns things via lita'
7
+ spec.summary = 'Record and retrieve information about things'
8
+ spec.homepage = 'https://github.com/knuedge/lita-who_has'
9
+ spec.license = 'MIT'
10
+ spec.metadata = { 'lita_plugin_type' => 'handler' }
11
+
12
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
13
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
15
+ spec.require_paths = ['lib']
16
+
17
+ spec.required_ruby_version = '~> 2.3'
18
+
19
+ spec.add_runtime_dependency 'lita', '>= 4.7'
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'pry-byebug'
23
+ spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rack-test'
25
+ spec.add_development_dependency 'rspec', '>= 3.0.0'
26
+ spec.add_development_dependency 'simplecov'
27
+ spec.add_development_dependency 'coveralls'
28
+ spec.add_development_dependency 'byebug'
29
+ spec.add_development_dependency 'rubocop'
30
+ spec.add_development_dependency 'travis', '~> 1.8'
31
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,31 @@
1
+ en:
2
+ lita:
3
+ handlers:
4
+ who_has:
5
+ claim_thing:
6
+ success: It's all yours!
7
+ failure:
8
+ thing_in_use_by_user: "Hmm, you are already using %{thing_id}"
9
+ thing_in_use_by_other_user: "Hmm, %{thing_id} is currently in use by %{user}"
10
+ release_thing:
11
+ success: Thanks!
12
+ failure:
13
+ thing_unknown: "Hmm, I do not know about %{thing_id}"
14
+ thing_not_in_use_by_user: "Hmm, you are not currently using %{thing_id}"
15
+ thing_in_use_by_other_user: "Hmm, you are not currently using %{thing_id} (%{user} is)"
16
+ forget_thing:
17
+ success: Poof! It's gone!
18
+ failure:
19
+ thing_unknown: "Hmm, I do not know about %{thing_id}"
20
+ thing_in_use_by_user: "Hmm, you are currently using %{thing_id}"
21
+ thing_in_use_by_other_user: "Hmm, %{thing_id} is currently in use by %{user}"
22
+ claim_used_thing:
23
+ success: It's all yours!
24
+ failure:
25
+ thing_unknown: "Hmm, I do not know about %{thing_id}"
26
+ thing_not_in_use: "Hmm, %{thing_id} is not currently in use"
27
+ thing_in_use_by_user: "Hmm, you are already using %{thing_id}"
28
+ thing_in_use_by_user_other: "Hmm, %{thing_id} is currently in use by %{user}, not %{specified_user}"
29
+ list_things:
30
+ failure:
31
+ no_things: "Hmm, I'm not tracking anything that matches your query"
@@ -0,0 +1,336 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lita::Handlers::WhoHas, lita_handler: true do
4
+ before(:each) do
5
+ allow(subject.config).to receive(:namespace).and_return('my_project')
6
+ end
7
+
8
+ describe 'Routing' do
9
+ it { is_expected.to route_command('claim ENV123').to(:claim_thing) }
10
+ it { is_expected.to route_command('release ENV123').to(:release_thing) }
11
+ it { is_expected.to route_command('claimables').to(:list_things) }
12
+ it { is_expected.to route_command('forget ENV123').to(:forget_thing) }
13
+ it { is_expected.to route_command('wrestle ENV123 from Alicia').to(:claim_used_thing) }
14
+ end
15
+
16
+ describe 'User claiming thing' do
17
+ context 'when thing is available' do
18
+ before(:each) do
19
+ subject.redis.hset('whohas_things:my_project:ENV123', 'user', '')
20
+ end
21
+
22
+ it 'should mark thing as in use by user' do
23
+ carl = Lita::User.create(123, name: 'Carl')
24
+ send_command('claim ENV123', as: carl)
25
+ expect(subject.redis.hget('whohas_things:my_project:ENV123', 'user')).to eq('Carl')
26
+ end
27
+
28
+ it 'should reply with confirmation' do
29
+ send_command('claim ENV123')
30
+ expect(replies.first).to eq("It's all yours!")
31
+ end
32
+ end
33
+
34
+ context 'when thing is unknown to bot' do
35
+ before(:each) do
36
+ subject.redis.del('whohas_things:my_project:ENV123')
37
+ end
38
+
39
+ it 'should mark thing as in use by user' do
40
+ carl = Lita::User.create(123, name: 'Carl')
41
+ send_command('claim ENV123', as: carl)
42
+ expect(subject.redis.hget('whohas_things:my_project:ENV123', 'user')).to eq('Carl')
43
+ end
44
+
45
+ it 'should reply with confirmation' do
46
+ send_command('claim ENV123')
47
+ expect(replies.first).to eq("It's all yours!")
48
+ end
49
+ end
50
+
51
+ context 'when thing is in use by another user' do
52
+ before(:each) do
53
+ subject.redis.hset('whohas_things:my_project:ENV123', 'user', 'Alicia')
54
+ end
55
+
56
+ it 'should leave the thing untouched' do
57
+ carl = Lita::User.create(123, name: 'Carl')
58
+ send_command('claim ENV123', as: carl)
59
+ expect(subject.redis.hget('whohas_things:my_project:ENV123', 'user')).to eq('Alicia')
60
+ end
61
+
62
+ it 'should reply with notification' do
63
+ subject.redis.hset('whohas_things:my_project:ENV123', 'user', 'Alicia')
64
+ carl = Lita::User.create(123, name: 'Carl')
65
+ send_command('claim ENV123', as: carl)
66
+ expect(replies.first).to eq('Hmm, ENV123 is currently in use by Alicia')
67
+ end
68
+ end
69
+
70
+ context 'when thing is already in use by user' do
71
+ before(:each) do
72
+ subject.redis.hset('whohas_things:my_project:ENV123', 'user', 'Carl')
73
+ end
74
+
75
+ it 'should leave the thing untouched' do
76
+ carl = Lita::User.create(123, name: 'Carl')
77
+ send_command('claim ENV123', as: carl)
78
+ expect(subject.redis.hget('whohas_things:my_project:ENV123', 'user')).to eq('Carl')
79
+ end
80
+
81
+ it 'should reply with notification' do
82
+ subject.redis.hset('whohas_things:my_project:ENV123', 'user', 'Carl')
83
+ carl = Lita::User.create(123, name: 'Carl')
84
+ send_command('claim ENV123', as: carl)
85
+ expect(replies.first).to eq('Hmm, you are already using ENV123')
86
+ end
87
+ end
88
+ end
89
+
90
+ describe 'User releasing thing' do
91
+ context 'when thing is in use by user' do
92
+ before(:each) do
93
+ subject.redis.hset('whohas_things:my_project:ENV234', 'user', 'Alicia')
94
+ end
95
+
96
+ it 'should mark thing as available' do
97
+ alicia = Lita::User.create(123, name: 'Alicia')
98
+ send_command('release ENV234', as: alicia)
99
+ expect(subject.redis.hget('whohas_things:my_project:ENV234', 'user')).to be_empty
100
+ end
101
+
102
+ it 'should reply with confirmation' do
103
+ alicia = Lita::User.create(123, name: 'Alicia')
104
+ send_command('release ENV234', as: alicia)
105
+ expect(replies.first).to eq('Thanks!')
106
+ end
107
+ end
108
+
109
+ context 'when thing is in use by another user' do
110
+ before(:each) do
111
+ subject.redis.hset('whohas_things:my_project:ENV234', 'user', 'Carl')
112
+ end
113
+
114
+ it 'should leave the thing untouched' do
115
+ alicia = Lita::User.create(123, name: 'Alicia')
116
+ send_command('release ENV234', as: alicia)
117
+ expect(subject.redis.hget('whohas_things:my_project:ENV234', 'user')).to eq('Carl')
118
+ end
119
+
120
+ it 'should reply with notification' do
121
+ alicia = Lita::User.create(123, name: 'Alicia')
122
+ send_command('release ENV234', as: alicia)
123
+ expect(replies.first).to eq('Hmm, you are not currently using ENV234 (Carl is)')
124
+ end
125
+ end
126
+
127
+ context 'when thing is not in use' do
128
+ before(:each) do
129
+ subject.redis.hset('whohas_things:my_project:ENV234', 'user', '')
130
+ end
131
+
132
+ it 'should leave the thing untouched' do
133
+ alicia = Lita::User.create(123, name: 'Alicia')
134
+ send_command('release ENV234', as: alicia)
135
+ expect(subject.redis.hget('whohas_things:my_project:ENV234', 'user')).to eq('')
136
+ end
137
+
138
+ it 'should reply with notification' do
139
+ alicia = Lita::User.create(123, name: 'Alicia')
140
+ send_command('release ENV234', as: alicia)
141
+ expect(replies.first).to eq('Hmm, you are not currently using ENV234')
142
+ end
143
+ end
144
+
145
+ context 'when thing is unknown to bot' do
146
+ before(:each) do
147
+ subject.redis.del('whohas_things:my_project:ENV234')
148
+ end
149
+
150
+ it 'should leave the thing untouched' do
151
+ alicia = Lita::User.create(123, name: 'Alicia')
152
+ send_command('release ENV234', as: alicia)
153
+ expect(subject.redis.hget('whohas_things:my_project:ENV234', 'user')).to be_nil
154
+ end
155
+
156
+ it 'should reply with notification' do
157
+ alicia = Lita::User.create(123, name: 'Alicia')
158
+ send_command('release ENV234', as: alicia)
159
+ expect(replies.first).to eq('Hmm, I do not know about ENV234')
160
+ end
161
+ end
162
+ end
163
+
164
+ describe 'User listing things' do
165
+ context 'with things recorded' do
166
+ before(:each) do
167
+ subject.redis.hset('whohas_things:my_project:ENV345', 'user', '')
168
+ subject.redis.hset('whohas_things:my_project:ENV123', 'user', 'Alicia')
169
+ subject.redis.hset('whohas_things:my_project:ENV234', 'user', 'Carl')
170
+ end
171
+
172
+ it 'should list things' do
173
+ send_command('claimables')
174
+ expect(replies.first.split("\n")).to eq([
175
+ 'ENV123 (Alicia)',
176
+ 'ENV234 (Carl)',
177
+ 'ENV345'
178
+ ])
179
+ end
180
+ end
181
+
182
+ context 'with no things recorded' do
183
+ it 'should respond with notification' do
184
+ send_command('claimables')
185
+ expect(replies.first).to eq('Hmm, I\'m not tracking anything that matches your query')
186
+ end
187
+ end
188
+ end
189
+
190
+ describe 'User removing thing' do
191
+ context 'when thing is available' do
192
+ before(:each) do
193
+ subject.redis.hset('whohas_things:my_project:ENV345', 'user', '')
194
+ end
195
+
196
+ it 'should forget thing' do
197
+ send_command('forget ENV345')
198
+ expect(subject.redis.keys).to_not include('whohas_things:my_project:ENV345')
199
+ end
200
+
201
+ it 'should confirm' do
202
+ send_command('forget ENV345')
203
+ expect(replies.first).to eq("Poof! It's gone!")
204
+ end
205
+ end
206
+
207
+ context 'when thing is unknown to bot' do
208
+ before(:each) do
209
+ subject.redis.del('whohas_things:my_project:ENV345')
210
+ end
211
+
212
+ it 'should reply with notification' do
213
+ send_command('forget ENV345')
214
+ expect(replies.first).to eq('Hmm, I do not know about ENV345')
215
+ end
216
+ end
217
+
218
+ context 'when thing is in use by another user' do
219
+ before(:each) do
220
+ subject.redis.hset('whohas_things:my_project:ENV345', 'user', 'Carl')
221
+ end
222
+
223
+ it 'should leave the thing untouched' do
224
+ alicia = Lita::User.create(123, name: 'Alicia')
225
+ send_command('forget ENV345', as: alicia)
226
+ expect(subject.redis.hget('whohas_things:my_project:ENV345', 'user')).to eq('Carl')
227
+ end
228
+
229
+ it 'should reply with notification' do
230
+ send_command('forget ENV345')
231
+ expect(replies.first).to eq('Hmm, ENV345 is currently in use by Carl')
232
+ end
233
+ end
234
+
235
+ context 'when thing is in use by user' do
236
+ before(:each) do
237
+ subject.redis.hset('whohas_things:my_project:ENV345', 'user', 'Alicia')
238
+ end
239
+
240
+ it 'should leave the thing untouched' do
241
+ alicia = Lita::User.create(123, name: 'Alicia')
242
+ send_command('forget ENV345', as: alicia)
243
+ expect(subject.redis.hget('whohas_things:my_project:ENV345', 'user')).to eq('Alicia')
244
+ end
245
+
246
+ it 'should reply with notification' do
247
+ alicia = Lita::User.create(123, name: 'Alicia')
248
+ send_command('forget ENV345', as: alicia)
249
+ expect(replies.first).to eq('Hmm, you are currently using ENV345')
250
+ end
251
+ end
252
+ end
253
+
254
+ describe 'User claiming thing from other user' do
255
+ context 'when thing is currently in use by specified user' do
256
+ before(:each) do
257
+ subject.redis.hset('whohas_things:my_project:ENV123', 'user', 'Alicia')
258
+ end
259
+
260
+ it 'should mark thing as in use' do
261
+ carl = Lita::User.create(123, name: 'Carl')
262
+ send_command('wrestle ENV123 from Alicia', as: carl)
263
+ expect(subject.redis.hget('whohas_things:my_project:ENV123', 'user')).to eq('Carl')
264
+ end
265
+
266
+ it 'should reply with confirmation' do
267
+ send_command('wrestle ENV123 from Alicia')
268
+ expect(replies.first).to eq("It's all yours!")
269
+ end
270
+ end
271
+
272
+ context 'when thing is currently in use by a user other than the specified one' do
273
+ before(:each) do
274
+ subject.redis.hset('whohas_things:my_project:ENV123', 'user', 'Alicia')
275
+ end
276
+
277
+ it 'should leave the thing untouched' do
278
+ carl = Lita::User.create(123, name: 'Carl')
279
+ send_command('wrestle ENV123 from Ben', as: carl)
280
+ expect(subject.redis.hget('whohas_things:my_project:ENV123', 'user')).to eq('Alicia')
281
+ end
282
+
283
+ it 'should reply with notification' do
284
+ send_command('wrestle ENV123 from Ben')
285
+ expect(replies.first).to eq('Hmm, ENV123 is currently in use by Alicia, not Ben')
286
+ end
287
+ end
288
+
289
+ context 'when thing is not currently in use' do
290
+ before(:each) do
291
+ subject.redis.hset('whohas_things:my_project:ENV123', 'user', nil)
292
+ end
293
+
294
+ it 'should leave the thing untouched' do
295
+ carl = Lita::User.create(123, name: 'Carl')
296
+ send_command('wrestle ENV123 from Ben', as: carl)
297
+ expect(subject.redis.hget('whohas_things:my_project:ENV123', 'user')).to be_empty
298
+ end
299
+
300
+ it 'should reply with notification' do
301
+ send_command('wrestle ENV123 from Ben')
302
+ expect(replies.first).to eq('Hmm, ENV123 is not currently in use')
303
+ end
304
+ end
305
+
306
+ context 'when thing is already marked as in use by requesting user' do
307
+ before(:each) do
308
+ subject.redis.hset('whohas_things:my_project:ENV123', 'user', 'Carl')
309
+ end
310
+
311
+ it 'should leave the thing untouched' do
312
+ carl = Lita::User.create(123, name: 'Carl')
313
+ send_command('wrestle ENV123 from Ben', as: carl)
314
+ expect(subject.redis.hget('whohas_things:my_project:ENV123', 'user')).to eq('Carl')
315
+ end
316
+
317
+ it 'should reply with notification' do
318
+ carl = Lita::User.create(123, name: 'Carl')
319
+ send_command('wrestle ENV123 from Ben', as: carl)
320
+ expect(replies.first).to eq('Hmm, you are already using ENV123')
321
+ end
322
+ end
323
+
324
+ context 'when thing is unknown to bot' do
325
+ before(:each) do
326
+ subject.redis.del('whohas_things:my_project:ENV123')
327
+ end
328
+
329
+ it 'should reply with notification' do
330
+ carl = Lita::User.create(123, name: 'Carl')
331
+ send_command('wrestle ENV123 from Ben', as: carl)
332
+ expect(replies.first).to eq('Hmm, I do not know about ENV123')
333
+ end
334
+ end
335
+ end
336
+ end
@@ -0,0 +1,16 @@
1
+ require 'byebug'
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start { add_filter '/spec/' }
9
+
10
+ require 'lita-who_has'
11
+ require 'lita/rspec'
12
+
13
+ # A compatibility mode is provided for older plugins upgrading from Lita 3.
14
+ # Since this plugin was generated with Lita 4, the compatibility mode should
15
+ # be left disabled.
16
+ Lita.version_3_compatibility_mode = false
File without changes
metadata ADDED
@@ -0,0 +1,214 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lita-who_has
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Gnagy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry-byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: travis
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '1.8'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '1.8'
167
+ description: A more generic lita-envy for who owns things via lita
168
+ email:
169
+ - jgnagy@knuedge.com
170
+ executables: []
171
+ extensions: []
172
+ extra_rdoc_files: []
173
+ files:
174
+ - ".gitignore"
175
+ - ".rubocop.yml"
176
+ - ".travis.yml"
177
+ - Gemfile
178
+ - README.md
179
+ - Rakefile
180
+ - lib/lita-who_has.rb
181
+ - lib/lita/handlers/who_has.rb
182
+ - lita-who_has.gemspec
183
+ - locales/en.yml
184
+ - spec/lita/handlers/envy_spec.rb
185
+ - spec/spec_helper.rb
186
+ - templates/.gitkeep
187
+ homepage: https://github.com/knuedge/lita-who_has
188
+ licenses:
189
+ - MIT
190
+ metadata:
191
+ lita_plugin_type: handler
192
+ post_install_message:
193
+ rdoc_options: []
194
+ require_paths:
195
+ - lib
196
+ required_ruby_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: '2.3'
201
+ required_rubygems_version: !ruby/object:Gem::Requirement
202
+ requirements:
203
+ - - ">="
204
+ - !ruby/object:Gem::Version
205
+ version: '0'
206
+ requirements: []
207
+ rubyforge_project:
208
+ rubygems_version: 2.5.2
209
+ signing_key:
210
+ specification_version: 4
211
+ summary: Record and retrieve information about things
212
+ test_files:
213
+ - spec/lita/handlers/envy_spec.rb
214
+ - spec/spec_helper.rb