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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -18
  3. data/config/locales/defra_ruby/validators/companies_house_number_validator/en.yml +10 -0
  4. data/lib/defra_ruby/validators.rb +15 -0
  5. data/lib/defra_ruby/validators/base_validator.rb +21 -0
  6. data/lib/defra_ruby/validators/companies_house_number_validator.rb +54 -0
  7. data/lib/defra_ruby/validators/companies_house_service.rb +36 -0
  8. data/lib/defra_ruby/validators/configuration.rb +35 -0
  9. data/lib/defra_ruby/validators/engine.rb +22 -0
  10. data/lib/defra_ruby/validators/version.rb +7 -0
  11. data/lib/defra_ruby_validators.rb +27 -9
  12. data/spec/cassettes/company_no_inactive.yml +14 -14
  13. data/spec/cassettes/company_no_not_found.yml +15 -15
  14. data/spec/cassettes/company_no_valid.yml +14 -14
  15. data/spec/defra_ruby/validators/companies_house_number_validator_spec.rb +88 -0
  16. data/spec/defra_ruby/validators/companies_house_service_spec.rb +58 -0
  17. data/spec/defra_ruby/validators/configuration_spec.rb +49 -0
  18. data/spec/defra_ruby/validators_spec.rb +12 -0
  19. data/spec/examples.txt +36 -27
  20. data/spec/spec_helper.rb +69 -19
  21. data/spec/support/defra_ruby_validators.rb +13 -2
  22. data/spec/support/dotenv.rb +4 -0
  23. data/spec/support/helpers/translator.rb +14 -0
  24. data/spec/support/pry.rb +7 -0
  25. data/spec/support/shared_examples/validators/invalid_record.rb +18 -0
  26. data/spec/support/shared_examples/validators/valid_record.rb +12 -0
  27. data/spec/support/shared_examples/validators/validator.rb +8 -0
  28. data/spec/support/simplecov.rb +17 -0
  29. metadata +37 -19
  30. data/config/locales/defra_ruby_validators/companies_house_number/en.yml +0 -14
  31. data/lib/defra_ruby_validators/companies_house_number_validator.rb +0 -56
  32. data/lib/defra_ruby_validators/companies_house_service.rb +0 -34
  33. data/lib/defra_ruby_validators/engine.rb +0 -20
  34. data/lib/defra_ruby_validators/validators.rb +0 -33
  35. data/lib/defra_ruby_validators/version.rb +0 -5
  36. data/spec/defra_ruby_validators/companies_house_number_validator_spec.rb +0 -125
  37. data/spec/defra_ruby_validators/companies_house_service_spec.rb +0 -55
  38. 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
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe DefraRubyValidators do
4
- it "has a version number" do
5
- expect(DefraRubyValidators::VERSION).not_to be nil
6
- end
7
- end