defra_ruby_validators 2.1.1 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -5
- data/Rakefile +2 -2
- data/bin/console +3 -7
- data/config/locales/defra_ruby/validators/business_type_validator/en.yml +1 -2
- data/config/locales/defra_ruby/validators/companies_house_number_validator/en.yml +5 -6
- data/config/locales/defra_ruby/validators/email_validator/en.yml +2 -3
- data/config/locales/defra_ruby/validators/grid_reference_validator/en.yml +3 -4
- data/config/locales/defra_ruby/validators/location_validator/en.yml +1 -2
- data/config/locales/defra_ruby/validators/past_date_validator/en.yml +6 -0
- data/config/locales/defra_ruby/validators/phone_number_validator/en.yml +3 -4
- data/config/locales/defra_ruby/validators/position_validator/en.yml +2 -3
- data/config/locales/defra_ruby/validators/token_validator/en.yml +2 -3
- data/config/locales/defra_ruby/validators/true_false_validator/en.yml +1 -2
- data/lib/defra_ruby/validators.rb +1 -0
- data/lib/defra_ruby/validators/base_validator.rb +8 -2
- data/lib/defra_ruby/validators/companies_house_number_validator.rb +5 -5
- data/lib/defra_ruby/validators/concerns/can_validate_characters.rb +1 -1
- data/lib/defra_ruby/validators/concerns/can_validate_length.rb +1 -1
- data/lib/defra_ruby/validators/concerns/can_validate_presence.rb +1 -1
- data/lib/defra_ruby/validators/concerns/can_validate_selection.rb +3 -2
- data/lib/defra_ruby/validators/email_validator.rb +1 -1
- data/lib/defra_ruby/validators/grid_reference_validator.rb +2 -2
- data/lib/defra_ruby/validators/past_date_validator.rb +27 -0
- data/lib/defra_ruby/validators/phone_number_validator.rb +1 -1
- data/lib/defra_ruby/validators/token_validator.rb +1 -1
- data/lib/defra_ruby/validators/true_false_validator.rb +1 -1
- data/lib/defra_ruby/validators/version.rb +1 -1
- data/spec/defra_ruby/validators/business_type_validator_spec.rb +1 -1
- data/spec/defra_ruby/validators/companies_house_number_validator_spec.rb +5 -25
- data/spec/defra_ruby/validators/companies_house_service_spec.rb +25 -13
- data/spec/defra_ruby/validators/email_validator_spec.rb +1 -1
- data/spec/defra_ruby/validators/grid_reference_validator_spec.rb +2 -2
- data/spec/defra_ruby/validators/location_validator_spec.rb +1 -1
- data/spec/defra_ruby/validators/past_date_validator_spec.rb +35 -0
- data/spec/defra_ruby/validators/phone_number_validator_spec.rb +1 -1
- data/spec/defra_ruby/validators/token_validator_spec.rb +1 -1
- data/spec/defra_ruby/validators/true_false_validator_spec.rb +10 -3
- data/spec/support/helpers/translator.rb +2 -2
- data/spec/support/shared_examples/validators/characters_validator.rb +1 -1
- data/spec/support/shared_examples/validators/length_validator.rb +1 -1
- data/spec/support/shared_examples/validators/presence_validator.rb +1 -1
- data/spec/support/shared_examples/validators/selection_validator.rb +2 -2
- metadata +8 -28
- data/spec/cassettes/company_no_inactive.yml +0 -67
- data/spec/cassettes/company_no_not_found.yml +0 -64
- data/spec/cassettes/company_no_valid.yml +0 -65
- data/spec/examples.txt +0 -81
- data/spec/support/vcr.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21bdd325a2591dc6b3240957791d511239cadf35
|
4
|
+
data.tar.gz: dbf3657df6f3c814a3f2081a4c576f3319c5c713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22c834aeb4feacd105d153c38a0db5ba1ea3951e8f4e78fb8bb8f48fb1a797ba64973b98565ea4c51904ca623a40934f1e9d6f57b7bb7319197762480cf17938
|
7
|
+
data.tar.gz: 3553f860583d638a6fcd86038240c507dd3fc4f89ad16e1fd87ec68bbf5386a27d36f46ecb7536717f2f060804ae5f8d9fdaa1ef784cbc05194df1beedf63b44
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
|
1
|
+
# Defra Ruby Validators
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.com/DEFRA/defra-ruby-validators.svg?branch=
|
4
|
-
[![Maintainability](https://
|
5
|
-
[![
|
6
|
-
[![security](https://hakiri.io/github/DEFRA/defra-ruby-validators/
|
3
|
+
[![Build Status](https://travis-ci.com/DEFRA/defra-ruby-validators.svg?branch=main)](https://travis-ci.com/DEFRA/defra-ruby-validators)
|
4
|
+
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_defra-ruby-validators&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=DEFRA_defra-ruby-validators)
|
5
|
+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_defra-ruby-validators&metric=coverage)](https://sonarcloud.io/dashboard?id=DEFRA_defra-ruby-validators)
|
6
|
+
[![security](https://hakiri.io/github/DEFRA/defra-ruby-validators/main.svg)](https://hakiri.io/github/DEFRA/defra-ruby-validators/main)
|
7
7
|
[![Gem Version](https://badge.fury.io/rb/defra_ruby_validators.svg)](https://badge.fury.io/rb/defra_ruby_validators)
|
8
8
|
[![Licence](https://img.shields.io/badge/Licence-OGLv3-blue.svg)](http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3)
|
9
9
|
|
@@ -117,6 +117,16 @@ If you want to include `overseas` in the accepted locations, you can enable this
|
|
117
117
|
validates :location, "defra_ruby/validators/location": { allow_overseas: true }
|
118
118
|
```
|
119
119
|
|
120
|
+
### Past date
|
121
|
+
|
122
|
+
This validator checks the value provided is present and not a date in the future (`<= Date.today`).
|
123
|
+
|
124
|
+
Add it to your model or form object using
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
validates :date_received, "defra_ruby/validators/past_date_validator": true
|
128
|
+
```
|
129
|
+
|
120
130
|
### Phone number
|
121
131
|
|
122
132
|
This validator checks the value is present, is not too long (15 is th maximum length for any phone number), and is in the correct format as per [E.164](https://en.wikipedia.org/wiki/E.164) (we use [phonelib](https://github.com/daddyz/phonelib) to check the format).
|
data/Rakefile
CHANGED
@@ -11,7 +11,6 @@ Bundler::GemHelper.install_tasks
|
|
11
11
|
# This is wrapped to prevent an error when rake is called in environments where
|
12
12
|
# rspec may not be available, e.g. production. As such we don't need to handle
|
13
13
|
# the error.
|
14
|
-
# rubocop:disable Lint/HandleExceptions
|
15
14
|
begin
|
16
15
|
require "rspec/core/rake_task"
|
17
16
|
|
@@ -26,8 +25,9 @@ begin
|
|
26
25
|
require "github_changelog_generator/task"
|
27
26
|
|
28
27
|
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
28
|
+
config.user = "defra"
|
29
|
+
config.project = "defra-ruby-validators"
|
29
30
|
end
|
30
31
|
rescue LoadError
|
31
32
|
# no changelog available
|
32
33
|
end
|
33
|
-
# rubocop:enable Lint/HandleExceptions
|
data/bin/console
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
|
-
require "
|
4
|
+
require "defra_ruby/validators"
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start(__FILE__)
|
9
|
+
require "pry"
|
10
|
+
Pry.start
|
@@ -2,9 +2,8 @@ en:
|
|
2
2
|
defra_ruby:
|
3
3
|
validators:
|
4
4
|
CompaniesHouseNumberValidator:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
error: There was an error connecting with Companies House. Hopefully this is a one off and will work if you try again.
|
5
|
+
blank: Enter a company registration number
|
6
|
+
invalid_format: "Enter a valid number - it should have 8 digits, or 2 letters followed by 6 digits, or 2 letters followed by 5 digits and another letter. If your number has only 7 digits, enter it with a zero at the start."
|
7
|
+
not_found: Companies House couldn't find a company with this number
|
8
|
+
inactive: Your company must be registered as an active company
|
9
|
+
error: There was an error connecting with Companies House. Hopefully this is a one off and will work if you try again.
|
@@ -2,6 +2,5 @@ en:
|
|
2
2
|
defra_ruby:
|
3
3
|
validators:
|
4
4
|
EmailValidator:
|
5
|
-
email
|
6
|
-
|
7
|
-
invalid_format: "Enter a valid email address - there’s a mistake in that one"
|
5
|
+
blank: "Enter an email address"
|
6
|
+
invalid_format: "Enter a valid email address - there’s a mistake in that one"
|
@@ -2,7 +2,6 @@ en:
|
|
2
2
|
defra_ruby:
|
3
3
|
validators:
|
4
4
|
GridReferenceValidator:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
invalid: The grid reference is not a valid coordinate
|
5
|
+
blank: Enter a grid reference
|
6
|
+
invalid_format: The grid reference should have 2 letters and 10 digits
|
7
|
+
invalid: The grid reference is not a valid coordinate
|
@@ -2,7 +2,6 @@ en:
|
|
2
2
|
defra_ruby:
|
3
3
|
validators:
|
4
4
|
PhoneNumberValidator:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
too_long: "Check the number you entered - it should have no more than than 15 characters"
|
5
|
+
blank: "Enter a telephone number"
|
6
|
+
invalid_format: "Enter a valid telephone number"
|
7
|
+
too_long: "Check the number you entered - it should have no more than than 15 characters"
|
@@ -2,6 +2,5 @@ en:
|
|
2
2
|
defra_ruby:
|
3
3
|
validators:
|
4
4
|
PositionValidator:
|
5
|
-
position
|
6
|
-
|
7
|
-
too_long: "The position must have no more than 70 characters"
|
5
|
+
invalid_format: "The position must contain only letters, spaces, commas, full stops, hyphens and apostrophes"
|
6
|
+
too_long: "The position must have no more than 70 characters"
|
@@ -21,6 +21,7 @@ require_relative "validators/phone_number_validator"
|
|
21
21
|
require_relative "validators/position_validator"
|
22
22
|
require_relative "validators/token_validator"
|
23
23
|
require_relative "validators/true_false_validator"
|
24
|
+
require_relative "validators/past_date_validator"
|
24
25
|
|
25
26
|
module DefraRuby
|
26
27
|
module Validators
|
@@ -6,11 +6,17 @@ module DefraRuby
|
|
6
6
|
|
7
7
|
protected
|
8
8
|
|
9
|
-
def
|
9
|
+
def add_validation_error(record, attribute, error)
|
10
|
+
record.errors.add(attribute,
|
11
|
+
error,
|
12
|
+
message: error_message(error))
|
13
|
+
end
|
14
|
+
|
15
|
+
def error_message(error)
|
10
16
|
if options[:messages] && options[:messages][error]
|
11
17
|
options[:messages][error]
|
12
18
|
else
|
13
|
-
I18n.t("defra_ruby.validators.#{class_name}.#{
|
19
|
+
I18n.t("defra_ruby.validators.#{class_name}.#{error}")
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
@@ -25,14 +25,14 @@ module DefraRuby
|
|
25
25
|
def value_is_present?(record, attribute, value)
|
26
26
|
return true if value.present?
|
27
27
|
|
28
|
-
record
|
28
|
+
add_validation_error(record, attribute, :blank)
|
29
29
|
false
|
30
30
|
end
|
31
31
|
|
32
32
|
def format_is_valid?(record, attribute, value)
|
33
33
|
return true if value.match?(VALID_COMPANIES_HOUSE_REGISTRATION_NUMBER_REGEX)
|
34
34
|
|
35
|
-
record
|
35
|
+
add_validation_error(record, attribute, :invalid_format)
|
36
36
|
false
|
37
37
|
end
|
38
38
|
|
@@ -41,12 +41,12 @@ module DefraRuby
|
|
41
41
|
when :active
|
42
42
|
true
|
43
43
|
when :inactive
|
44
|
-
record
|
44
|
+
add_validation_error(record, attribute, :inactive)
|
45
45
|
when :not_found
|
46
|
-
record
|
46
|
+
add_validation_error(record, attribute, :not_found)
|
47
47
|
end
|
48
48
|
rescue StandardError
|
49
|
-
record
|
49
|
+
add_validation_error(record, attribute, :error)
|
50
50
|
end
|
51
51
|
|
52
52
|
end
|
@@ -10,7 +10,7 @@ module DefraRuby
|
|
10
10
|
# Name fields must contain only letters, spaces, commas, full stops, hyphens and apostrophes
|
11
11
|
return true if value.match?(/\A[-a-z\s,.']+\z/i)
|
12
12
|
|
13
|
-
record
|
13
|
+
add_validation_error(record, attribute, :invalid_format)
|
14
14
|
false
|
15
15
|
end
|
16
16
|
|
@@ -9,7 +9,7 @@ module DefraRuby
|
|
9
9
|
def value_is_not_too_long?(record, attribute, value, max_length)
|
10
10
|
return true if value.length <= max_length
|
11
11
|
|
12
|
-
record
|
12
|
+
add_validation_error(record, attribute, :too_long)
|
13
13
|
false
|
14
14
|
end
|
15
15
|
|
@@ -7,9 +7,10 @@ module DefraRuby
|
|
7
7
|
private
|
8
8
|
|
9
9
|
def value_is_included?(record, attribute, value, valid_options)
|
10
|
-
|
10
|
+
# In this case, we do want `false.present?` to return `true` https://github.com/rails/rails/issues/10804
|
11
|
+
return true if (value == false || value.present?) && valid_options.include?(value)
|
11
12
|
|
12
|
-
record
|
13
|
+
add_validation_error(record, attribute, :inclusion)
|
13
14
|
false
|
14
15
|
end
|
15
16
|
|
@@ -19,7 +19,7 @@ module DefraRuby
|
|
19
19
|
# validate_email_format returns nil if the validation passes
|
20
20
|
return true unless ValidatesEmailFormatOf.validate_email_format(value)
|
21
21
|
|
22
|
-
record
|
22
|
+
add_validation_error(record, attribute, :invalid_format)
|
23
23
|
false
|
24
24
|
end
|
25
25
|
|
@@ -22,7 +22,7 @@ module DefraRuby
|
|
22
22
|
def valid_format?(record, attribute, value)
|
23
23
|
return true if value.match?(/\A#{grid_reference_pattern}\z/)
|
24
24
|
|
25
|
-
record
|
25
|
+
add_validation_error(record, attribute, :invalid_format)
|
26
26
|
false
|
27
27
|
end
|
28
28
|
|
@@ -30,7 +30,7 @@ module DefraRuby
|
|
30
30
|
OsMapRef::Location.for(value).easting
|
31
31
|
true
|
32
32
|
rescue OsMapRef::Error
|
33
|
-
record
|
33
|
+
add_validation_error(record, attribute, :invalid)
|
34
34
|
false
|
35
35
|
end
|
36
36
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DefraRuby
|
4
|
+
module Validators
|
5
|
+
class PastDateValidator < BaseValidator
|
6
|
+
def validate_each(record, attribute, value)
|
7
|
+
return false if value.blank?
|
8
|
+
|
9
|
+
date = value.to_date
|
10
|
+
|
11
|
+
if date > Date.today
|
12
|
+
add_validation_error(record, attribute, :past_date)
|
13
|
+
|
14
|
+
return false
|
15
|
+
end
|
16
|
+
|
17
|
+
if date.year < 1900
|
18
|
+
add_validation_error(record, attribute, :invalid_date)
|
19
|
+
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -42,7 +42,7 @@ module DefraRuby
|
|
42
42
|
allow_any_instance_of(DefraRuby::Validators::BaseValidator).to receive(:options).and_return({})
|
43
43
|
end
|
44
44
|
|
45
|
-
error_message = Helpers::Translator.error_message(BusinessTypeValidator, :
|
45
|
+
error_message = Helpers::Translator.error_message(BusinessTypeValidator, :inclusion)
|
46
46
|
|
47
47
|
it_behaves_like "an invalid record",
|
48
48
|
validatable: validatable,
|
@@ -37,11 +37,7 @@ module DefraRuby
|
|
37
37
|
context "when given an invalid company number" do
|
38
38
|
context "because it is blank" do
|
39
39
|
validatable = Test::CompaniesHouseNumberValidatable.new
|
40
|
-
error_message = Helpers::Translator.error_message(
|
41
|
-
CompaniesHouseNumberValidator,
|
42
|
-
:company_no,
|
43
|
-
:blank
|
44
|
-
)
|
40
|
+
error_message = Helpers::Translator.error_message(CompaniesHouseNumberValidator, :blank)
|
45
41
|
|
46
42
|
it_behaves_like "an invalid record",
|
47
43
|
validatable: validatable,
|
@@ -52,11 +48,7 @@ module DefraRuby
|
|
52
48
|
|
53
49
|
context "because the format is wrong" do
|
54
50
|
validatable = Test::CompaniesHouseNumberValidatable.new(invalid_format_number)
|
55
|
-
error_message = Helpers::Translator.error_message(
|
56
|
-
CompaniesHouseNumberValidator,
|
57
|
-
:company_no,
|
58
|
-
:invalid_format
|
59
|
-
)
|
51
|
+
error_message = Helpers::Translator.error_message(CompaniesHouseNumberValidator, :invalid_format)
|
60
52
|
|
61
53
|
it_behaves_like "an invalid record",
|
62
54
|
validatable: validatable,
|
@@ -71,11 +63,7 @@ module DefraRuby
|
|
71
63
|
end
|
72
64
|
|
73
65
|
validatable = Test::CompaniesHouseNumberValidatable.new(unknown_number)
|
74
|
-
error_message = Helpers::Translator.error_message(
|
75
|
-
CompaniesHouseNumberValidator,
|
76
|
-
:company_no,
|
77
|
-
:not_found
|
78
|
-
)
|
66
|
+
error_message = Helpers::Translator.error_message(CompaniesHouseNumberValidator, :not_found)
|
79
67
|
|
80
68
|
it_behaves_like "an invalid record",
|
81
69
|
validatable: validatable,
|
@@ -90,11 +78,7 @@ module DefraRuby
|
|
90
78
|
end
|
91
79
|
|
92
80
|
validatable = Test::CompaniesHouseNumberValidatable.new(inactive_number)
|
93
|
-
error_message = Helpers::Translator.error_message(
|
94
|
-
CompaniesHouseNumberValidator,
|
95
|
-
:company_no,
|
96
|
-
:inactive
|
97
|
-
)
|
81
|
+
error_message = Helpers::Translator.error_message(CompaniesHouseNumberValidator, :inactive)
|
98
82
|
|
99
83
|
it_behaves_like "an invalid record",
|
100
84
|
validatable: validatable,
|
@@ -110,11 +94,7 @@ module DefraRuby
|
|
110
94
|
end
|
111
95
|
|
112
96
|
validatable = Test::CompaniesHouseNumberValidatable.new(valid_numbers.sample)
|
113
|
-
error_message = Helpers::Translator.error_message(
|
114
|
-
CompaniesHouseNumberValidator,
|
115
|
-
:company_no,
|
116
|
-
:error
|
117
|
-
)
|
97
|
+
error_message = Helpers::Translator.error_message(CompaniesHouseNumberValidator, :error)
|
118
98
|
|
119
99
|
it_behaves_like "an invalid record",
|
120
100
|
validatable: validatable,
|
@@ -1,13 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "webmock/rspec"
|
4
|
+
|
3
5
|
RSpec.describe DefraRuby::Validators::CompaniesHouseService do
|
4
6
|
let(:subject) { described_class.new("09360070") }
|
5
7
|
let(:host) { "https://api.companieshouse.gov.uk/" }
|
6
8
|
|
7
9
|
describe "#status" do
|
8
10
|
context "when the company_no is for an active company" do
|
9
|
-
before
|
10
|
-
|
11
|
+
before do
|
12
|
+
expected_body = { "company_status": "active" }
|
13
|
+
|
14
|
+
stub_request(:any, /.*#{host}.*/).to_return(
|
15
|
+
status: 200,
|
16
|
+
body: expected_body.to_json
|
17
|
+
)
|
18
|
+
end
|
11
19
|
|
12
20
|
it "returns :active" do
|
13
21
|
expect(subject.status).to eq(:active)
|
@@ -15,9 +23,11 @@ RSpec.describe DefraRuby::Validators::CompaniesHouseService do
|
|
15
23
|
end
|
16
24
|
|
17
25
|
context "when the company_no is not found" do
|
18
|
-
|
19
|
-
|
20
|
-
|
26
|
+
before do
|
27
|
+
stub_request(:any, /.*#{host}.*/).to_return(
|
28
|
+
status: 404
|
29
|
+
)
|
30
|
+
end
|
21
31
|
|
22
32
|
it "returns :not_found" do
|
23
33
|
expect(subject.status).to eq(:not_found)
|
@@ -25,9 +35,14 @@ RSpec.describe DefraRuby::Validators::CompaniesHouseService do
|
|
25
35
|
end
|
26
36
|
|
27
37
|
context "when the company_no is inactive" do
|
28
|
-
|
29
|
-
|
30
|
-
|
38
|
+
before do
|
39
|
+
expected_body = { "company_status": "dissolved" }
|
40
|
+
|
41
|
+
stub_request(:any, /.*#{host}.*/).to_return(
|
42
|
+
status: 200,
|
43
|
+
body: expected_body.to_json
|
44
|
+
)
|
45
|
+
end
|
31
46
|
|
32
47
|
it "returns :inactive" do
|
33
48
|
expect(subject.status).to eq(:inactive)
|
@@ -35,11 +50,8 @@ RSpec.describe DefraRuby::Validators::CompaniesHouseService do
|
|
35
50
|
end
|
36
51
|
|
37
52
|
context "when there is a problem with the Companies House API" do
|
38
|
-
before(:each) { VCR.turn_off! }
|
39
|
-
after(:each) { VCR.turn_on! }
|
40
|
-
|
41
53
|
context "and the request times out" do
|
42
|
-
before
|
54
|
+
before { stub_request(:any, /.*#{host}.*/).to_timeout }
|
43
55
|
|
44
56
|
it "raises an exception" do
|
45
57
|
expect { subject.status }.to raise_error(StandardError)
|
@@ -47,7 +59,7 @@ RSpec.describe DefraRuby::Validators::CompaniesHouseService do
|
|
47
59
|
end
|
48
60
|
|
49
61
|
context "and request returns an error" do
|
50
|
-
before
|
62
|
+
before { stub_request(:any, /.*#{host}.*/).to_raise(SocketError) }
|
51
63
|
|
52
64
|
it "raises an exception" do
|
53
65
|
expect { subject.status }.to raise_error(StandardError)
|
@@ -31,7 +31,7 @@ module DefraRuby
|
|
31
31
|
context "because the email is not correctly formatted" do
|
32
32
|
validatable = Test::EmailValidatable.new(invalid_email)
|
33
33
|
|
34
|
-
error_message = Helpers::Translator.error_message(EmailValidator, :
|
34
|
+
error_message = Helpers::Translator.error_message(EmailValidator, :invalid_format)
|
35
35
|
|
36
36
|
it_behaves_like "an invalid record",
|
37
37
|
validatable: validatable,
|
@@ -31,7 +31,7 @@ module DefraRuby
|
|
31
31
|
context "when the grid reference is not valid" do
|
32
32
|
context "because the grid reference is not correctly formatted" do
|
33
33
|
validatable = Test::GridReferenceValidatable.new(invalid_grid_reference)
|
34
|
-
error_message = Helpers::Translator.error_message(GridReferenceValidator, :
|
34
|
+
error_message = Helpers::Translator.error_message(GridReferenceValidator, :invalid_format)
|
35
35
|
|
36
36
|
it_behaves_like "an invalid record",
|
37
37
|
validatable: validatable,
|
@@ -42,7 +42,7 @@ module DefraRuby
|
|
42
42
|
|
43
43
|
context "because the grid reference is not a coordinate" do
|
44
44
|
validatable = Test::GridReferenceValidatable.new(non_coordinate_grid_reference)
|
45
|
-
error_message = Helpers::Translator.error_message(GridReferenceValidator, :
|
45
|
+
error_message = Helpers::Translator.error_message(GridReferenceValidator, :invalid)
|
46
46
|
|
47
47
|
it_behaves_like "an invalid record",
|
48
48
|
validatable: validatable,
|
@@ -42,7 +42,7 @@ module DefraRuby
|
|
42
42
|
allow_any_instance_of(DefraRuby::Validators::BaseValidator).to receive(:options).and_return({})
|
43
43
|
end
|
44
44
|
|
45
|
-
error_message = Helpers::Translator.error_message(LocationValidator, :
|
45
|
+
error_message = Helpers::Translator.error_message(LocationValidator, :inclusion)
|
46
46
|
|
47
47
|
it_behaves_like "an invalid record",
|
48
48
|
validatable: validatable,
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
module Test
|
6
|
+
PastDateValidatable = Struct.new(:date) do
|
7
|
+
include ActiveModel::Validations
|
8
|
+
|
9
|
+
validates :date, "defra_ruby/validators/past_date": true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module DefraRuby
|
14
|
+
module Validators
|
15
|
+
RSpec.describe PastDateValidator, type: :model do
|
16
|
+
|
17
|
+
valid_date = Date.today
|
18
|
+
future_date = Date.today + 1
|
19
|
+
invalid_date = Date.new(20, 2, 2)
|
20
|
+
|
21
|
+
it_behaves_like "a valid record", Test::PastDateValidatable.new(valid_date)
|
22
|
+
it_behaves_like "an invalid record",
|
23
|
+
validatable: Test::PastDateValidatable.new(future_date),
|
24
|
+
attribute: :date,
|
25
|
+
error: :past_date,
|
26
|
+
error_message: Helpers::Translator.error_message(PastDateValidator, :past_date)
|
27
|
+
|
28
|
+
it_behaves_like "an invalid record",
|
29
|
+
validatable: Test::PastDateValidatable.new(invalid_date),
|
30
|
+
attribute: :date,
|
31
|
+
error: :invalid_date,
|
32
|
+
error_message: Helpers::Translator.error_message(PastDateValidator, :invalid_date)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -44,7 +44,7 @@ module DefraRuby
|
|
44
44
|
context "when the phone number is not valid" do
|
45
45
|
context "because the phone number is not correctly formatted" do
|
46
46
|
validatable = Test::PhoneNumberValidatable.new(invalid_number)
|
47
|
-
error_message = Helpers::Translator.error_message(PhoneNumberValidator, :
|
47
|
+
error_message = Helpers::Translator.error_message(PhoneNumberValidator, :invalid_format)
|
48
48
|
|
49
49
|
it_behaves_like "an invalid record",
|
50
50
|
validatable: validatable,
|
@@ -30,7 +30,7 @@ module DefraRuby
|
|
30
30
|
context "when the token is not valid" do
|
31
31
|
context "because the token is not correctly formatted" do
|
32
32
|
validatable = Test::TokenValidatable.new(invalid_token)
|
33
|
-
error_message = Helpers::Translator.error_message(TokenValidator, :
|
33
|
+
error_message = Helpers::Translator.error_message(TokenValidator, :invalid_format)
|
34
34
|
|
35
35
|
it_behaves_like "an invalid record",
|
36
36
|
validatable: validatable,
|
@@ -13,17 +13,24 @@ end
|
|
13
13
|
module DefraRuby
|
14
14
|
module Validators
|
15
15
|
RSpec.describe TrueFalseValidator do
|
16
|
-
|
17
|
-
valid_value = %w[true false].sample
|
18
16
|
invalid_value = "unsure"
|
19
17
|
|
20
18
|
it_behaves_like("a validator")
|
19
|
+
|
20
|
+
it_behaves_like(
|
21
|
+
"a selection validator",
|
22
|
+
TrueFalseValidator,
|
23
|
+
Test::TrueFalseValidatable,
|
24
|
+
:attribute,
|
25
|
+
valid: true, invalid: invalid_value
|
26
|
+
)
|
27
|
+
|
21
28
|
it_behaves_like(
|
22
29
|
"a selection validator",
|
23
30
|
TrueFalseValidator,
|
24
31
|
Test::TrueFalseValidatable,
|
25
32
|
:attribute,
|
26
|
-
valid:
|
33
|
+
valid: false, invalid: invalid_value
|
27
34
|
)
|
28
35
|
end
|
29
36
|
end
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module Helpers
|
4
4
|
module Translator
|
5
|
-
def self.error_message(klass,
|
5
|
+
def self.error_message(klass, error)
|
6
6
|
class_name = klass_name(klass)
|
7
7
|
|
8
|
-
I18n.t("defra_ruby.validators.#{class_name}.#{
|
8
|
+
I18n.t("defra_ruby.validators.#{class_name}.#{error}")
|
9
9
|
end
|
10
10
|
|
11
11
|
def self.klass_name(klass)
|
@@ -16,7 +16,7 @@ RSpec.shared_examples "a characters validator" do |validator, validatable_class,
|
|
16
16
|
context "when the #{attribute} is not valid" do
|
17
17
|
context "because the #{attribute} is not correctly formatted" do
|
18
18
|
validatable = validatable_class.new(values[:invalid])
|
19
|
-
error_message = Helpers::Translator.error_message(validator,
|
19
|
+
error_message = Helpers::Translator.error_message(validator, :invalid_format)
|
20
20
|
|
21
21
|
it_behaves_like "an invalid record",
|
22
22
|
validatable: validatable,
|
@@ -16,7 +16,7 @@ RSpec.shared_examples "a length validator" do |validator, validatable_class, att
|
|
16
16
|
context "when the #{attribute} is not valid" do
|
17
17
|
context "because the #{attribute} is too long" do
|
18
18
|
validatable = validatable_class.new(values[:invalid])
|
19
|
-
error_message = Helpers::Translator.error_message(validator,
|
19
|
+
error_message = Helpers::Translator.error_message(validator, :too_long)
|
20
20
|
|
21
21
|
it_behaves_like "an invalid record",
|
22
22
|
validatable: validatable,
|
@@ -16,7 +16,7 @@ RSpec.shared_examples "a presence validator" do |validator, validatable_class, a
|
|
16
16
|
context "when the #{attribute} is not valid" do
|
17
17
|
context "because the #{attribute} is not present" do
|
18
18
|
validatable = validatable_class.new
|
19
|
-
error_message = Helpers::Translator.error_message(validator,
|
19
|
+
error_message = Helpers::Translator.error_message(validator, :blank)
|
20
20
|
|
21
21
|
it_behaves_like "an invalid record",
|
22
22
|
validatable: validatable,
|
@@ -16,7 +16,7 @@ RSpec.shared_examples "a selection validator" do |validator, validatable_class,
|
|
16
16
|
context "when the #{attribute} is not valid" do
|
17
17
|
context "because the #{attribute} is not present" do
|
18
18
|
validatable = validatable_class.new
|
19
|
-
error_message = Helpers::Translator.error_message(validator,
|
19
|
+
error_message = Helpers::Translator.error_message(validator, :inclusion)
|
20
20
|
|
21
21
|
it_behaves_like "an invalid record",
|
22
22
|
validatable: validatable,
|
@@ -27,7 +27,7 @@ RSpec.shared_examples "a selection validator" do |validator, validatable_class,
|
|
27
27
|
|
28
28
|
context "because the #{attribute} is not from an approved list" do
|
29
29
|
validatable = validatable_class.new(values[:invalid])
|
30
|
-
error_message = Helpers::Translator.error_message(validator,
|
30
|
+
error_message = Helpers::Translator.error_message(validator, :inclusion)
|
31
31
|
|
32
32
|
it_behaves_like "an invalid record",
|
33
33
|
validatable: validatable,
|
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.
|
4
|
+
version: 2.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Defra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -180,32 +180,18 @@ dependencies:
|
|
180
180
|
version: '3.0'
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: simplecov
|
183
|
-
requirement: !ruby/object:Gem::Requirement
|
184
|
-
requirements:
|
185
|
-
- - ">="
|
186
|
-
- !ruby/object:Gem::Version
|
187
|
-
version: '0'
|
188
|
-
type: :development
|
189
|
-
prerelease: false
|
190
|
-
version_requirements: !ruby/object:Gem::Requirement
|
191
|
-
requirements:
|
192
|
-
- - ">="
|
193
|
-
- !ruby/object:Gem::Version
|
194
|
-
version: '0'
|
195
|
-
- !ruby/object:Gem::Dependency
|
196
|
-
name: vcr
|
197
183
|
requirement: !ruby/object:Gem::Requirement
|
198
184
|
requirements:
|
199
185
|
- - "~>"
|
200
186
|
- !ruby/object:Gem::Version
|
201
|
-
version:
|
187
|
+
version: 0.17.1
|
202
188
|
type: :development
|
203
189
|
prerelease: false
|
204
190
|
version_requirements: !ruby/object:Gem::Requirement
|
205
191
|
requirements:
|
206
192
|
- - "~>"
|
207
193
|
- !ruby/object:Gem::Version
|
208
|
-
version:
|
194
|
+
version: 0.17.1
|
209
195
|
- !ruby/object:Gem::Dependency
|
210
196
|
name: webmock
|
211
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -237,6 +223,7 @@ files:
|
|
237
223
|
- config/locales/defra_ruby/validators/email_validator/en.yml
|
238
224
|
- config/locales/defra_ruby/validators/grid_reference_validator/en.yml
|
239
225
|
- config/locales/defra_ruby/validators/location_validator/en.yml
|
226
|
+
- config/locales/defra_ruby/validators/past_date_validator/en.yml
|
240
227
|
- config/locales/defra_ruby/validators/phone_number_validator/en.yml
|
241
228
|
- config/locales/defra_ruby/validators/position_validator/en.yml
|
242
229
|
- config/locales/defra_ruby/validators/token_validator/en.yml
|
@@ -255,15 +242,13 @@ files:
|
|
255
242
|
- lib/defra_ruby/validators/engine.rb
|
256
243
|
- lib/defra_ruby/validators/grid_reference_validator.rb
|
257
244
|
- lib/defra_ruby/validators/location_validator.rb
|
245
|
+
- lib/defra_ruby/validators/past_date_validator.rb
|
258
246
|
- lib/defra_ruby/validators/phone_number_validator.rb
|
259
247
|
- lib/defra_ruby/validators/position_validator.rb
|
260
248
|
- lib/defra_ruby/validators/token_validator.rb
|
261
249
|
- lib/defra_ruby/validators/true_false_validator.rb
|
262
250
|
- lib/defra_ruby/validators/version.rb
|
263
251
|
- lib/defra_ruby_validators.rb
|
264
|
-
- spec/cassettes/company_no_inactive.yml
|
265
|
-
- spec/cassettes/company_no_not_found.yml
|
266
|
-
- spec/cassettes/company_no_valid.yml
|
267
252
|
- spec/defra_ruby/validators/business_type_validator_spec.rb
|
268
253
|
- spec/defra_ruby/validators/companies_house_number_validator_spec.rb
|
269
254
|
- spec/defra_ruby/validators/companies_house_service_spec.rb
|
@@ -271,12 +256,12 @@ files:
|
|
271
256
|
- spec/defra_ruby/validators/email_validator_spec.rb
|
272
257
|
- spec/defra_ruby/validators/grid_reference_validator_spec.rb
|
273
258
|
- spec/defra_ruby/validators/location_validator_spec.rb
|
259
|
+
- spec/defra_ruby/validators/past_date_validator_spec.rb
|
274
260
|
- spec/defra_ruby/validators/phone_number_validator_spec.rb
|
275
261
|
- spec/defra_ruby/validators/position_validator_spec.rb
|
276
262
|
- spec/defra_ruby/validators/token_validator_spec.rb
|
277
263
|
- spec/defra_ruby/validators/true_false_validator_spec.rb
|
278
264
|
- spec/defra_ruby/validators_spec.rb
|
279
|
-
- spec/examples.txt
|
280
265
|
- spec/spec_helper.rb
|
281
266
|
- spec/support/defra_ruby_validators.rb
|
282
267
|
- spec/support/helpers/text_generator.rb
|
@@ -291,7 +276,6 @@ files:
|
|
291
276
|
- spec/support/shared_examples/validators/valid_record.rb
|
292
277
|
- spec/support/shared_examples/validators/validator.rb
|
293
278
|
- spec/support/simplecov.rb
|
294
|
-
- spec/support/vcr.rb
|
295
279
|
homepage: https://github.com/DEFRA/defra-ruby-validators
|
296
280
|
licenses:
|
297
281
|
- The Open Government Licence (OGL) Version 3
|
@@ -320,6 +304,7 @@ summary: Defra ruby on rails validations
|
|
320
304
|
test_files:
|
321
305
|
- spec/spec_helper.rb
|
322
306
|
- spec/defra_ruby/validators_spec.rb
|
307
|
+
- spec/defra_ruby/validators/past_date_validator_spec.rb
|
323
308
|
- spec/defra_ruby/validators/companies_house_service_spec.rb
|
324
309
|
- spec/defra_ruby/validators/configuration_spec.rb
|
325
310
|
- spec/defra_ruby/validators/phone_number_validator_spec.rb
|
@@ -331,13 +316,8 @@ test_files:
|
|
331
316
|
- spec/defra_ruby/validators/true_false_validator_spec.rb
|
332
317
|
- spec/defra_ruby/validators/location_validator_spec.rb
|
333
318
|
- spec/defra_ruby/validators/email_validator_spec.rb
|
334
|
-
- spec/examples.txt
|
335
|
-
- spec/cassettes/company_no_not_found.yml
|
336
|
-
- spec/cassettes/company_no_valid.yml
|
337
|
-
- spec/cassettes/company_no_inactive.yml
|
338
319
|
- spec/support/simplecov.rb
|
339
320
|
- spec/support/i18n.rb
|
340
|
-
- spec/support/vcr.rb
|
341
321
|
- spec/support/pry.rb
|
342
322
|
- spec/support/defra_ruby_validators.rb
|
343
323
|
- spec/support/helpers/translator.rb
|
@@ -1,67 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: get
|
5
|
-
uri: https://api.companieshouse.gov.uk/company/07281919
|
6
|
-
body:
|
7
|
-
encoding: US-ASCII
|
8
|
-
string: ''
|
9
|
-
headers:
|
10
|
-
Accept:
|
11
|
-
- "*/*"
|
12
|
-
Accept-Encoding:
|
13
|
-
- gzip, deflate
|
14
|
-
User-Agent:
|
15
|
-
- rest-client/2.0.2 (darwin16.7.0 x86_64) ruby/2.4.2p198
|
16
|
-
Host:
|
17
|
-
- api.companieshouse.gov.uk
|
18
|
-
Authorization:
|
19
|
-
- Basic MnZodWowb1dhYk13N2h6TnpBVWlTT2ctNktpVVRCcFhCRF83Zktibzo=
|
20
|
-
response:
|
21
|
-
status:
|
22
|
-
code: 200
|
23
|
-
message: OK
|
24
|
-
headers:
|
25
|
-
Date:
|
26
|
-
- Tue, 20 Aug 2019 14:28:41 GMT
|
27
|
-
Content-Type:
|
28
|
-
- application/json
|
29
|
-
Content-Length:
|
30
|
-
- '979'
|
31
|
-
Connection:
|
32
|
-
- keep-alive
|
33
|
-
Access-Control-Allow-Credentials:
|
34
|
-
- 'true'
|
35
|
-
Access-Control-Allow-Headers:
|
36
|
-
- X-RateLimit-Query, origin, content-type, content-length, user-agent, host,
|
37
|
-
accept, authorization
|
38
|
-
Access-Control-Expose-Headers:
|
39
|
-
- Location,www-authenticate,cache-control,pragma,content-type,expires,last-modified
|
40
|
-
- X-RateLimit-Window, X-RateLimit-Limit, X-RateLimit-Remain, X-RateLimit-Reset,
|
41
|
-
Location, www-authenticate, cache-control, pragma, content-type, expires,
|
42
|
-
last-modified
|
43
|
-
Access-Control-Max-Age:
|
44
|
-
- '3600'
|
45
|
-
Cache-Control:
|
46
|
-
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
47
|
-
Pragma:
|
48
|
-
- no-cache
|
49
|
-
X-Ratelimit-Limit:
|
50
|
-
- '600'
|
51
|
-
X-Ratelimit-Remain:
|
52
|
-
- '590'
|
53
|
-
X-Ratelimit-Reset:
|
54
|
-
- '1566311455'
|
55
|
-
X-Ratelimit-Window:
|
56
|
-
- 5m
|
57
|
-
Server:
|
58
|
-
- CompaniesHouse
|
59
|
-
body:
|
60
|
-
encoding: UTF-8
|
61
|
-
string: '{"sic_codes":["82990"],"company_number":"07281919","has_been_liquidated":false,"accounts":{"last_accounts":{"made_up_to":"2013-06-30","type":"total-exemption-small"},"accounting_reference_date":{"day":"30","month":"06"}},"last_full_members_list_date":"2014-06-11","status":"active","type":"ltd","date_of_creation":"2010-06-11","registered_office_address":{"postal_code":"HA8
|
62
|
-
7EJ","locality":"Edgware","region":"Middlesex","address_line_1":"8th Floor
|
63
|
-
Elizabeth House","address_line_2":"54-58 High Street"},"undeliverable_registered_office_address":false,"company_name":"DIRECT
|
64
|
-
SKIPS UK LTD","annual_return":{"last_made_up_to":"2014-06-11"},"jurisdiction":"england-wales","etag":"1cdef5bc2a020b3e9003b086033b64b78bcb28f6","company_status":"dissolved","has_insolvency_history":false,"has_charges":false,"links":{"self":"/company/07281919","filing_history":"/company/07281919/filing-history","officers":"/company/07281919/officers"},"date_of_cessation":"2016-01-05","can_file":false}'
|
65
|
-
http_version:
|
66
|
-
recorded_at: Tue, 20 Aug 2019 14:28:41 GMT
|
67
|
-
recorded_with: VCR 4.0.0
|
@@ -1,64 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: get
|
5
|
-
uri: https://api.companieshouse.gov.uk/company/99999999
|
6
|
-
body:
|
7
|
-
encoding: US-ASCII
|
8
|
-
string: ''
|
9
|
-
headers:
|
10
|
-
Accept:
|
11
|
-
- "*/*"
|
12
|
-
Accept-Encoding:
|
13
|
-
- gzip, deflate
|
14
|
-
User-Agent:
|
15
|
-
- rest-client/2.0.2 (darwin16.7.0 x86_64) ruby/2.4.2p198
|
16
|
-
Host:
|
17
|
-
- api.companieshouse.gov.uk
|
18
|
-
Authorization:
|
19
|
-
- Basic MnZodWowb1dhYk13N2h6TnpBVWlTT2ctNktpVVRCcFhCRF83Zktibzo=
|
20
|
-
response:
|
21
|
-
status:
|
22
|
-
code: 404
|
23
|
-
message: Not Found
|
24
|
-
headers:
|
25
|
-
Date:
|
26
|
-
- Tue, 20 Aug 2019 14:28:41 GMT
|
27
|
-
Content-Type:
|
28
|
-
- application/json
|
29
|
-
Content-Length:
|
30
|
-
- '70'
|
31
|
-
Connection:
|
32
|
-
- keep-alive
|
33
|
-
Access-Control-Allow-Credentials:
|
34
|
-
- 'true'
|
35
|
-
Access-Control-Allow-Headers:
|
36
|
-
- X-RateLimit-Query, origin, content-type, content-length, user-agent, host,
|
37
|
-
accept, authorization
|
38
|
-
Access-Control-Expose-Headers:
|
39
|
-
- Location,www-authenticate,cache-control,pragma,content-type,expires,last-modified
|
40
|
-
- X-RateLimit-Window, X-RateLimit-Limit, X-RateLimit-Remain, X-RateLimit-Reset,
|
41
|
-
Location, www-authenticate, cache-control, pragma, content-type, expires,
|
42
|
-
last-modified
|
43
|
-
Access-Control-Max-Age:
|
44
|
-
- '3600'
|
45
|
-
Cache-Control:
|
46
|
-
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
47
|
-
Pragma:
|
48
|
-
- no-cache
|
49
|
-
X-Ratelimit-Limit:
|
50
|
-
- '600'
|
51
|
-
X-Ratelimit-Remain:
|
52
|
-
- '591'
|
53
|
-
X-Ratelimit-Reset:
|
54
|
-
- '1566311455'
|
55
|
-
X-Ratelimit-Window:
|
56
|
-
- 5m
|
57
|
-
Server:
|
58
|
-
- CompaniesHouse
|
59
|
-
body:
|
60
|
-
encoding: UTF-8
|
61
|
-
string: '{"errors":[{"type":"ch:service","error":"company-profile-not-found"}]}'
|
62
|
-
http_version:
|
63
|
-
recorded_at: Tue, 20 Aug 2019 14:28:41 GMT
|
64
|
-
recorded_with: VCR 4.0.0
|
@@ -1,65 +0,0 @@
|
|
1
|
-
---
|
2
|
-
http_interactions:
|
3
|
-
- request:
|
4
|
-
method: get
|
5
|
-
uri: https://api.companieshouse.gov.uk/company/09360070
|
6
|
-
body:
|
7
|
-
encoding: US-ASCII
|
8
|
-
string: ''
|
9
|
-
headers:
|
10
|
-
Accept:
|
11
|
-
- "*/*"
|
12
|
-
Accept-Encoding:
|
13
|
-
- gzip, deflate
|
14
|
-
User-Agent:
|
15
|
-
- rest-client/2.0.2 (darwin16.7.0 x86_64) ruby/2.4.2p198
|
16
|
-
Host:
|
17
|
-
- api.companieshouse.gov.uk
|
18
|
-
Authorization:
|
19
|
-
- Basic MnZodWowb1dhYk13N2h6TnpBVWlTT2ctNktpVVRCcFhCRF83Zktibzo=
|
20
|
-
response:
|
21
|
-
status:
|
22
|
-
code: 200
|
23
|
-
message: OK
|
24
|
-
headers:
|
25
|
-
Date:
|
26
|
-
- Tue, 20 Aug 2019 14:28:40 GMT
|
27
|
-
Content-Type:
|
28
|
-
- application/json
|
29
|
-
Content-Length:
|
30
|
-
- '1178'
|
31
|
-
Connection:
|
32
|
-
- keep-alive
|
33
|
-
Access-Control-Allow-Credentials:
|
34
|
-
- 'true'
|
35
|
-
Access-Control-Allow-Headers:
|
36
|
-
- X-RateLimit-Query, origin, content-type, content-length, user-agent, host,
|
37
|
-
accept, authorization
|
38
|
-
Access-Control-Expose-Headers:
|
39
|
-
- Location,www-authenticate,cache-control,pragma,content-type,expires,last-modified
|
40
|
-
- X-RateLimit-Window, X-RateLimit-Limit, X-RateLimit-Remain, X-RateLimit-Reset,
|
41
|
-
Location, www-authenticate, cache-control, pragma, content-type, expires,
|
42
|
-
last-modified
|
43
|
-
Access-Control-Max-Age:
|
44
|
-
- '3600'
|
45
|
-
Cache-Control:
|
46
|
-
- no-store, no-cache, must-revalidate, post-check=0, pre-check=0
|
47
|
-
Pragma:
|
48
|
-
- no-cache
|
49
|
-
X-Ratelimit-Limit:
|
50
|
-
- '600'
|
51
|
-
X-Ratelimit-Remain:
|
52
|
-
- '592'
|
53
|
-
X-Ratelimit-Reset:
|
54
|
-
- '1566311455'
|
55
|
-
X-Ratelimit-Window:
|
56
|
-
- 5m
|
57
|
-
Server:
|
58
|
-
- CompaniesHouse
|
59
|
-
body:
|
60
|
-
encoding: UTF-8
|
61
|
-
string: '{"type":"ltd","company_name":"0800 WASTE LTD.","has_insolvency_history":false,"accounts":{"next_due":"2019-09-30","next_made_up_to":"2018-12-31","next_accounts":{"overdue":false,"period_start_on":"2018-01-01","due_on":"2019-09-30","period_end_on":"2018-12-31"},"accounting_reference_date":{"month":"12","day":"31"},"last_accounts":{"period_end_on":"2017-12-31","period_start_on":"2017-01-01","made_up_to":"2017-12-31"},"overdue":false},"undeliverable_registered_office_address":false,"etag":"0ec9d00cab0ffee2ef1f5d59f4f714fa5b1618f5","company_number":"09360070","registered_office_address":{"postal_code":"SM3
|
62
|
-
9ND","locality":"Sutton","region":"Surrey","address_line_1":"21 Haslam Avenue"},"jurisdiction":"england-wales","date_of_creation":"2014-12-18","company_status":"active","has_charges":false,"sic_codes":["38110"],"last_full_members_list_date":"2015-12-18","confirmation_statement":{"overdue":false,"next_made_up_to":"2020-01-23","last_made_up_to":"2019-01-23","next_due":"2020-02-06"},"links":{"self":"/company/09360070","filing_history":"/company/09360070/filing-history","officers":"/company/09360070/officers"},"registered_office_is_in_dispute":false,"can_file":true}'
|
63
|
-
http_version:
|
64
|
-
recorded_at: Tue, 20 Aug 2019 14:28:40 GMT
|
65
|
-
recorded_with: VCR 4.0.0
|
data/spec/examples.txt
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
example_id | status | run_time |
|
2
|
-
---------------------------------------------------------------------------------- | ------ | --------------- |
|
3
|
-
./spec/defra_ruby/validators/business_type_validator_spec.rb[1:1:1] | passed | 0.00145 seconds |
|
4
|
-
./spec/defra_ruby/validators/business_type_validator_spec.rb[1:2:1] | passed | 0.00011 seconds |
|
5
|
-
./spec/defra_ruby/validators/business_type_validator_spec.rb[1:2:2:1:1:1] | passed | 0.00017 seconds |
|
6
|
-
./spec/defra_ruby/validators/business_type_validator_spec.rb[1:2:2:1:1:2] | passed | 0.00445 seconds |
|
7
|
-
./spec/defra_ruby/validators/business_type_validator_spec.rb[1:2:2:2:1:1:1] | passed | 0.00018 seconds |
|
8
|
-
./spec/defra_ruby/validators/business_type_validator_spec.rb[1:2:2:2:1:1:2] | passed | 0.00016 seconds |
|
9
|
-
./spec/defra_ruby/validators/business_type_validator_spec.rb[1:2:2:2:1:1:3] | passed | 0.00059 seconds |
|
10
|
-
./spec/defra_ruby/validators/business_type_validator_spec.rb[1:2:2:2:2:1:1] | passed | 0.00016 seconds |
|
11
|
-
./spec/defra_ruby/validators/business_type_validator_spec.rb[1:2:2:2:2:1:2] | passed | 0.0002 seconds |
|
12
|
-
./spec/defra_ruby/validators/business_type_validator_spec.rb[1:2:2:2:2:1:3] | passed | 0.00018 seconds |
|
13
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:1:1] | passed | 0.00009 seconds |
|
14
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:1:1:1:1] | passed | 0.00043 seconds |
|
15
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:1:1:1:2] | passed | 0.00044 seconds |
|
16
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:1:2:1:1] | passed | 0.00043 seconds |
|
17
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:1:2:1:2] | passed | 0.00041 seconds |
|
18
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:1:3:1:1] | passed | 0.00045 seconds |
|
19
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:1:3:1:2] | passed | 0.00646 seconds |
|
20
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:1:4:1:1] | passed | 0.00042 seconds |
|
21
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:1:4:1:2] | passed | 0.00038 seconds |
|
22
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:1:1:1] | passed | 0.00015 seconds |
|
23
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:1:1:2] | passed | 0.00016 seconds |
|
24
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:1:1:3] | passed | 0.00017 seconds |
|
25
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:2:1:1] | passed | 0.00017 seconds |
|
26
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:2:1:2] | passed | 0.00015 seconds |
|
27
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:2:1:3] | passed | 0.0002 seconds |
|
28
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:3:1:1] | passed | 0.00046 seconds |
|
29
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:3:1:2] | passed | 0.00042 seconds |
|
30
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:3:1:3] | passed | 0.00043 seconds |
|
31
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:4:1:1] | passed | 0.00046 seconds |
|
32
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:4:1:2] | passed | 0.00046 seconds |
|
33
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:2:4:1:3] | passed | 0.00044 seconds |
|
34
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:3:1:1] | passed | 0.00045 seconds |
|
35
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:3:1:2] | passed | 0.00042 seconds |
|
36
|
-
./spec/defra_ruby/validators/companies_house_number_validator_spec.rb[1:2:3:1:3] | passed | 0.00046 seconds |
|
37
|
-
./spec/defra_ruby/validators/companies_house_service_spec.rb[1:1:1:1] | passed | 0.10949 seconds |
|
38
|
-
./spec/defra_ruby/validators/companies_house_service_spec.rb[1:1:2:1] | passed | 0.22067 seconds |
|
39
|
-
./spec/defra_ruby/validators/companies_house_service_spec.rb[1:1:3:1] | passed | 0.11422 seconds |
|
40
|
-
./spec/defra_ruby/validators/companies_house_service_spec.rb[1:1:4:1:1] | passed | 0.01368 seconds |
|
41
|
-
./spec/defra_ruby/validators/companies_house_service_spec.rb[1:1:4:2:1] | passed | 0.01557 seconds |
|
42
|
-
./spec/defra_ruby/validators/configuration_spec.rb[1:1:1] | passed | 0.0014 seconds |
|
43
|
-
./spec/defra_ruby/validators/configuration_spec.rb[1:2] | passed | 0.00045 seconds |
|
44
|
-
./spec/defra_ruby/validators/configuration_spec.rb[1:3:1:1] | passed | 0.00113 seconds |
|
45
|
-
./spec/defra_ruby/validators/configuration_spec.rb[1:3:2:1] | passed | 0.00015 seconds |
|
46
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:1:1] | passed | 0.0001 seconds |
|
47
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:2:1] | passed | 0.0001 seconds |
|
48
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:2:2:1:1:1] | passed | 0.00014 seconds |
|
49
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:2:2:1:1:2] | passed | 0.00013 seconds |
|
50
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:2:2:2:1:1:1] | passed | 0.00018 seconds |
|
51
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:2:2:2:1:1:2] | passed | 0.00019 seconds |
|
52
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:2:2:2:1:1:3] | passed | 0.00023 seconds |
|
53
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:3:1] | passed | 0.00013 seconds |
|
54
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:3:2:1:1:1] | passed | 0.00017 seconds |
|
55
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:3:2:1:1:2] | passed | 0.00015 seconds |
|
56
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:3:2:2:1:1:1] | passed | 0.00021 seconds |
|
57
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:3:2:2:1:1:2] | passed | 0.00019 seconds |
|
58
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:3:2:2:1:1:3] | passed | 0.0003 seconds |
|
59
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:4:1:1:1:1] | passed | 0.00014 seconds |
|
60
|
-
./spec/defra_ruby/validators/position_validator_spec.rb[1:4:1:1:1:2] | passed | 0.00018 seconds |
|
61
|
-
./spec/defra_ruby/validators/token_validator_spec.rb[1:1:1] | passed | 0.00009 seconds |
|
62
|
-
./spec/defra_ruby/validators/token_validator_spec.rb[1:2:1] | passed | 0.00012 seconds |
|
63
|
-
./spec/defra_ruby/validators/token_validator_spec.rb[1:2:2:1:1:1] | passed | 0.0002 seconds |
|
64
|
-
./spec/defra_ruby/validators/token_validator_spec.rb[1:2:2:1:1:2] | passed | 0.00012 seconds |
|
65
|
-
./spec/defra_ruby/validators/token_validator_spec.rb[1:2:2:2:1:1:1] | passed | 0.00018 seconds |
|
66
|
-
./spec/defra_ruby/validators/token_validator_spec.rb[1:2:2:2:1:1:2] | passed | 0.00014 seconds |
|
67
|
-
./spec/defra_ruby/validators/token_validator_spec.rb[1:2:2:2:1:1:3] | passed | 0.00017 seconds |
|
68
|
-
./spec/defra_ruby/validators/token_validator_spec.rb[1:3:1:1:1:1] | passed | 0.00018 seconds |
|
69
|
-
./spec/defra_ruby/validators/token_validator_spec.rb[1:3:1:1:1:2] | passed | 0.00016 seconds |
|
70
|
-
./spec/defra_ruby/validators/token_validator_spec.rb[1:3:1:1:1:3] | passed | 0.00015 seconds |
|
71
|
-
./spec/defra_ruby/validators/true_false_validator_spec.rb[1:1:1] | passed | 0.0001 seconds |
|
72
|
-
./spec/defra_ruby/validators/true_false_validator_spec.rb[1:2:1] | passed | 0.0001 seconds |
|
73
|
-
./spec/defra_ruby/validators/true_false_validator_spec.rb[1:2:2:1:1:1] | passed | 0.00014 seconds |
|
74
|
-
./spec/defra_ruby/validators/true_false_validator_spec.rb[1:2:2:1:1:2] | passed | 0.00015 seconds |
|
75
|
-
./spec/defra_ruby/validators/true_false_validator_spec.rb[1:2:2:2:1:1:1] | passed | 0.00017 seconds |
|
76
|
-
./spec/defra_ruby/validators/true_false_validator_spec.rb[1:2:2:2:1:1:2] | passed | 0.00016 seconds |
|
77
|
-
./spec/defra_ruby/validators/true_false_validator_spec.rb[1:2:2:2:1:1:3] | passed | 0.00024 seconds |
|
78
|
-
./spec/defra_ruby/validators/true_false_validator_spec.rb[1:2:2:2:2:1:1] | passed | 0.00019 seconds |
|
79
|
-
./spec/defra_ruby/validators/true_false_validator_spec.rb[1:2:2:2:2:1:2] | passed | 0.00018 seconds |
|
80
|
-
./spec/defra_ruby/validators/true_false_validator_spec.rb[1:2:2:2:2:1:3] | passed | 0.00019 seconds |
|
81
|
-
./spec/defra_ruby/validators_spec.rb[1:1:1] | passed | 0.001 seconds |
|
data/spec/support/vcr.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Stubbing HTTP requests
|
4
|
-
require "webmock/rspec"
|
5
|
-
# Auto generate fake responses for web-requests
|
6
|
-
require "vcr"
|
7
|
-
|
8
|
-
VCR.configure do |c|
|
9
|
-
c.cassette_library_dir = "spec/cassettes"
|
10
|
-
c.hook_into :webmock
|
11
|
-
|
12
|
-
c.ignore_hosts "127.0.0.1", "codeclimate.com"
|
13
|
-
|
14
|
-
SECONDS_IN_DAY = 24 * 60 * 60
|
15
|
-
|
16
|
-
c.default_cassette_options = { re_record_interval: (14 * SECONDS_IN_DAY) }
|
17
|
-
|
18
|
-
# Strip out authorization info
|
19
|
-
c.filter_sensitive_data("Basic <API_KEY>") do |interaction|
|
20
|
-
auth = interaction.request.headers["Authorization"]
|
21
|
-
auth.first if auth.nil? || auth.empty?
|
22
|
-
end
|
23
|
-
end
|