open-charities 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/open_charities/request.rb +3 -2
- data/lib/open_charities/version.rb +1 -1
- data/spec/open_charities/request_spec.rb +12 -21
- metadata +2 -2
data/README.md
CHANGED
@@ -25,8 +25,9 @@ module OpenCharities
|
|
25
25
|
def validate(reg_number)
|
26
26
|
number = reg_number.to_s.strip
|
27
27
|
|
28
|
-
# match 7
|
29
|
-
|
28
|
+
# match any 6/7 digit number OR 6/7 digit number followed by a dash and
|
29
|
+
# another 1 or 2 numbers
|
30
|
+
charities_regex = /\A\d{6,7}\z|\A\d{6,7}\-\d{1,2}\z/
|
30
31
|
|
31
32
|
msg = "#{number} is not a valid UK charity registration number"
|
32
33
|
raise InvalidRegistration.new(msg) unless number =~ charities_regex
|
@@ -6,16 +6,12 @@ describe OpenCharities::Request do
|
|
6
6
|
|
7
7
|
describe "#new" do
|
8
8
|
context "throws an exception" do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
it "that's too long" do
|
16
|
-
expect {
|
17
|
-
subject.new "12345678"
|
18
|
-
}.to raise_exception OpenCharities::InvalidRegistration
|
9
|
+
%W(12345 12345678 #{"123 ABC"} #{"123?!56"}).each do |n|
|
10
|
+
specify do
|
11
|
+
expect {
|
12
|
+
subject.new n
|
13
|
+
}.to raise_exception OpenCharities::InvalidRegistration
|
14
|
+
end
|
19
15
|
end
|
20
16
|
|
21
17
|
it "that's nil" do
|
@@ -23,20 +19,15 @@ describe OpenCharities::Request do
|
|
23
19
|
subject.new nil
|
24
20
|
}.to raise_exception OpenCharities::InvalidRegistration
|
25
21
|
end
|
22
|
+
end
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
it "that contains non alphanumeric chars" do
|
34
|
-
expect {
|
35
|
-
subject.new "1234?456"
|
36
|
-
}.to raise_exception OpenCharities::InvalidRegistration
|
24
|
+
context 'is valid' do
|
25
|
+
%w(123456 1234567 123456-1 1234567-1 123456-12 1234567-12).each do |n|
|
26
|
+
specify do
|
27
|
+
expect { subject.new(n) }.to_not raise_exception
|
28
|
+
end
|
37
29
|
end
|
38
30
|
end
|
39
|
-
|
40
31
|
end
|
41
32
|
|
42
33
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open-charities
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|