validocno 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/validocno/validator.rb +7 -3
- data/lib/validocno/version.rb +1 -1
- data/lib/validocno.rb +2 -2
- data/spec/validator_spec.rb +26 -6
- data/spec/validocno_spec.rb +25 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 1c3dcc97a6fc2dbf8e31d24f40a1ccd292f3e006
|
4
|
-
data.tar.gz: 2d0e220cae2235931d5fe2f4ae1aeebef279b9bf
|
5
2
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 185b383a8583ca4c0bb9d13dc31f130c213e0a34fb39030a9eb4e6810997022aec3069e76303eb95a02058bb19e45add7f95547a8408c0f05494b1f1deed02b8
|
4
|
+
data.tar.gz: 726084ea929a160371b3a2e844a0d4b6c852c530d4bbf6d631ee3d9fc64852c39cffffc04d9457aa9fff02a952ac9da6640e983dcc722809914eac15126358f2
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: e9ecae61688b852b69d897fa32600a8139402e4d
|
7
|
+
data.tar.gz: dacbe802188d7d89b01a6e2d94ca6a2684ee8bf6
|
data/lib/validocno/validator.rb
CHANGED
@@ -44,9 +44,13 @@ module Validocno
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
47
|
+
def validate
|
48
|
+
is_valid = response_string.match(response_strings[:valid]) ? true : false
|
49
|
+
|
50
|
+
{
|
51
|
+
:valid => is_valid,
|
52
|
+
:message => response_string
|
53
|
+
}
|
50
54
|
end
|
51
55
|
|
52
56
|
def response_strings
|
data/lib/validocno/version.rb
CHANGED
data/lib/validocno.rb
CHANGED
@@ -11,8 +11,8 @@ require 'validocno/version'
|
|
11
11
|
require 'validocno/http_client'
|
12
12
|
|
13
13
|
module Validocno
|
14
|
-
def self.
|
14
|
+
def self.validate(doc_number)
|
15
15
|
validator = Validocno::Validator.new(doc_number)
|
16
|
-
validator.
|
16
|
+
validator.validate
|
17
17
|
end
|
18
18
|
end
|
data/spec/validator_spec.rb
CHANGED
@@ -20,16 +20,36 @@ describe Validocno::Validator do
|
|
20
20
|
|
21
21
|
end
|
22
22
|
|
23
|
-
describe '#
|
23
|
+
describe '#validate' do
|
24
24
|
let(:invalid_doc_number) { 'A1234567890' }
|
25
|
-
let(:
|
25
|
+
let(:expired_doc_number) { 'A0111856' }
|
26
|
+
let(:validator_with_invalid) { Validocno::Validator.new(invalid_doc_number) }
|
27
|
+
let(:validator_with_expired) { Validocno::Validator.new(expired_doc_number) }
|
26
28
|
|
27
|
-
it 'returns
|
28
|
-
expect(validator).to
|
29
|
+
it 'returns hash with :valid and :message keys' do
|
30
|
+
expect(validator.validate).to have_key(:valid)
|
31
|
+
expect(validator.validate).to have_key(:message)
|
29
32
|
end
|
30
33
|
|
31
|
-
it '
|
32
|
-
expect(
|
34
|
+
it 'validates document with valid number' do
|
35
|
+
expect(validator.validate).to include(
|
36
|
+
:valid => true,
|
37
|
+
:message => "Dokument #{doc_number} on kehtiv."
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'validates expired document' do
|
42
|
+
expect(validator_with_expired.validate).to include(
|
43
|
+
:valid => false,
|
44
|
+
:message => "Dokument #{expired_doc_number} on kehtetu."
|
45
|
+
)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'validates document with invalid number' do
|
49
|
+
expect(validator_with_invalid.validate).to include(
|
50
|
+
:valid => false,
|
51
|
+
:message => "Dokumenti #{invalid_doc_number} ei ole välja antud."
|
52
|
+
)
|
33
53
|
end
|
34
54
|
end
|
35
55
|
end
|
data/spec/validocno_spec.rb
CHANGED
@@ -1,20 +1,39 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Validocno do
|
4
|
-
describe '.
|
4
|
+
describe '.validate' do
|
5
5
|
let(:valid_doc_number) { 'A1234567' }
|
6
|
+
let(:expired_doc_number) { 'A0111856' }
|
6
7
|
let(:invalid_doc_number) { 'A1234567890' }
|
7
8
|
|
8
|
-
it 'returns
|
9
|
-
expect(Validocno.
|
9
|
+
it 'returns hash with :valid and :message keys' do
|
10
|
+
expect(Validocno.validate(valid_doc_number)).to have_key(:valid)
|
11
|
+
expect(Validocno.validate(valid_doc_number)).to have_key(:message)
|
10
12
|
end
|
11
13
|
|
12
|
-
it '
|
13
|
-
expect(Validocno.
|
14
|
+
it 'validates document with valid number' do
|
15
|
+
expect(Validocno.validate(valid_doc_number)).to include(
|
16
|
+
:valid => true,
|
17
|
+
:message => "Dokument #{valid_doc_number} on kehtiv."
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'validates expired document' do
|
22
|
+
expect(Validocno.validate(expired_doc_number)).to include(
|
23
|
+
:valid => false,
|
24
|
+
:message => "Dokument #{expired_doc_number} on kehtetu."
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'validates document with invalid number' do
|
29
|
+
expect(Validocno.validate(invalid_doc_number)).to include(
|
30
|
+
:valid => false,
|
31
|
+
:message => "Dokumenti #{invalid_doc_number} ei ole välja antud."
|
32
|
+
)
|
14
33
|
end
|
15
34
|
|
16
35
|
it 'raises an error without a document number' do
|
17
|
-
expect { Validocno.
|
36
|
+
expect { Validocno.validate }.to raise_error(ArgumentError)
|
18
37
|
end
|
19
38
|
end
|
20
39
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validocno
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Pakk
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2014-12-
|
12
|
+
date: 2014-12-04 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
requirement: &id001 !ruby/object:Gem::Requirement
|