defra_ruby_validators 2.5.0 → 2.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/lib/defra_ruby/validators/companies_house_number_validator.rb +2 -1
  3. data/lib/defra_ruby/validators/version.rb +1 -1
  4. metadata +22 -175
  5. data/spec/defra_ruby/validators/business_type_validator_spec.rb +0 -56
  6. data/spec/defra_ruby/validators/companies_house_number_validator_spec.rb +0 -124
  7. data/spec/defra_ruby/validators/companies_house_service_spec.rb +0 -98
  8. data/spec/defra_ruby/validators/configuration_spec.rb +0 -49
  9. data/spec/defra_ruby/validators/email_validator_spec.rb +0 -46
  10. data/spec/defra_ruby/validators/grid_reference_validator_spec.rb +0 -57
  11. data/spec/defra_ruby/validators/location_validator_spec.rb +0 -56
  12. data/spec/defra_ruby/validators/past_date_validator_spec.rb +0 -35
  13. data/spec/defra_ruby/validators/phone_number_validator_spec.rb +0 -59
  14. data/spec/defra_ruby/validators/position_validator_spec.rb +0 -47
  15. data/spec/defra_ruby/validators/token_validator_spec.rb +0 -45
  16. data/spec/defra_ruby/validators/true_false_validator_spec.rb +0 -37
  17. data/spec/defra_ruby/validators_spec.rb +0 -12
  18. data/spec/examples.txt +0 -189
  19. data/spec/spec_helper.rb +0 -87
  20. data/spec/support/defra_ruby_validators.rb +0 -16
  21. data/spec/support/helpers/text_generator.rb +0 -17
  22. data/spec/support/helpers/translator.rb +0 -15
  23. data/spec/support/i18n.rb +0 -8
  24. data/spec/support/pry.rb +0 -7
  25. data/spec/support/shared_examples/validators/characters_validator.rb +0 -29
  26. data/spec/support/shared_examples/validators/invalid_record.rb +0 -29
  27. data/spec/support/shared_examples/validators/length_validator.rb +0 -29
  28. data/spec/support/shared_examples/validators/presence_validator.rb +0 -29
  29. data/spec/support/shared_examples/validators/selection_validator.rb +0 -40
  30. data/spec/support/shared_examples/validators/valid_record.rb +0 -12
  31. data/spec/support/shared_examples/validators/validator.rb +0 -8
  32. data/spec/support/simplecov.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8964c61f339abf2c0d3a469cad34c7234caf819e1844f3968e04d85147cc67c4
4
- data.tar.gz: bf2ad073d11e02f698039b03286c1519ff01126d384119b8f3c0785b2c1cf6cd
3
+ metadata.gz: 3a8cefa4eee1eb9fcc363935f64760eb88aafd35d29ac09cfd3663105aafa3eb
4
+ data.tar.gz: 0dbc80e1d0c36fc4452257e6ade5377d83f04b860f9ec0375975526aca43f961
5
5
  SHA512:
6
- metadata.gz: f24569969b429ffd1c1d7db53c94420f47aa0b32538c0584403458ee4fdf45cb72a911341ef993c959a298a8256b94b3511867a54cb9fa098d04e4573547ee6a
7
- data.tar.gz: 4b40e37219533ce6c295b33b00c267c45550855790832f37f363db07f63d83c8d2a04cbfd4a8bf6f1762f52639f56888b614d741b13712614ed02fe0113cbad0
6
+ metadata.gz: 0417b991688a935460cbd8e96d28dd8d1496838d7aa5d56420f9a0e5ac701d652b278657a1a733c905e1f3b8ae6880e659b58071e90673af351224c9a3445ed2
7
+ data.tar.gz: 88fb21c5eb3ca1cc365ce4b52aeb8171540ec1cc5776b32cab5122fccb978215f46ea92ff13ceedde13fedd4b700d8f757a74db50f08e4e0e45e049c6ab2dfde
@@ -31,7 +31,8 @@ module DefraRuby
31
31
  end
32
32
 
33
33
  def format_is_valid?(record, attribute, value)
34
- return true if value.match?(VALID_COMPANIES_HOUSE_REGISTRATION_NUMBER_REGEX)
34
+ # All-zero values are invalid, despite matching the main regex
35
+ return true if value.match?(VALID_COMPANIES_HOUSE_REGISTRATION_NUMBER_REGEX) && !value.match(/^0+$/)
35
36
 
36
37
  add_validation_error(record, attribute, :invalid_format)
37
38
  false
@@ -2,6 +2,6 @@
2
2
 
3
3
  module DefraRuby
