zss 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/lib/zss/permit.rb +19 -0
- data/lib/zss/require.rb +21 -0
- data/lib/zss/validate.rb +19 -0
- data/lib/zss/version.rb +1 -1
- data/spec/unit/permit_spec.rb +32 -0
- data/spec/unit/require_spec.rb +38 -0
- data/spec/unit/validate_spec.rb +41 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ee2c88c981357c17dd093d250bf59d3a875cd6f
|
4
|
+
data.tar.gz: 32baca82197034c6984b7077932f9f490cab5d88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 523023fa07cff6cc0f1f1bd8edfab53c0a937adc49d90ce1b80b81027354ad0398e75ae568ec3a28da2324b602a9294b7b56420319fa669b206999f386f5365b
|
7
|
+
data.tar.gz: 117cee817892be99ef23b0e4fc5b02fae3934b043ed1f2278959b32537a697aa7742cf056f6d9da4eb50f16f72879ecf0b4be3b0616fa7f88785852684f4c240
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
zss (0.3.
|
4
|
+
zss (0.3.3)
|
5
5
|
activesupport (~> 4.2)
|
6
6
|
daemons (~> 1.1)
|
7
7
|
em-zeromq (~> 0.5)
|
@@ -29,7 +29,7 @@ GEM
|
|
29
29
|
codeclimate-test-reporter (0.4.6)
|
30
30
|
simplecov (>= 0.7.1, < 1.0.0)
|
31
31
|
coderay (1.1.0)
|
32
|
-
daemons (1.1
|
32
|
+
daemons (1.2.1)
|
33
33
|
diff-lcs (1.2.5)
|
34
34
|
docile (1.1.5)
|
35
35
|
em-zeromq (0.5.0)
|
@@ -78,9 +78,9 @@ GEM
|
|
78
78
|
simplecov-html (~> 0.9.0)
|
79
79
|
simplecov-html (0.9.0)
|
80
80
|
slop (3.6.0)
|
81
|
-
sucker_punch (1.
|
81
|
+
sucker_punch (1.4.0)
|
82
82
|
celluloid (~> 0.16.0)
|
83
|
-
thread_safe (0.3.
|
83
|
+
thread_safe (0.3.5)
|
84
84
|
timers (4.0.1)
|
85
85
|
hitimes
|
86
86
|
tzinfo (1.2.2)
|
data/lib/zss/permit.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module ZSS
|
2
|
+
module Permit
|
3
|
+
|
4
|
+
class Permitter
|
5
|
+
|
6
|
+
def self.permit! params, attributes
|
7
|
+
params.keep_if do |k, _|
|
8
|
+
Array(attributes).include? k.to_sym
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def permit! params, *attributes
|
15
|
+
Permitter.permit!(params, attributes)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
data/lib/zss/require.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module ZSS
|
2
|
+
module Require
|
3
|
+
|
4
|
+
class Requirer
|
5
|
+
|
6
|
+
def self.requires params, attributes
|
7
|
+
Array(attributes).each do |attribute|
|
8
|
+
unless params[attribute].present?
|
9
|
+
raise ZSS::Error.new(400, "Invalid parameter '#{attribute}'")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def requires params, *attributes
|
17
|
+
Requirer.requires(params, attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/zss/validate.rb
ADDED
data/lib/zss/version.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'zss/permit'
|
3
|
+
|
4
|
+
describe ZSS::Permit do
|
5
|
+
|
6
|
+
let!(:params) do
|
7
|
+
{ arg1: 'somevalue', arg2: 'someothervalue' }
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'filters all non permitted params' do
|
11
|
+
ZSS::Permit::Permitter.permit!(params, [ :arg1 ])
|
12
|
+
expect(
|
13
|
+
params
|
14
|
+
).to eq({ arg1: 'somevalue' })
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can be included' do
|
18
|
+
|
19
|
+
class SomeClass
|
20
|
+
include ZSS::Permit
|
21
|
+
end
|
22
|
+
|
23
|
+
testObject = SomeClass.new
|
24
|
+
testObject.permit!(params, :arg1)
|
25
|
+
|
26
|
+
expect(
|
27
|
+
params
|
28
|
+
).to eq({ arg1: 'somevalue' })
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'zss/require'
|
3
|
+
|
4
|
+
describe ZSS::Require do
|
5
|
+
|
6
|
+
it 'raises 400 if any attributes are missing' do
|
7
|
+
|
8
|
+
expect{
|
9
|
+
ZSS::Require::Requirer.requires({ arg1: 'somevalue' }, [ :arg1, :arg2 ])
|
10
|
+
}.to raise_error(ZSS::Error) do |e|
|
11
|
+
expect(e.code).to eq(400)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'accepts when all params are set' do
|
17
|
+
expect(
|
18
|
+
ZSS::Require::Requirer.requires({ arg1: 'somevalue', arg2: 'someothervalue' }, [ :arg1, :arg2 ])
|
19
|
+
).to be
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'can be included' do
|
23
|
+
|
24
|
+
class SomeClass
|
25
|
+
include ZSS::Require
|
26
|
+
end
|
27
|
+
|
28
|
+
testObject = SomeClass.new
|
29
|
+
|
30
|
+
expect{
|
31
|
+
testObject.requires({ arg1: 'somevalue' }, [ :arg1, :arg2 ])
|
32
|
+
}.to raise_error(ZSS::Error) do |e|
|
33
|
+
expect(e.code).to eq(400)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'zss/validate'
|
3
|
+
|
4
|
+
describe ZSS::Validate do
|
5
|
+
|
6
|
+
it 'accepts a valid uri' do
|
7
|
+
|
8
|
+
expect(ZSS::Validate::Validator.is_valid_uri?('https://clubjudge.com')).to be
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'denies an inclomplete uri' do
|
13
|
+
|
14
|
+
expect(ZSS::Validate::Validator.is_valid_uri?('www.sapo.pt')).not_to be
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'denies an erroneous url' do
|
19
|
+
expect(URI).to receive(:parse).and_raise(StandardError)
|
20
|
+
expect(ZSS::Validate::Validator.is_valid_uri?('somestring')).not_to be
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'denies an invalid uri' do
|
24
|
+
|
25
|
+
expect(ZSS::Validate::Validator.is_valid_uri?('some1nval/dUrl')).not_to be
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'can be included' do
|
30
|
+
|
31
|
+
class SomeClass
|
32
|
+
include ZSS::Validate
|
33
|
+
end
|
34
|
+
|
35
|
+
testObject = SomeClass.new
|
36
|
+
|
37
|
+
expect(testObject.is_valid_uri?('https://clubjudge.com')).to be
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pedro Januário
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -232,10 +232,13 @@ files:
|
|
232
232
|
- lib/zss/message/message_address.rb
|
233
233
|
- lib/zss/message/message_type.rb
|
234
234
|
- lib/zss/message/smi.rb
|
235
|
+
- lib/zss/permit.rb
|
236
|
+
- lib/zss/require.rb
|
235
237
|
- lib/zss/router.rb
|
236
238
|
- lib/zss/runner.rb
|
237
239
|
- lib/zss/service.rb
|
238
240
|
- lib/zss/socket.rb
|
241
|
+
- lib/zss/validate.rb
|
239
242
|
- lib/zss/version.rb
|
240
243
|
- spec/integration/client_spec.rb
|
241
244
|
- spec/integration/service_spec.rb
|
@@ -247,9 +250,12 @@ files:
|
|
247
250
|
- spec/unit/error_spec.rb
|
248
251
|
- spec/unit/message_address_spec.rb
|
249
252
|
- spec/unit/message_spec.rb
|
253
|
+
- spec/unit/permit_spec.rb
|
254
|
+
- spec/unit/require_spec.rb
|
250
255
|
- spec/unit/router_spec.rb
|
251
256
|
- spec/unit/service_spec.rb
|
252
257
|
- spec/unit/socket_spec.rb
|
258
|
+
- spec/unit/validate_spec.rb
|
253
259
|
- zss.gemspec
|
254
260
|
homepage: https://github.com/pjanuario/zmq-service-suite-ruby
|
255
261
|
licenses:
|
@@ -289,6 +295,9 @@ test_files:
|
|
289
295
|
- spec/unit/error_spec.rb
|
290
296
|
- spec/unit/message_address_spec.rb
|
291
297
|
- spec/unit/message_spec.rb
|
298
|
+
- spec/unit/permit_spec.rb
|
299
|
+
- spec/unit/require_spec.rb
|
292
300
|
- spec/unit/router_spec.rb
|
293
301
|
- spec/unit/service_spec.rb
|
294
302
|
- spec/unit/socket_spec.rb
|
303
|
+
- spec/unit/validate_spec.rb
|