callcredit 0.3.4 → 0.3.5
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/CHANGELOG.md +4 -0
- data/lib/callcredit/validations.rb +13 -9
- data/lib/callcredit/version.rb +1 -1
- data/spec/validations_spec.rb +9 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa5511f62db44e4945ee93b3f8be5bdc295ee064
|
4
|
+
data.tar.gz: 4cee4c1eaca735897d678190311dc9ff62383aab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b63ca88889c45fba9f6369c647e54168b266563c47f237230563992fe3e348b0e2d60dc0f5cada2d6b0e8e887e960ed560a2fd5f15ea0ce4df261258e25dab8
|
7
|
+
data.tar.gz: e4e06bc0571ce0f04c5277843330184e73f70333024253007e32c06ea8533a22470ef011b7e417d8d172717047ad9debdbe1d11f557fb3f2166cc7a0d2efaf91
|
data/CHANGELOG.md
CHANGED
@@ -4,12 +4,12 @@ module Callcredit
|
|
4
4
|
module Validations
|
5
5
|
|
6
6
|
VALIDATIONS = {
|
7
|
-
date_of_birth:
|
8
|
-
title:
|
9
|
-
first_name:
|
10
|
-
last_name:
|
11
|
-
middle_names:
|
12
|
-
postcode:
|
7
|
+
date_of_birth: ->(value) { clean_date_of_birth(value) },
|
8
|
+
title: ->(value) { value || "Unknown" },
|
9
|
+
first_name: ->(value) { clean_first_name(value) },
|
10
|
+
last_name: ->(value) { clean_last_name(value) },
|
11
|
+
middle_names: ->(value) { clean_middle_names(value) },
|
12
|
+
postcode: ->(value) { clean_postcode(value) }
|
13
13
|
}
|
14
14
|
|
15
15
|
def self.clean_param(key, value)
|
@@ -18,6 +18,7 @@ module Callcredit
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.clean_date_of_birth(date_of_birth)
|
21
|
+
return unless date_of_birth
|
21
22
|
date_of_birth = Date.parse(date_of_birth) if date_of_birth.is_a? String
|
22
23
|
date_of_birth.strftime("%d/%m/%Y")
|
23
24
|
rescue
|
@@ -25,13 +26,15 @@ module Callcredit
|
|
25
26
|
end
|
26
27
|
|
27
28
|
def self.clean_first_name(name)
|
28
|
-
|
29
|
+
return unless name
|
30
|
+
name = name.to_ascii
|
29
31
|
input_error(:first_name, name) unless name =~ /\A[a-z A-Z'-]{1,30}\z/
|
30
32
|
name
|
31
33
|
end
|
32
34
|
|
33
35
|
def self.clean_last_name(name)
|
34
|
-
|
36
|
+
return unless name
|
37
|
+
name = name.to_ascii
|
35
38
|
input_error(:last_name, name) unless name =~ /\A[a-z A-Z'-]{1,30}\z/
|
36
39
|
name
|
37
40
|
end
|
@@ -44,7 +47,8 @@ module Callcredit
|
|
44
47
|
end
|
45
48
|
|
46
49
|
def self.clean_postcode(postcode)
|
47
|
-
|
50
|
+
return unless postcode
|
51
|
+
postcode = postcode.upcase.strip
|
48
52
|
input_error(:postcode, postcode) unless postcode =~ /\A[A-Z 0-9]{5,8}\z/
|
49
53
|
postcode
|
50
54
|
end
|
data/lib/callcredit/version.rb
CHANGED
data/spec/validations_spec.rb
CHANGED
@@ -16,6 +16,11 @@ describe Callcredit::Validations do
|
|
16
16
|
describe '#clean_date_of_birth' do
|
17
17
|
subject { Callcredit::Validations.clean_date_of_birth(date_of_birth) }
|
18
18
|
|
19
|
+
context "without a date of birth" do
|
20
|
+
let(:date_of_birth) { nil }
|
21
|
+
it { should == nil }
|
22
|
+
end
|
23
|
+
|
19
24
|
context "with a date object" do
|
20
25
|
let(:date_of_birth) { Date.parse("01/01/2000") }
|
21
26
|
it { should == date_of_birth.strftime("%d/%m/%Y") }
|
@@ -39,9 +44,7 @@ describe Callcredit::Validations do
|
|
39
44
|
|
40
45
|
context "without a first name" do
|
41
46
|
let(:first_name) { nil }
|
42
|
-
it
|
43
|
-
expect { subject }.to raise_error Callcredit::InvalidRequestError
|
44
|
-
end
|
47
|
+
it { should == nil }
|
45
48
|
end
|
46
49
|
|
47
50
|
context "with a simple first name" do
|
@@ -54,14 +57,14 @@ describe Callcredit::Validations do
|
|
54
57
|
it { should == "Grey" }
|
55
58
|
end
|
56
59
|
|
57
|
-
context "
|
60
|
+
context "with a very long first name" do
|
58
61
|
let(:first_name) { "A" * 31 }
|
59
62
|
it "raises an error" do
|
60
63
|
expect { subject }.to raise_error Callcredit::InvalidRequestError
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
64
|
-
context "
|
67
|
+
context "with a first name with numbers in it" do
|
65
68
|
let(:first_name) { "David the 3rd" }
|
66
69
|
it "raises an error" do
|
67
70
|
expect { subject }.to raise_error Callcredit::InvalidRequestError
|
@@ -83,9 +86,7 @@ describe Callcredit::Validations do
|
|
83
86
|
|
84
87
|
context "without a post code" do
|
85
88
|
let(:postcode) { nil }
|
86
|
-
it
|
87
|
-
expect { subject }.to raise_error Callcredit::InvalidRequestError
|
88
|
-
end
|
89
|
+
it { should == nil }
|
89
90
|
end
|
90
91
|
|
91
92
|
context "with a correct post code" do
|