4
4
  module Validators
5
- VERSION = "2.5.0"
5
+ VERSION = "2.5.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defra_ruby_validators
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Defra
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-11 00:00:00.000000000 Z
11
+ date: 2023-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: os_map_ref
28
+ name: i18n
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: phonelib
42
+ name: matrix
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,21 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rest-client
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '2.0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '2.0'
69
- - !ruby/object:Gem::Dependency
70
- name: validates_email_format_of
56
+ name: os_map_ref
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
59
  - - ">="
@@ -81,55 +67,13 @@ dependencies:
81
67
  - !ruby/object:Gem::Version
82
68
  version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
- name: defra_ruby_style
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: dotenv
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: github_changelog_generator
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: i18n
70
+ name: phonelib
127
71
  requirement: !ruby/object:Gem::Requirement
128
72
  requirements:
129
73
  - - ">="
130
74
  - !ruby/object:Gem::Version
131
75
  version: '0'
132
- type: :development
76
+ type: :runtime
133
77
  prerelease: false
134
78
  version_requirements: !ruby/object:Gem::Requirement
135
79
  requirements:
@@ -137,75 +81,33 @@ dependencies:
137
81
  - !ruby/object:Gem::Version
138
82
  version: '0'
139
83
  - !ruby/object:Gem::Dependency
140
- name: pry-byebug
84
+ name: rest-client
141
85
  requirement: !ruby/object:Gem::Requirement
142
86
  requirements:
143
- - - ">="
87
+ - - "~>"
144
88
  - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
89
+ version: '2.0'
90
+ type: :runtime
147
91
  prerelease: false
148
92
  version_requirements: !ruby/object:Gem::Requirement
149
93
  requirements:
150
- - - ">="
94
+ - - "~>"
151
95
  - !ruby/object:Gem::Version
152
- version: '0'
96
+ version: '2.0'
153
97
  - !ruby/object:Gem::Dependency
154
- name: rake
98
+ name: validates_email_format_of
155
99
  requirement: !ruby/object:Gem::Requirement
156
100
  requirements:
157
101
  - - ">="
158
102
  - !ruby/object:Gem::Version
159
103
  version: '0'
160
- type: :development
104
+ type: :runtime
161
105
  prerelease: false
162
106
  version_requirements: !ruby/object:Gem::Requirement
163
107
  requirements:
164
108
  - - ">="
165
109
  - !ruby/object:Gem::Version
166
110
  version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: rspec
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: '3.0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: '3.0'
181
- - !ruby/object:Gem::Dependency
182
- name: simplecov
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: 0.17.1
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - "~>"
193
- - !ruby/object:Gem::Version
194
- version: 0.17.1
195
- - !ruby/object:Gem::Dependency
196
- name: webmock
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: '3.4'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: '3.4'
209
111
  description: Package of validations commonly used in Defra Rails based digital services
210
112
  email:
211
113
  - alan.cruikshanks@environment-agency.gov.uk
@@ -249,40 +151,13 @@ files:
249
151
  - lib/defra_ruby/validators/true_false_validator.rb
250
152
  - lib/defra_ruby/validators/version.rb
251
153
  - lib/defra_ruby_validators.rb
252
- - spec/defra_ruby/validators/business_type_validator_spec.rb
253
- - spec/defra_ruby/validators/companies_house_number_validator_spec.rb
254
- - spec/defra_ruby/validators/companies_house_service_spec.rb
255
- - spec/defra_ruby/validators/configuration_spec.rb
256
- - spec/defra_ruby/validators/email_validator_spec.rb
257
- - spec/defra_ruby/validators/grid_reference_validator_spec.rb
258
- - spec/defra_ruby/validators/location_validator_spec.rb
259
- - spec/defra_ruby/validators/past_date_validator_spec.rb
260
- - spec/defra_ruby/validators/phone_number_validator_spec.rb
261
- - spec/defra_ruby/validators/position_validator_spec.rb
262
- - spec/defra_ruby/validators/token_validator_spec.rb
263
- - spec/defra_ruby/validators/true_false_validator_spec.rb
264
- - spec/defra_ruby/validators_spec.rb
265
- - spec/examples.txt
266
- - spec/spec_helper.rb
267
- - spec/support/defra_ruby_validators.rb
268
- - spec/support/helpers/text_generator.rb
269
- - spec/support/helpers/translator.rb
270
- - spec/support/i18n.rb
271
- - spec/support/pry.rb
272
- - spec/support/shared_examples/validators/characters_validator.rb
273
- - spec/support/shared_examples/validators/invalid_record.rb
274
- - spec/support/shared_examples/validators/length_validator.rb
275
- - spec/support/shared_examples/validators/presence_validator.rb
276
- - spec/support/shared_examples/validators/selection_validator.rb
277
- - spec/support/shared_examples/validators/valid_record.rb
278
- - spec/support/shared_examples/validators/validator.rb
279
- - spec/support/simplecov.rb
280
154
  homepage: https://github.com/DEFRA/defra-ruby-validators
