defra_ruby_validators 2.4.1 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +9 -2
- data/lib/defra_ruby/validators/companies_house_number_validator.rb +9 -5
- data/lib/defra_ruby/validators/companies_house_service.rb +26 -12
- data/lib/defra_ruby/validators/version.rb +1 -1
- metadata +22 -174
- data/spec/defra_ruby/validators/business_type_validator_spec.rb +0 -56
- data/spec/defra_ruby/validators/companies_house_number_validator_spec.rb +0 -108
- data/spec/defra_ruby/validators/companies_house_service_spec.rb +0 -70
- data/spec/defra_ruby/validators/configuration_spec.rb +0 -49
- data/spec/defra_ruby/validators/email_validator_spec.rb +0 -46
- data/spec/defra_ruby/validators/grid_reference_validator_spec.rb +0 -57
- data/spec/defra_ruby/validators/location_validator_spec.rb +0 -56
- data/spec/defra_ruby/validators/past_date_validator_spec.rb +0 -35
- data/spec/defra_ruby/validators/phone_number_validator_spec.rb +0 -59
- data/spec/defra_ruby/validators/position_validator_spec.rb +0 -47
- data/spec/defra_ruby/validators/token_validator_spec.rb +0 -45
- data/spec/defra_ruby/validators/true_false_validator_spec.rb +0 -37
- data/spec/defra_ruby/validators_spec.rb +0 -12
- data/spec/spec_helper.rb +0 -87
- data/spec/support/defra_ruby_validators.rb +0 -16
- data/spec/support/helpers/text_generator.rb +0 -17
- data/spec/support/helpers/translator.rb +0 -15
- data/spec/support/i18n.rb +0 -8
- data/spec/support/pry.rb +0 -7
- data/spec/support/shared_examples/validators/characters_validator.rb +0 -29
- data/spec/support/shared_examples/validators/invalid_record.rb +0 -29
- data/spec/support/shared_examples/validators/length_validator.rb +0 -29
- data/spec/support/shared_examples/validators/presence_validator.rb +0 -29
- data/spec/support/shared_examples/validators/selection_validator.rb +0 -40
- data/spec/support/shared_examples/validators/valid_record.rb +0 -12
- data/spec/support/shared_examples/validators/validator.rb +0 -8
- data/spec/support/simplecov.rb +0 -17
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.shared_examples "a length validator" do |validator, validatable_class, attribute, values|
|
4
|
-
it "includes CanValidateLength" do
|
5
|
-
included_modules = described_class.ancestors.select { |ancestor| ancestor.instance_of?(Module) }
|
6
|
-
|
7
|
-
expect(included_modules)
|
8
|
-
.to include(DefraRuby::Validators::CanValidateLength)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#validate_each" do
|
12
|
-
context "when the #{attribute} is valid" do
|
13
|
-
it_behaves_like "a valid record", validatable_class.new(values[:valid])
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when the #{attribute} is not valid" do
|
17
|
-
context "because the #{attribute} is too long" do
|
18
|
-
validatable = validatable_class.new(values[:invalid])
|
19
|
-
error_message = Helpers::Translator.error_message(validator, :too_long)
|
20
|
-
|
21
|
-
it_behaves_like "an invalid record",
|
22
|
-
validatable: validatable,
|
23
|
-
attribute: attribute,
|
24
|
-
error: :too_long,
|
25
|
-
error_message: error_message
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.shared_examples "a presence validator" do |validator, validatable_class, attribute, values|
|
4
|
-
it "includes CanValidatePresence" do
|
5
|
-
included_modules = described_class.ancestors.select { |ancestor| ancestor.instance_of?(Module) }
|
6
|
-
|
7
|
-
expect(included_modules)
|
8
|
-
.to include(DefraRuby::Validators::CanValidatePresence)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#validate_each" do
|
12
|
-
context "when the #{attribute} is valid" do
|
13
|
-
it_behaves_like "a valid record", validatable_class.new(values[:valid])
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when the #{attribute} is not valid" do
|
17
|
-
context "because the #{attribute} is not present" do
|
18
|
-
validatable = validatable_class.new
|
19
|
-
error_message = Helpers::Translator.error_message(validator, :blank)
|
20
|
-
|
21
|
-
it_behaves_like "an invalid record",
|
22
|
-
validatable: validatable,
|
23
|
-
attribute: attribute,
|
24
|
-
error: :blank,
|
25
|
-
error_message: error_message
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.shared_examples "a selection validator" do |validator, validatable_class, attribute, values|
|
4
|
-
it "includes CanValidateSelection" do
|
5
|
-
included_modules = described_class.ancestors.select { |ancestor| ancestor.instance_of?(Module) }
|
6
|
-
|
7
|
-
expect(included_modules)
|
8
|
-
.to include(DefraRuby::Validators::CanValidateSelection)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#validate_each" do
|
12
|
-
context "when the #{attribute} is valid" do
|
13
|
-
it_behaves_like "a valid record", validatable_class.new(values[:valid])
|
14
|
-
end
|
15
|
-
|
16
|
-
context "when the #{attribute} is not valid" do
|
17
|
-
context "because the #{attribute} is not present" do
|
18
|
-
validatable = validatable_class.new
|
19
|
-
error_message = Helpers::Translator.error_message(validator, :inclusion)
|
20
|
-
|
21
|
-
it_behaves_like "an invalid record",
|
22
|
-
validatable: validatable,
|
23
|
-
attribute: attribute,
|
24
|
-
error: :inclusion,
|
25
|
-
error_message: error_message
|
26
|
-
end
|
27
|
-
|
28
|
-
context "because the #{attribute} is not from an approved list" do
|
29
|
-
validatable = validatable_class.new(values[:invalid])
|
30
|
-
error_message = Helpers::Translator.error_message(validator, :inclusion)
|
31
|
-
|
32
|
-
it_behaves_like "an invalid record",
|
33
|
-
validatable: validatable,
|
34
|
-
attribute: attribute,
|
35
|
-
error: :inclusion,
|
36
|
-
error_message: error_message
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.shared_examples "a valid record" do |validatable|
|
4
|
-
it "confirms the object is valid" do
|
5
|
-
expect(validatable).to be_valid
|
6
|
-
end
|
7
|
-
|
8
|
-
it "the errors are empty" do
|
9
|
-
validatable.valid?
|
10
|
-
expect(validatable.errors).to be_empty
|
11
|
-
end
|
12
|
-
end
|
data/spec/support/simplecov.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "simplecov"
|
4
|
-
|
5
|
-
# We start it with the rails param to ensure it includes coverage for all code
|
6
|
-
# started by the rails app, and not just the files touched by our unit tests.
|
7
|
-
# This gives us the most accurate assessment of our unit test coverage
|
8
|
-
# https://github.com/colszowka/simplecov#getting-started
|
9
|
-
SimpleCov.start do
|
10
|
-
# We filter the spec folder, mainly to ensure that any dummy apps don't get
|
11
|
-
# included in the coverage report. However our intent is that nothing in the
|
12
|
-
# spec folder should be included
|
13
|
-
add_filter "/spec/"
|
14
|
-
# The version file is simply just that, so we do not feel the need to ensure
|
15
|
-
# we have a test for it
|
16
|
-
add_filter "lib/defra_ruby/validators/version"
|
17
|
-
end
|