lita-locker 0.3.1 → 0.4.0

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: 90e3064b31cd1ed25871959527a507cf3f0f8674
4
- data.tar.gz: b19fcdce56cd0e290317977bfe25d9c49abeaffa
3
+ metadata.gz: 03119612570e96f75bb028de84abf384232d3706
4
+ data.tar.gz: a05484fd65388045838e0bf6940162aff13ceb2f
5
5
  SHA512:
6
- metadata.gz: 47178acf7895afab5c9c96a0df08842a86c538891c04500b3d6543e4f1f55c128466098039c68480fdfbbb2710a7486626dec62a0b2eee23efd85f92889e9db5
7
- data.tar.gz: 0be130945fa756e2e7b6f9f8e0bf35bfa6a8219438f5a719f94f637c08dc170cf523d7d8f6fe3640c27d24a91b751e3e8d7ea6380d40c82aa5d659279ba14346
6
+ metadata.gz: 27704990d5d11504024266de0c058758eda2375f882cffa78f2377afe07f5ccc2328ed871ba0b3c963bd82abe46597244a376110059e2e59e02bf09bf1b97673
7
+ data.tar.gz: b8a522feb8841916016981f8d81136ccd1eb51b619978f64d58ce3b23d0f498a6f0dfc35bfb1df2900816ccc7d2aeacd52439798f03d13a0c070e23b0ca90ec6
data/README.md CHANGED
@@ -58,7 +58,7 @@ unreserve <subject> - Remove yourself from the queue for <subject>
58
58
  ### Labels
59
59
  ```
60
60
  locker label list - List all labels
61
- locker label create <name> - Create a label with <name>. <name> must be A-Z, a-z, 0-9, no spaces or punctuation.
61
+ locker label create <name> - Create a label with <name>.
62
62
  locker label delete <name> - Delete the label with <name>. Clears all locks associated.
63
63
  locker label add <resource> to <name> - Adds <resource> to the list of things to lock/unlock for <name>
64
64
  locker label remove <resource> from <name> - Removes <resource> from <name>
@@ -68,8 +68,8 @@ locker label show <name> - Show all resources for <name>
68
68
  ### Resources
69
69
  ```
70
70
  locker resource list - List all resources
71
- locker resource create <name> - Create a resource with <name>. <name> must be A-Z, a-z, 0-9, no spaces or punctuation.
72
- locker resource delete <name> - Delete the resource with <name>. Clears all locks associated.
71
+ locker resource create <name> - Create a resource with <name>. (Restricted to locker_admins group)
72
+ locker resource delete <name> - Delete the resource with <name>. Clears all locks associated. (Restricted to locker_admins group)
73
73
  locker resource show <name> - Show the state of <name>