281
155
  licenses:
282
156
  - The Open Government Licence (OGL) Version 3
283
157
  metadata:
284
158
  allowed_push_host: https://rubygems.org
285
- post_install_message:
159
+ rubygems_mfa_required: 'true'
160
+ post_install_message:
286
161
  rdoc_options: []
287
162
  require_paths:
288
163
  - lib
@@ -290,43 +165,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
290
165
  requirements:
291
166
  - - ">="
292
167
  - !ruby/object:Gem::Version
293
- version: '0'
168
+ version: '3.1'
294
169
  required_rubygems_version: !ruby/object:Gem::Requirement
295
170
  requirements:
296
171
  - - ">="
297
172
  - !ruby/object:Gem::Version
298
173
  version: '0'
299
174
  requirements: []
300
- rubygems_version: 3.1.2
301
- signing_key:
175
+ rubygems_version: 3.3.7
176
+ signing_key:
302
177
  specification_version: 4
303
178
  summary: Defra ruby on rails validations
304
- test_files:
305
- - spec/spec_helper.rb
306
- - spec/defra_ruby/validators_spec.rb
307
- - spec/defra_ruby/validators/past_date_validator_spec.rb
308
- - spec/defra_ruby/validators/companies_house_service_spec.rb
309
- - spec/defra_ruby/validators/configuration_spec.rb
310
- - spec/defra_ruby/validators/phone_number_validator_spec.rb
311
- - spec/defra_ruby/validators/position_validator_spec.rb
312
- - spec/defra_ruby/validators/grid_reference_validator_spec.rb
313
- - spec/defra_ruby/validators/business_type_validator_spec.rb
314
- - spec/defra_ruby/validators/companies_house_number_validator_spec.rb
315
- - spec/defra_ruby/validators/token_validator_spec.rb
316
- - spec/defra_ruby/validators/true_false_validator_spec.rb
317
- - spec/defra_ruby/validators/location_validator_spec.rb
318
- - spec/defra_ruby/validators/email_validator_spec.rb
319
- - spec/examples.txt
320
- - spec/support/simplecov.rb
321
- - spec/support/i18n.rb
322
- - spec/support/pry.rb
323
- - spec/support/defra_ruby_validators.rb
324
- - spec/support/helpers/translator.rb
325
- - spec/support/helpers/text_generator.rb
326
- - spec/support/shared_examples/validators/selection_validator.rb
327
- - spec/support/shared_examples/validators/invalid_record.rb
328
- - spec/support/shared_examples/validators/presence_validator.rb
329
- - spec/support/shared_examples/validators/characters_validator.rb
330
- - spec/support/shared_examples/validators/length_validator.rb
331
- - spec/support/shared_examples/validators/valid_record.rb
332
- - spec/support/shared_examples/validators/validator.rb
179
+ test_files: []
@@ -1,56 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Test
6
- BusinessTypeValidatable = Struct.new(:business_type) do
7
- include ActiveModel::Validations
8
-
9
- validates :business_type, "defra_ruby/validators/business_type": true
10
- end
11
- end
12
-
13
- module DefraRuby
14
- module Validators
15
- RSpec.describe BusinessTypeValidator do
16
-
17
- valid_type = %w[soleTrader limitedCompany partnership limitedLiabilityPartnership localAuthority charity].sample
18
- invalid_type = "coven"
19
-
20
- it_behaves_like("a validator")
21
- it_behaves_like(
22
- "a selection validator",
23
- BusinessTypeValidator,
24
- Test::BusinessTypeValidatable,
25
- :business_type,
26
- valid: valid_type, invalid: invalid_type
27
- )
28
-
29
- context "when the value is overseas" do
30
- validatable = Test::BusinessTypeValidatable.new("overseas")
31
-
32
- context "when overseas_allowed is enabled" do
33
- before do
34
- allow_any_instance_of(DefraRuby::Validators::BaseValidator).to receive(:options).and_return(allow_overseas: true)
35
- end
36
-
37
- it_behaves_like "a valid record", validatable
38
- end
39
-
40
- context "when overseas_allowed is not enabled" do
41
- before do
42
- allow_any_instance_of(DefraRuby::Validators::BaseValidator).to receive(:options).and_return({})
43
- end
44
-
45
- error_message = Helpers::Translator.error_message(BusinessTypeValidator, :inclusion)
46
-
47
- it_behaves_like "an invalid record",
48
- validatable: validatable,
49
- attribute: :business_type,
50
- error: :inclusion,
51
- error_message: error_message
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,124 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- module Test
6
- CompaniesHouseNumberValidatable = Struct.new(:company_no) do
7
- include ActiveModel::Validations
8
-
9
- validates :company_no, "defra_ruby/validators/companies_house_number": true
10
- end
11
-
12
- CompaniesHouseCompanyTypeAndNumberValidatable = Struct.new(:company_no) do
13
- include ActiveModel::Validations
14
-
15
- validates :company_no, "defra_ruby/validators/companies_house_number": { company_type: "ltd" }
16
- end
17
- end
18
-
19
- module DefraRuby
20
- module Validators
21
- RSpec.describe CompaniesHouseNumberValidator do
22
-
23
- valid_numbers = %w[10997904 09764739 SC534714 IP00141R]
24
- invalid_format_number = "foobar42"
25
- unknown_number = "99999999"
26
- inactive_number = "07281919"
27
-
28
- it_behaves_like "a validator"
29
-
30
- describe "#validate_each" do
31
- context "when given a valid company number" do
32
- before do
33
- allow_any_instance_of(CompaniesHouseService).to receive(:status).and_return(:active)
34
- end
35
-
36
- valid_numbers.each do |company_no|
37
- context "like #{company_no}" do
38
- it_behaves_like "a valid record", Test::CompaniesHouseNumberValidatable.new(company_no)
39
- end
40
- end
41
- end
42
-
43
- context "when given an invalid company number" do
44
- context "because it is blank" do
45
- validatable = Test::CompaniesHouseNumberValidatable.new
46
- error_message = Helpers::Translator.error_message(CompaniesHouseNumberValidator, :blank)
47
-
48
- it_behaves_like "an invalid record",
49
- validatable: validatable,
50
- attribute: :company_no,
51
- error: :blank,
52
- error_message: error_message
53
- end
54
-
55
- context "because the format is wrong" do
56
- validatable = Test::CompaniesHouseNumberValidatable.new(invalid_format_number)
57
- error_message = Helpers::Translator.error_message(CompaniesHouseNumberValidator, :invalid_format)
58
-
59
- it_behaves_like "an invalid record",
60
- validatable: validatable,
61
- attribute: :company_no,
62
- error: :invalid_format,
63
- error_message: error_message
64
- end
65
-
66
- context "because it's not found on companies house" do
67
- before do
68
- allow_any_instance_of(CompaniesHouseService).to receive(:status).and_return(:not_found)
69
- end
70
-
71
- validatable = Test::CompaniesHouseNumberValidatable.new(unknown_number)
72
- error_message = Helpers::Translator.error_message(CompaniesHouseNumberValidator, :not_found)
73
-
74
- it_behaves_like "an invalid record",
75
- validatable: validatable,
76
- attribute: :company_no,
77
- error: :not_found,
78
- error_message: error_message
79
- end
80
-
81
- context "because it's not 'active' on companies house" do
82
- before do
83
- allow_any_instance_of(CompaniesHouseService).to receive(:status).and_return(:inactive)
84
- end
85
-
86
- validatable = Test::CompaniesHouseNumberValidatable.new(inactive_number)
87
- error_message = Helpers::Translator.error_message(CompaniesHouseNumberValidator, :inactive)
88
-
89
- it_behaves_like "an invalid record",
90
- validatable: validatable,
91
- attribute: :company_no,
92
- error: :inactive,
93
- error_message: error_message
94
- end
95
-
96
- context "with a company_type option" do
97
- let(:company_no) { valid_numbers.first }
98
-
99
- it "calls the companies house service with the `ltd` param" do
100
- expect(CompaniesHouseService).to receive(:new).with(company_no, "ltd")
101
-
102
- Test::CompaniesHouseCompanyTypeAndNumberValidatable.new(company_no).valid?
103
- end
104
- end
105
- end
106
-
107
- context "when there is an error connecting with companies house" do
108
- before do
109
- allow_any_instance_of(CompaniesHouseService).to receive(:status).and_raise(StandardError)
110
- end
111
-
112
- validatable = Test::CompaniesHouseNumberValidatable.new(valid_numbers.sample)
113
- error_message = Helpers::Translator.error_message(CompaniesHouseNumberValidator, :error)
114
-
115
- it_behaves_like "an invalid record",
116
- validatable: validatable,
117
- attribute: :company_no,
118
- error: :error,
119
- error_message: error_message
120
- end
121
- end
122
- end
123
- end
124
- end
@@ -1,98 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "webmock/rspec"
4
-
5
- RSpec.describe DefraRuby::Validators::CompaniesHouseService do
6
- let(:host) { "https://api.companieshouse.gov.uk/" }
7
-
8
- describe "#status" do
9
- let(:subject) { described_class.new("09360070") }
10
-
11
- context "when the company_no is for an active company" do
12
- before do
13
- expected_body = { "company_status": "active", "type": "ltd" }
14
-
15
- stub_request(:any, /.*#{host}.*/).to_return(
16
- status: 200,
17
- body: expected_body.to_json
18
- )
19
- end
20
-
21
- it "returns :active" do
22
- expect(subject.status).to eq(:active)
23
- end
24
- end
25
-
26
- context "when the company_no is not found" do
27
- before do
28
- stub_request(:any, /.*#{host}.*/).to_return(
29
- status: 404
30
- )
31
- end
32
-
33
- it "returns :not_found" do
34
- expect(subject.status).to eq(:not_found)
35
- end
36
- end
37
-
38
- context "when the company_no is inactive" do
39
- before do
40
- expected_body = { "company_status": "dissolved", "type": "ltd" }
41
-
42
- stub_request(:any, /.*#{host}.*/).to_return(
43
- status: 200,
44
- body: expected_body.to_json
45
- )
46
- end
47
-
48
- it "returns :inactive" do
49
- expect(subject.status).to eq(:inactive)
50
- end
51
- end
52
-
53
- context "checking the company_type" do
54
- let(:subject) { described_class.new("09360070", "llp") }
55
-
56
- context "when the company_no is for a LLP" do
57
- before do
58
- stub_request(:any, /.*#{host}.*/).to_return(
59
- status: 200,
60
- body: expected_body.to_json
61
- )
62
- end
63
-
64
- let(:expected_body) { { "company_status": "active", "type": "llp" } }
65
-
66
- it "returns :active" do
67
- expect(subject.status).to eq(:active)
68
- end
69
-
70
- context "but a ltd company is found" do
71
- let(:expected_body) { { "company_status": "active", "type": "ltd" } }
72
-
73
- it "returns :not_found" do
74
- expect(subject.status).to eq(:not_found)
75
- end
76
- end
77
- end
78
- end
79
-
80
- context "when there is a problem with the Companies House API" do
81
- context "and the request times out" do
82
- before { stub_request(:any, /.*#{host}.*/).to_timeout }
83
-
84
- it "raises an exception" do
85
- expect { subject.status }.to raise_error(StandardError)
86
- end
87
- end
88
-
89
- context "and request returns an error" do
90
- before { stub_request(:any, /.*#{host}.*/).to_raise(SocketError) }
91
-
92
- it "raises an exception" do
93
- expect { subject.status }.to raise_error(StandardError)
94
- end
95
- end
96
- end
97
- end
98
- end
@@ -1,49 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- RSpec.describe DefraRuby::Validators::Configuration do
6
- describe "ATTRIBUTES" do
7
- it "represents the expected config settings and only those settings" do
8
- expected_attributes = %i[
9
- companies_house_host
10
- companies_house_api_key
11
- ]
12
-
13
- expect(described_class::ATTRIBUTES).to match_array(expected_attributes)
14
- end
15
- end
16
-
17
- it "sets the appropriate default config settings" do
18
- fresh_config = described_class.new
19
-
20
- expect(fresh_config.companies_house_host).to eq("https://api.companieshouse.gov.uk/company/")
21
- expect(fresh_config.companies_house_api_key).to eq(nil)
22
- end
23
-
24
- describe "#ensure_valid" do
25
- before(:each) do
26
- described_class::ATTRIBUTES.each do |attribute|
27
- subject.public_send("#{attribute}=", "foo")
28
- end
29
- end
30
-
31
- context "when all of the attributes are present" do
32
- it "does not raise an error" do
33
- expect { subject.ensure_valid }.to_not raise_error
34
- expect(subject.ensure_valid).to eq(true)
35
- end
36
- end
37
-
38
- context "when at least one of the attributes is missing" do
39
- before(:each) do
40
- subject.companies_house_api_key = nil
41
- end
42
-
43
- it "raises an error" do
44
- message = "The following DefraRuby::Validators configuration attributes are missing: [:companies_house_api_key]"
45
- expect { subject.ensure_valid }.to raise_error(message)
46
- end
47
- end
48
- end
49
- end