companies-house-gateway 0.3.10 → 0.3.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -3
- data/CHANGELOG.md +5 -0
- data/README.md +1 -3
- data/companies_house_gateway.gemspec +2 -2
- data/lib/companies_house_gateway/validations.rb +2 -1
- data/lib/companies_house_gateway/version.rb +1 -1
- data/spec/client_spec.rb +8 -2
- data/spec/companies_house_gateway_spec.rb +7 -3
- data/spec/request_spec.rb +13 -9
- data/spec/shared_examples.rb +4 -4
- data/spec/spec_helper.rb +6 -1
- data/spec/validations_spec.rb +27 -22
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04cf38078081525f799988721cdbf1b56edeff84
|
4
|
+
data.tar.gz: 7d930409cc38db5bb0ce57180953fc4d0b0f2752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 216bc972349999e778674cb0fe63d4ef2af2aef28059f805ced622099a1db751d594222d20ee31114c0ed3d185505b7726ce7063e16e58d297115abf275a0103
|
7
|
+
data.tar.gz: a27e4551ee2a88f49006a1e1f80c35617d70fdff0ceada8c263c35a806fa6e58b67c73ca4302d9cffdfe8deb080336f2198a6ca88f925a0c2b0ac65e2a50addc
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# Companies House Gateway
|
2
2
|
|
3
|
-
Simple Ruby Gem for interacting with the Companies House XML Gateway API.
|
4
|
-
the XML submissions and responses required so you can deal with Ruby hashes
|
5
|
-
instead.
|
3
|
+
Simple Ruby Gem for interacting with the [Companies House XML Gateway API](http://xmlgw.companieshouse.gov.uk/).
|
6
4
|
|
7
5
|
[![Gem Version](https://badge.fury.io/rb/companies-house-gateway.svg)](http://badge.fury.io/rb/companies-house-gateway)
|
8
6
|
[![Build Status](https://travis-ci.org/gocardless/companies-house-gateway-ruby.svg?branch=master)](https://travis-ci.org/gocardless/companies-house-gateway-ruby)
|
@@ -5,8 +5,8 @@ Gem::Specification.new do |gem|
|
|
5
5
|
gem.add_runtime_dependency 'multi_xml', '~> 0.5.1'
|
6
6
|
gem.add_runtime_dependency 'nokogiri', '~> 1.4'
|
7
7
|
|
8
|
-
gem.add_development_dependency 'rspec', '~>
|
9
|
-
gem.add_development_dependency 'webmock', '~> 1.
|
8
|
+
gem.add_development_dependency 'rspec', '~> 3.0'
|
9
|
+
gem.add_development_dependency 'webmock', '~> 1.21'
|
10
10
|
|
11
11
|
gem.authors = ['Grey Baker']
|
12
12
|
gem.description = %q{Ruby wrapper for the Companies House XML Gateway}
|
@@ -69,6 +69,7 @@ module CompaniesHouseGateway
|
|
69
69
|
def self.clean_company_number(number)
|
70
70
|
return unless number
|
71
71
|
number = number.to_s.strip # remove whitespace
|
72
|
+
number = number.upcase # upcase any prefixes
|
72
73
|
|
73
74
|
# 0-pad 5 or 7 digit registration number
|
74
75
|
if number.match /\A(\D{2})(\d{5})\z/
|
@@ -94,4 +95,4 @@ module CompaniesHouseGateway
|
|
94
95
|
raise InvalidRequestError.new(msg, param)
|
95
96
|
end
|
96
97
|
end
|
97
|
-
end
|
98
|
+
end
|
data/spec/client_spec.rb
CHANGED
@@ -19,7 +19,10 @@ describe CompaniesHouseGateway::Client do
|
|
19
19
|
before { configure_companies_house_gateway }
|
20
20
|
subject(:new_client) { CompaniesHouseGateway::Client.new }
|
21
21
|
|
22
|
-
|
22
|
+
describe '#config' do
|
23
|
+
subject { super().config }
|
24
|
+
it { should_not == CompaniesHouseGateway.config }
|
25
|
+
end
|
23
26
|
it "has the attributes of the global config" do
|
24
27
|
new_client.config[:sender_id] ==
|
25
28
|
CompaniesHouseGateway.config[:sender_id]
|
@@ -30,7 +33,10 @@ describe CompaniesHouseGateway::Client do
|
|
30
33
|
before { config[:first_name] = "test" }
|
31
34
|
subject(:new_client) { CompaniesHouseGateway::Client.new(config) }
|
32
35
|
|
33
|
-
|
36
|
+
describe '#config' do
|
37
|
+
subject { super().config }
|
38
|
+
it { should_not == config }
|
39
|
+
end
|
34
40
|
it "has the attributes of the passed in config" do
|
35
41
|
new_client.config[:sender_id] == config[:sender_id]
|
36
42
|
end
|
@@ -5,8 +5,8 @@ shared_examples "it delegates to the client" do |method_name|
|
|
5
5
|
let(:data) { "data" }
|
6
6
|
|
7
7
|
it "delegates #{method_name} to the client" do
|
8
|
-
CompaniesHouseGateway::Client.
|
9
|
-
|
8
|
+
expect_any_instance_of(CompaniesHouseGateway::Client).
|
9
|
+
to receive(method_name).with(data)
|
10
10
|
CompaniesHouseGateway.send(method_name, data)
|
11
11
|
end
|
12
12
|
end
|
@@ -21,7 +21,11 @@ describe CompaniesHouseGateway do
|
|
21
21
|
before do
|
22
22
|
CompaniesHouseGateway.configure { |config| config[key] = key }
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
|
+
describe [key] do
|
26
|
+
subject { super()[key] }
|
27
|
+
it { should == key }
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
data/spec/request_spec.rb
CHANGED
@@ -25,14 +25,14 @@ describe CompaniesHouseGateway::Request do
|
|
25
25
|
let(:xsd) { Nokogiri::XML::Schema(xml_schema) }
|
26
26
|
|
27
27
|
it "generates a valid XML request" do
|
28
|
-
xsd.validate(request_xml).
|
28
|
+
expect(xsd.validate(request_xml)).to eq([])
|
29
29
|
end
|
30
30
|
|
31
31
|
context "with an email address" do
|
32
32
|
before { config[:email] = "grey@gocardless.com" }
|
33
33
|
|
34
34
|
it "generates a valid XML request" do
|
35
|
-
xsd.validate(request_xml).
|
35
|
+
expect(xsd.validate(request_xml)).to eq([])
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -42,18 +42,22 @@ describe CompaniesHouseGateway::Request do
|
|
42
42
|
|
43
43
|
it "makes a get request" do
|
44
44
|
perform_check
|
45
|
-
a_request(:post, config[:api_endpoint]).
|
45
|
+
expect(a_request(:post, config[:api_endpoint])).to have_been_made
|
46
46
|
end
|
47
47
|
|
48
48
|
context "when the config[:raw] is true" do
|
49
49
|
before { config[:raw] = true }
|
50
|
-
it {
|
51
|
-
|
50
|
+
it { is_expected.to be_a Faraday::Response }
|
51
|
+
|
52
|
+
describe '#body' do
|
53
|
+
subject { super().body }
|
54
|
+
it { should be_a String }
|
55
|
+
end
|
52
56
|
end
|
53
57
|
|
54
58
|
context "when the config[:raw] is false" do
|
55
|
-
it {
|
56
|
-
it {
|
59
|
+
it { is_expected.to be_a Hash }
|
60
|
+
it { is_expected.to include "GovTalkMessage" }
|
57
61
|
|
58
62
|
context "errors" do
|
59
63
|
context "500" do
|
@@ -80,8 +84,8 @@ describe CompaniesHouseGateway::Request do
|
|
80
84
|
it "wraps the error" do
|
81
85
|
expect { perform_check }.
|
82
86
|
to raise_error CompaniesHouseGateway::APIError do |error|
|
83
|
-
error.error_code.
|
84
|
-
error.message.
|
87
|
+
expect(error.error_code).to eq("604")
|
88
|
+
expect(error.message).to eq("Error text")
|
85
89
|
end
|
86
90
|
end
|
87
91
|
end
|
data/spec/shared_examples.rb
CHANGED
@@ -35,7 +35,7 @@ shared_examples 'it generates valid xml' do
|
|
35
35
|
let(:xsd) { Nokogiri::XML::Schema.from_document(xsd_doc) }
|
36
36
|
|
37
37
|
it "generates a valid XML request" do
|
38
|
-
xsd.validate(request_xml).
|
38
|
+
expect(xsd.validate(request_xml)).to eq([])
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -51,7 +51,7 @@ shared_examples 'it returns only the body of the response' do
|
|
51
51
|
before { stub_request(:post, config[:api_endpoint]).to_return(response) }
|
52
52
|
subject { described_class.new(client).perform(check_data) }
|
53
53
|
|
54
|
-
it {
|
55
|
-
it {
|
56
|
-
it {
|
54
|
+
it { is_expected.to be_a Hash }
|
55
|
+
it { is_expected.not_to be_empty }
|
56
|
+
it { is_expected.not_to include klass }
|
57
57
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
require 'companies_house_gateway'
|
2
2
|
require 'webmock/rspec'
|
3
3
|
require 'shared_examples'
|
4
|
-
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.mock_with(:rspec) { |mocks| mocks.verify_partial_doubles = true }
|
7
|
+
config.raise_errors_for_deprecations!
|
8
|
+
config.include WebMock::API
|
9
|
+
end
|
5
10
|
|
6
11
|
def configure_companies_house_gateway
|
7
12
|
CompaniesHouseGateway.configure { |config| config[:sender_id] = "Grey" }
|
data/spec/validations_spec.rb
CHANGED
@@ -6,12 +6,12 @@ describe CompaniesHouseGateway::Validations do
|
|
6
6
|
|
7
7
|
context "without a string" do
|
8
8
|
let(:string) { nil }
|
9
|
-
it {
|
9
|
+
it { is_expected.to eq(nil) }
|
10
10
|
end
|
11
11
|
|
12
12
|
context "with a short string" do
|
13
13
|
let(:string) { "A" * 160 }
|
14
|
-
it {
|
14
|
+
it { is_expected.to eq(string) }
|
15
15
|
end
|
16
16
|
|
17
17
|
context "with a long string" do
|
@@ -28,17 +28,17 @@ describe CompaniesHouseGateway::Validations do
|
|
28
28
|
|
29
29
|
context "without a date" do
|
30
30
|
let(:date) { nil }
|
31
|
-
it {
|
31
|
+
it { is_expected.to eq(nil) }
|
32
32
|
end
|
33
33
|
|
34
34
|
context "with a date object" do
|
35
35
|
let(:date) { Date.parse("01/01/2000") }
|
36
|
-
it {
|
36
|
+
it { is_expected.to eq(date.strftime("%d/%m/%Y")) }
|
37
37
|
end
|
38
38
|
|
39
39
|
context "with a parseable string" do
|
40
40
|
let(:date) { "01-01-2000" }
|
41
|
-
it {
|
41
|
+
it { is_expected.to eq("01/01/2000") }
|
42
42
|
end
|
43
43
|
|
44
44
|
context "with a load of rubbish" do
|
@@ -55,12 +55,12 @@ describe CompaniesHouseGateway::Validations do
|
|
55
55
|
|
56
56
|
context "without a boolean" do
|
57
57
|
let(:bool) { nil }
|
58
|
-
it {
|
58
|
+
it { is_expected.to eq(nil) }
|
59
59
|
end
|
60
60
|
|
61
61
|
context "with a boolean" do
|
62
62
|
let(:bool) { true }
|
63
|
-
it {
|
63
|
+
it { is_expected.to eq(bool) }
|
64
64
|
end
|
65
65
|
|
66
66
|
context "with a load of rubbish" do
|
@@ -77,17 +77,17 @@ describe CompaniesHouseGateway::Validations do
|
|
77
77
|
|
78
78
|
context "without a number" do
|
79
79
|
let(:number) { nil }
|
80
|
-
it {
|
80
|
+
it { is_expected.to eq(nil) }
|
81
81
|
end
|
82
82
|
|
83
83
|
context "with a number" do
|
84
84
|
let(:number) { 9 }
|
85
|
-
it {
|
85
|
+
it { is_expected.to eq(number.to_s) }
|
86
86
|
end
|
87
87
|
|
88
88
|
context "with a string that looks like a number" do
|
89
89
|
let(:number) { "91" }
|
90
|
-
it {
|
90
|
+
it { is_expected.to eq(number) }
|
91
91
|
end
|
92
92
|
|
93
93
|
context "with a load of rubbish" do
|
@@ -104,17 +104,17 @@ describe CompaniesHouseGateway::Validations do
|
|
104
104
|
|
105
105
|
context "without a data_set" do
|
106
106
|
let(:data_set) { nil }
|
107
|
-
it {
|
107
|
+
it { is_expected.to eq(nil) }
|
108
108
|
end
|
109
109
|
|
110
110
|
context "with a valid symbol" do
|
111
111
|
let(:data_set) { :live }
|
112
|
-
it {
|
112
|
+
it { is_expected.to eq("LIVE") }
|
113
113
|
end
|
114
114
|
|
115
115
|
context "with a valid string" do
|
116
116
|
let(:data_set) { "LIVE" }
|
117
|
-
it {
|
117
|
+
it { is_expected.to eq("LIVE") }
|
118
118
|
end
|
119
119
|
|
120
120
|
context "with a load of rubbish" do
|
@@ -133,17 +133,17 @@ describe CompaniesHouseGateway::Validations do
|
|
133
133
|
|
134
134
|
context "without an officer_type" do
|
135
135
|
let(:officer_type) { nil }
|
136
|
-
it {
|
136
|
+
it { is_expected.to eq(nil) }
|
137
137
|
end
|
138
138
|
|
139
139
|
context "with a valid symbol" do
|
140
140
|
let(:officer_type) { :dis }
|
141
|
-
it {
|
141
|
+
it { is_expected.to eq("DIS") }
|
142
142
|
end
|
143
143
|
|
144
144
|
context "with a valid string" do
|
145
145
|
let(:officer_type) { "DIS" }
|
146
|
-
it {
|
146
|
+
it { is_expected.to eq("DIS") }
|
147
147
|
end
|
148
148
|
|
149
149
|
context "with a load of rubbish" do
|
@@ -196,28 +196,33 @@ describe CompaniesHouseGateway::Validations do
|
|
196
196
|
context "allows a company number starting with #{prefix}" do
|
197
197
|
prefix = (prefix == '\d\d') ? '07' : prefix
|
198
198
|
let(:number) { "#{prefix}112233" }
|
199
|
-
it {
|
199
|
+
it { is_expected.to eq("#{prefix}112233") }
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
203
|
context "does not 0-pads 8 digit registration numbers" do
|
204
204
|
let(:number) { "17495895" }
|
205
|
-
it {
|
205
|
+
it { is_expected.to eq("17495895") }
|
206
206
|
end
|
207
207
|
|
208
208
|
context "0-pads 7 digit registration numbers" do
|
209
209
|
let(:number) { "7495895" }
|
210
|
-
it {
|
210
|
+
it { is_expected.to eq("07495895") }
|
211
211
|
end
|
212
212
|
|
213
213
|
context "0-pads 5 digit NI registration numbers" do
|
214
214
|
let(:number) { "NI27768" }
|
215
|
-
it {
|
215
|
+
it { is_expected.to eq("NI027768") }
|
216
216
|
end
|
217
217
|
|
218
|
-
context "does not 0-
|
218
|
+
context "does not 0-pad 6 digit NI registration numbers" do
|
219
219
|
let(:number) { "NI127768" }
|
220
|
-
it {
|
220
|
+
it { is_expected.to eq("NI127768") }
|
221
|
+
end
|
222
|
+
|
223
|
+
context "upcases prefixes" do
|
224
|
+
let(:number) { "sc127768" }
|
225
|
+
it { is_expected.to eq("SC127768") }
|
221
226
|
end
|
222
227
|
end
|
223
228
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: companies-house-gateway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grey Baker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday_middleware
|
@@ -64,28 +64,28 @@ dependencies:
|
|
64
64
|
requirements:
|
65
65
|
- - ~>
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
67
|
+
version: '3.0'
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - ~>
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
74
|
+
version: '3.0'
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: webmock
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - ~>
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 1.
|
81
|
+
version: '1.21'
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - ~>
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 1.
|
88
|
+
version: '1.21'
|
89
89
|
description: Ruby wrapper for the Companies House XML Gateway
|
90
90
|
email:
|
91
91
|
- grey@gocardless.com
|