74
74
  ```
75
75
 
@@ -4,18 +4,21 @@ module Lita
4
4
  http.get '/locker/label/:name', :http_label_show
5
5
  http.get '/locker/resource/:name', :http_resource_show
6
6
 
7
- # route(
8
- # /^\(lock\)\s([a-zA-Z0-9_-]+)$/,
9
- # :lock
10
- # )
7
+ LABEL_REGEX = /([\W\S_-]+)/
8
+ RESOURCE_REGEX = /([\.a-zA-Z0-9_-]+)/
11
9
 
12
- # route(
13
- # /^\(unlock\)\s([a-zA-Z0-9_-]+)$/,
14
- # :unlock
15
- # )
10
+ route(
11
+ /^\(lock\)\s#{LABEL_REGEX}$/,
12
+ :lock
13
+ )
14
+
15
+ route(
16
+ /^\(unlock\)\s#{LABEL_REGEX}$/,
17
+ :unlock
18
+ )
16
19
 
17
20
  route(
18
- /^lock\s([a-zA-Z0-9_-]+)$/,
21
+ /^lock\s#{LABEL_REGEX}$/,
19
22
  :lock,
20
23
  command: true,
21
24
  help: {
@@ -33,7 +36,7 @@ module Lita
33
36
  # )
34
37
 
35
38
  route(
36
- /^unlock\s([a-zA-Z0-9_-]+)$/,
39
+ /^unlock\s#{LABEL_REGEX}$/,
37
40
  :unlock,
38
41
  command: true,
39
42
  help: {
@@ -42,7 +45,7 @@ module Lita
42
45
  )
43
46
 
44
47
  route(
45
- /^unlock\s([a-zA-Z0-9_-]+)\sforce$/,
48
+ /^unlock\s#{LABEL_REGEX}\sforce$/,
46
49
  :unlock_force,
47
50
  command: true,
48
51
  help: {
@@ -61,9 +64,10 @@ module Lita
61
64
  )
62
65
 
63
66
  route(
64
- /^locker\sresource\screate\s([a-zA-Z0-9_-]+)$/,
67
+ /^locker\sresource\screate\s#{RESOURCE_REGEX}$/,
65
68
  :resource_create,
66
69
  command: true,
70
+ restrict_to: [:locker_admins],
67
71
  help: {
68
72
  t('help.resource_create_key') =>
69
73
  t('help.resource_create_value')
@@ -71,9 +75,10 @@ module Lita
71
75
  )
72
76
 
73
77
  route(
74
- /^locker\sresource\sdelete\s([a-zA-Z0-9_-]+)$/,
78
+ /^locker\sresource\sdelete\s#{RESOURCE_REGEX}$/,
75
79
  :resource_delete,
76
80
  command: true,
81
+ restrict_to: [:locker_admins],
77
82
  help: {
78
83
  t('help.resource_delete_key') =>
79
84
  t('help.resource_delete_value')
@@ -81,7 +86,7 @@ module Lita
81
86
  )
82
87
 
83
88
  route(
84
- /^locker\sresource\sshow\s([a-zA-Z0-9_-]+)$/,
89
+ /^locker\sresource\sshow\s#{RESOURCE_REGEX}$/,
85
90
  :resource_show,
86
91
  command: true,
87
92
  help: {
@@ -101,7 +106,7 @@ module Lita
101
106
  )
102
107
 
103
108
  route(
104
- /^locker\slabel\screate\s([a-zA-Z0-9_-]+)$/,
109
+ /^locker\slabel\screate\s#{LABEL_REGEX}$/,
105
110
  :label_create,
106
111
  command: true,
107
112
  help: {
@@ -111,7 +116,7 @@ module Lita
111
116
  )
112
117
 
113
118
  route(
114
- /^locker\slabel\sdelete\s([a-zA-Z0-9_-]+)$/,
119
+ /^locker\slabel\sdelete\s#{LABEL_REGEX}$/,
115
120
  :label_delete,
116
121
  command: true,
117
122
  help: {
@@ -121,7 +126,7 @@ module Lita
121
126
  )
122
127
 
123
128
  route(
124
- /^locker\slabel\sshow\s([a-zA-Z0-9_-]+)$/,
129
+ /^locker\slabel\sshow\s#{LABEL_REGEX}$/,
125
130
  :label_show,
126
131
  command: true,
127
132
  help: {
@@ -131,7 +136,7 @@ module Lita
131
136
  )
132
137
 
133
138
  route(
134
- /^locker\slabel\sadd\s([a-zA-Z0-9_-]+)\sto\s([a-zA-Z0-9_-]+)$/,
139
+ /^locker\slabel\sadd\s#{RESOURCE_REGEX}\sto\s#{LABEL_REGEX}$/,
135
140
  :label_add,
136
141
  command: true,
137
142
  help: {
@@ -141,7 +146,7 @@ module Lita
141
146
  )
142
147
 
143
148
  route(
144
- /^locker\slabel\sremove\s([a-zA-Z0-9_-]+)\sfrom\s([a-zA-Z0-9_-]+)$/,
149
+ /^locker\slabel\sremove\s#{RESOURCE_REGEX}\sfrom\s#{LABEL_REGEX}$/,
145
150
  :label_remove,
146
151
  command: true,
147
152
  help: {
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-locker'
3
- spec.version = '0.3.1'
3
+ spec.version = '0.4.0'
4
4
  spec.authors = ['Eric Sigler']
5
5
  spec.email = ['me@esigler.com']
6
6
  spec.description = %q("lock" and "unlock" arbitrary subjects)
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.add_development_dependency 'bundler', '~> 1.3'
20
20
  spec.add_development_dependency 'rake'
21
- spec.add_development_dependency 'rspec', '>= 3.0.0.beta2'
21
+ spec.add_development_dependency 'rspec', '>= 3.0.0'
22
22
  spec.add_development_dependency 'simplecov'
23
23
  spec.add_development_dependency 'coveralls'
24
24
  spec.add_development_dependency 'rubocop'
@@ -1,17 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Lita::Handlers::Locker, lita_handler: true do
4
- # it { routes('(lock) foobar').to(:lock) }
5
- # it { routes('(unlock) foobar').to(:unlock) }
4
+ it { routes('(lock) foobar').to(:lock) }
5
+ it { routes('(unlock) foobar').to(:unlock) }
6
6
 
7
7
  it { routes_command('lock foobar').to(:lock) }
8
+ it { routes_command('lock foo bar').to(:lock) }
9
+ it { routes_command('lock foo-bar').to(:lock) }
10
+ it { routes_command('lock foo_bar').to(:lock) }
8
11
  # it { routes_command('lock foobar 30m').to(:lock) }
9
12
 
10
13
  it { routes_command('unlock foobar').to(:unlock) }
14
+ it { routes_command('unlock foo bar').to(:unlock) }
15
+ it { routes_command('unlock foo-bar').to(:unlock) }
16
+ it { routes_command('unlock foo_bar').to(:unlock) }
11
17
  it { routes_command('unlock foobar force').to(:unlock_force) }
12
18
 
13
19
  it { routes_command('locker resource list').to(:resource_list) }
14
20
  it { routes_command('locker resource create foobar').to(:resource_create) }
21
+ it { routes_command('locker resource create foo.bar').to(:resource_create) }
22
+ it { routes_command('locker resource create foo-bar').to(:resource_create) }
23
+ it { routes_command('locker resource create foo_bar').to(:resource_create) }
15
24
  it { routes_command('locker resource delete foobar').to(:resource_delete) }
16
25
  it { routes_command('locker resource show foobar').to(:resource_show) }
17
26
 
@@ -25,6 +34,13 @@ describe Lita::Handlers::Locker, lita_handler: true do
25
34
  it { routes_http(:get, '/locker/label/foobar').to(:http_label_show) }
26
35
  it { routes_http(:get, '/locker/resource/foobar').to(:http_resource_show) }
27
36
 
37
+ before do
38
+ allow(Lita::Authorization).to receive(:user_in_group?).with(
39
+ user,
40
+ :locker_admins
41
+ ).and_return(true)
42
+ end
43
+
28
44
  describe '#lock' do
29
45
  it 'locks a resource when it is available' do
30
46
  send_command('locker resource create foobar')
@@ -175,7 +191,8 @@ describe Lita::Handlers::Locker, lita_handler: true do
175
191
  send_command('locker label create foobar')
176
192
  send_command('locker label create bazbat')
177
193
  send_command('locker label list')
178
- expect(replies.last).to eq('Label: bazbat')
194
+ expect(replies.include?('Label: foobar')).to eq(true)
195
+ expect(replies.include?('Label: bazbat')).to eq(true)
179
196
  end
180
197
  end
181
198
 
@@ -298,7 +315,8 @@ describe Lita::Handlers::Locker, lita_handler: true do
298
315
  send_command('locker resource create foobar')
299
316
  send_command('locker resource create bazbat')
300
317
  send_command('locker resource list')
301
- expect(replies.last).to eq('Resource: foobar, state: unlocked')
318
+ expect(replies.include?('Resource: foobar, state: unlocked')).to eq(true)
319
+ expect(replies.include?('Resource: bazbat, state: unlocked')).to eq(true)
302
320
  end
303
321
  end
304
322
 
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: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Sigler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-17 00:00:00.000000000 Z
11
+ date: 2014-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: 3.0.0.beta2
61
+ version: 3.0.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: 3.0.0.beta2
68
+ version: 3.0.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement