defra_ruby_validators 0.1.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -18
- data/config/locales/defra_ruby/validators/companies_house_number_validator/en.yml +10 -0
- data/lib/defra_ruby/validators.rb +15 -0
- data/lib/defra_ruby/validators/base_validator.rb +21 -0
- data/lib/defra_ruby/validators/companies_house_number_validator.rb +54 -0
- data/lib/defra_ruby/validators/companies_house_service.rb +36 -0
- data/lib/defra_ruby/validators/configuration.rb +35 -0
- data/lib/defra_ruby/validators/engine.rb +22 -0
- data/lib/defra_ruby/validators/version.rb +7 -0
- data/lib/defra_ruby_validators.rb +27 -9
- data/spec/cassettes/company_no_inactive.yml +14 -14
- data/spec/cassettes/company_no_not_found.yml +15 -15
- data/spec/cassettes/company_no_valid.yml +14 -14
- data/spec/defra_ruby/validators/companies_house_number_validator_spec.rb +88 -0
- data/spec/defra_ruby/validators/companies_house_service_spec.rb +58 -0
- data/spec/defra_ruby/validators/configuration_spec.rb +49 -0
- data/spec/defra_ruby/validators_spec.rb +12 -0
- data/spec/examples.txt +36 -27
- data/spec/spec_helper.rb +69 -19
- data/spec/support/defra_ruby_validators.rb +13 -2
- data/spec/support/dotenv.rb +4 -0
- data/spec/support/helpers/translator.rb +14 -0
- data/spec/support/pry.rb +7 -0
- data/spec/support/shared_examples/validators/invalid_record.rb +18 -0
- data/spec/support/shared_examples/validators/valid_record.rb +12 -0
- data/spec/support/shared_examples/validators/validator.rb +8 -0
- data/spec/support/simplecov.rb +17 -0
- metadata +37 -19
- data/config/locales/defra_ruby_validators/companies_house_number/en.yml +0 -14
- data/lib/defra_ruby_validators/companies_house_number_validator.rb +0 -56
- data/lib/defra_ruby_validators/companies_house_service.rb +0 -34
- data/lib/defra_ruby_validators/engine.rb +0 -20
- data/lib/defra_ruby_validators/validators.rb +0 -33
- data/lib/defra_ruby_validators/version.rb +0 -5
- data/spec/defra_ruby_validators/companies_house_number_validator_spec.rb +0 -125
- data/spec/defra_ruby_validators/companies_house_service_spec.rb +0 -55
- data/spec/defra_ruby_validators/version_spec.rb +0 -7
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module DefraRubyValidators
|
4
|
-
RSpec.describe CompaniesHouseService do
|
5
|
-
let(:companies_house_service) { CompaniesHouseService.new("09360070") }
|
6
|
-
|
7
|
-
context "when a company_no is for an active company" do
|
8
|
-
it "returns :active" do
|
9
|
-
VCR.use_cassette("company_no_valid") do
|
10
|
-
expect(companies_house_service.status).to eq(:active)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context "when a company_no is not found" do
|
16
|
-
let(:companies_house_service) { CompaniesHouseService.new("99999999") }
|
17
|
-
|
18
|
-
it "returns :not_found" do
|
19
|
-
VCR.use_cassette("company_no_not_found") do
|
20
|
-
expect(companies_house_service.status).to eq(:not_found)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when a company_no is inactive" do
|
26
|
-
let(:companies_house_service) { CompaniesHouseService.new("07281919") }
|
27
|
-
|
28
|
-
it "returns :inactive" do
|
29
|
-
VCR.use_cassette("company_no_inactive") do
|
30
|
-
expect(companies_house_service.status).to eq(:inactive)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "when the request times out" do
|
36
|
-
it "raises an exception" do
|
37
|
-
VCR.turned_off do
|
38
|
-
host = "https://api.companieshouse.gov.uk/"
|
39
|
-
stub_request(:any, /.*#{host}.*/).to_timeout
|
40
|
-
expect { companies_house_service.status }.to raise_error(StandardError)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context "when the request returns an error" do
|
46
|
-
it "raises an exception" do
|
47
|
-
VCR.turned_off do
|
48
|
-
host = "https://api.companieshouse.gov.uk/"
|
49
|
-
stub_request(:any, /.*#{host}.*/).to_raise(SocketError)
|
50
|
-
expect { companies_house_service.status }.to raise_error(StandardError)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|