defra_ruby_validators 1.1.0 → 1.2.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 +88 -1
- data/config/locales/defra_ruby/validators/business_type_validator/en.yml +6 -0
- data/config/locales/defra_ruby/validators/email_validator/en.yml +7 -0
- data/config/locales/defra_ruby/validators/grid_reference_validator/en.yml +8 -0
- data/config/locales/defra_ruby/validators/location_validator/en.yml +6 -0
- data/config/locales/defra_ruby/validators/phone_number_validator/en.yml +8 -0
- data/config/locales/defra_ruby/validators/position_validator/en.yml +7 -0
- data/config/locales/defra_ruby/validators/token_validator/en.yml +7 -0
- data/config/locales/defra_ruby/validators/true_false_validator/en.yml +2 -1
- data/lib/defra_ruby/validators.rb +10 -0
- data/lib/defra_ruby/validators/base_validator.rb +2 -4
- data/lib/defra_ruby/validators/business_type_validator.rb +15 -0
- data/lib/defra_ruby/validators/companies_house_number_validator.rb +5 -5
- data/lib/defra_ruby/validators/concerns/can_validate_characters.rb +19 -0
- data/lib/defra_ruby/validators/concerns/can_validate_length.rb +18 -0
- data/lib/defra_ruby/validators/concerns/can_validate_presence.rb +18 -0
- data/lib/defra_ruby/validators/concerns/can_validate_selection.rb +6 -8
- data/lib/defra_ruby/validators/email_validator.rb +28 -0
- data/lib/defra_ruby/validators/grid_reference_validator.rb +55 -0
- data/lib/defra_ruby/validators/location_validator.rb +15 -0
- data/lib/defra_ruby/validators/phone_number_validator.rb +32 -0
- data/lib/defra_ruby/validators/position_validator.rb +22 -0
- data/lib/defra_ruby/validators/token_validator.rb +27 -0
- data/lib/defra_ruby/validators/true_false_validator.rb +2 -2
- data/lib/defra_ruby/validators/version.rb +1 -1
- 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/business_type_validator_spec.rb +30 -0
- data/spec/defra_ruby/validators/companies_house_number_validator_spec.rb +15 -15
- data/spec/defra_ruby/validators/email_validator_spec.rb +42 -0
- data/spec/defra_ruby/validators/grid_reference_validator_spec.rb +49 -0
- data/spec/defra_ruby/validators/location_validator_spec.rb +30 -0
- data/spec/defra_ruby/validators/phone_number_validator_spec.rb +55 -0
- data/spec/defra_ruby/validators/position_validator_spec.rb +47 -0
- data/spec/defra_ruby/validators/token_validator_spec.rb +41 -0
- data/spec/defra_ruby/validators/true_false_validator_spec.rb +11 -4
- data/spec/examples.txt +79 -44
- data/spec/spec_helper.rb +4 -0
- data/spec/support/helpers/text_generator.rb +17 -0
- data/spec/support/helpers/translator.rb +2 -3
- data/spec/support/shared_examples/validators/characters_validator.rb +25 -0
- data/spec/support/shared_examples/validators/invalid_record.rb +13 -3
- data/spec/support/shared_examples/validators/length_validator.rb +25 -0
- data/spec/support/shared_examples/validators/presence_validator.rb +25 -0
- data/spec/support/shared_examples/validators/selection_validator.rb +11 -11
- metadata +70 -19
- data/spec/support/dotenv.rb +0 -4
@@ -0,0 +1,25 @@
|
|
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, attribute, :blank)
|
20
|
+
|
21
|
+
it_behaves_like "an invalid record", validatable, attribute, error_message
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
RSpec.shared_examples "a selection validator" do |validator, validatable_class,
|
3
|
+
RSpec.shared_examples "a selection validator" do |validator, validatable_class, attribute, values|
|
4
4
|
it "includes CanValidateSelection" do
|
5
5
|
included_modules = described_class.ancestors.select { |ancestor| ancestor.instance_of?(Module) }
|
6
6
|
|
@@ -9,23 +9,23 @@ RSpec.shared_examples "a selection validator" do |validator, validatable_class,
|
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "#validate_each" do
|
12
|
-
context "when the #{
|
13
|
-
it_behaves_like "a valid record", validatable_class.new(
|
12
|
+
context "when the #{attribute} is valid" do
|
13
|
+
it_behaves_like "a valid record", validatable_class.new(values[:valid])
|
14
14
|
end
|
15
15
|
|
16
|
-
context "when the #{
|
17
|
-
context "because the #{
|
16
|
+
context "when the #{attribute} is not valid" do
|
17
|
+
context "because the #{attribute} is not present" do
|
18
18
|
validatable = validatable_class.new
|
19
|
-
error_message = Helpers::Translator.error_message(
|
19
|
+
error_message = Helpers::Translator.error_message(validator, attribute, :inclusion)
|
20
20
|
|
21
|
-
it_behaves_like "an invalid record", validatable,
|
21
|
+
it_behaves_like "an invalid record", validatable, attribute, error_message
|
22
22
|
end
|
23
23
|
|
24
|
-
context "because the #{
|
25
|
-
validatable = validatable_class.new(
|
26
|
-
error_message = Helpers::Translator.error_message(
|
24
|
+
context "because the #{attribute} is not from an approved list" do
|
25
|
+
validatable = validatable_class.new(values[:invalid])
|
26
|
+
error_message = Helpers::Translator.error_message(validator, attribute, :inclusion)
|
27
27
|
|
28
|
-
it_behaves_like "an invalid record", validatable,
|
28
|
+
it_behaves_like "an invalid record", validatable, attribute, error_message
|
29
29
|
end
|
30
30
|
end
|
31
31
|
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: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Defra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06
|
11
|
+
date: 2019-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -25,7 +25,21 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: os_map_ref
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: phonelib
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - ">="
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: validates_email_format_of
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: defra_ruby_style
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,20 +178,6 @@ dependencies:
|
|
150
178
|
- - "~>"
|
151
179
|
- !ruby/object:Gem::Version
|
152
180
|
version: '3.0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: rubocop
|
155
|
-
requirement: !ruby/object:Gem::Requirement
|
156
|
-
requirements:
|
157
|
-
- - ">="
|
158
|
-
- !ruby/object:Gem::Version
|
159
|
-
version: '0'
|
160
|
-
type: :development
|
161
|
-
prerelease: false
|
162
|
-
version_requirements: !ruby/object:Gem::Requirement
|
163
|
-
requirements:
|
164
|
-
- - ">="
|
165
|
-
- !ruby/object:Gem::Version
|
166
|
-
version: '0'
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: simplecov
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -218,34 +232,61 @@ files:
|
|
218
232
|
- Rakefile
|
219
233
|
- bin/console
|
220
234
|
- bin/setup
|
235
|
+
- config/locales/defra_ruby/validators/business_type_validator/en.yml
|
221
236
|
- config/locales/defra_ruby/validators/companies_house_number_validator/en.yml
|
237
|
+
- config/locales/defra_ruby/validators/email_validator/en.yml
|
238
|
+
- config/locales/defra_ruby/validators/grid_reference_validator/en.yml
|
239
|
+
- config/locales/defra_ruby/validators/location_validator/en.yml
|
240
|
+
- config/locales/defra_ruby/validators/phone_number_validator/en.yml
|
241
|
+
- config/locales/defra_ruby/validators/position_validator/en.yml
|
242
|
+
- config/locales/defra_ruby/validators/token_validator/en.yml
|
222
243
|
- config/locales/defra_ruby/validators/true_false_validator/en.yml
|
223
244
|
- lib/defra_ruby/validators.rb
|
224
245
|
- lib/defra_ruby/validators/base_validator.rb
|
246
|
+
- lib/defra_ruby/validators/business_type_validator.rb
|
225
247
|
- lib/defra_ruby/validators/companies_house_number_validator.rb
|
226
248
|
- lib/defra_ruby/validators/companies_house_service.rb
|
249
|
+
- lib/defra_ruby/validators/concerns/can_validate_characters.rb
|
250
|
+
- lib/defra_ruby/validators/concerns/can_validate_length.rb
|
251
|
+
- lib/defra_ruby/validators/concerns/can_validate_presence.rb
|
227
252
|
- lib/defra_ruby/validators/concerns/can_validate_selection.rb
|
228
253
|
- lib/defra_ruby/validators/configuration.rb
|
254
|
+
- lib/defra_ruby/validators/email_validator.rb
|
229
255
|
- lib/defra_ruby/validators/engine.rb
|
256
|
+
- lib/defra_ruby/validators/grid_reference_validator.rb
|
257
|
+
- lib/defra_ruby/validators/location_validator.rb
|
258
|
+
- lib/defra_ruby/validators/phone_number_validator.rb
|
259
|
+
- lib/defra_ruby/validators/position_validator.rb
|
260
|
+
- lib/defra_ruby/validators/token_validator.rb
|
230
261
|
- lib/defra_ruby/validators/true_false_validator.rb
|
231
262
|
- lib/defra_ruby/validators/version.rb
|
232
263
|
- lib/defra_ruby_validators.rb
|
233
264
|
- spec/cassettes/company_no_inactive.yml
|
234
265
|
- spec/cassettes/company_no_not_found.yml
|
235
266
|
- spec/cassettes/company_no_valid.yml
|
267
|
+
- spec/defra_ruby/validators/business_type_validator_spec.rb
|
236
268
|
- spec/defra_ruby/validators/companies_house_number_validator_spec.rb
|
237
269
|
- spec/defra_ruby/validators/companies_house_service_spec.rb
|
238
270
|
- spec/defra_ruby/validators/configuration_spec.rb
|
271
|
+
- spec/defra_ruby/validators/email_validator_spec.rb
|
272
|
+
- spec/defra_ruby/validators/grid_reference_validator_spec.rb
|
273
|
+
- spec/defra_ruby/validators/location_validator_spec.rb
|
274
|
+
- spec/defra_ruby/validators/phone_number_validator_spec.rb
|
275
|
+
- spec/defra_ruby/validators/position_validator_spec.rb
|
276
|
+
- spec/defra_ruby/validators/token_validator_spec.rb
|
239
277
|
- spec/defra_ruby/validators/true_false_validator_spec.rb
|
240
278
|
- spec/defra_ruby/validators_spec.rb
|
241
279
|
- spec/examples.txt
|
242
280
|
- spec/spec_helper.rb
|
243
281
|
- spec/support/defra_ruby_validators.rb
|
244
|
-
- spec/support/
|
282
|
+
- spec/support/helpers/text_generator.rb
|
245
283
|
- spec/support/helpers/translator.rb
|
246
284
|
- spec/support/i18n.rb
|
247
285
|
- spec/support/pry.rb
|
286
|
+
- spec/support/shared_examples/validators/characters_validator.rb
|
248
287
|
- spec/support/shared_examples/validators/invalid_record.rb
|
288
|
+
- spec/support/shared_examples/validators/length_validator.rb
|
289
|
+
- spec/support/shared_examples/validators/presence_validator.rb
|
249
290
|
- spec/support/shared_examples/validators/selection_validator.rb
|
250
291
|
- spec/support/shared_examples/validators/valid_record.rb
|
251
292
|
- spec/support/shared_examples/validators/validator.rb
|
@@ -281,8 +322,15 @@ test_files:
|
|
281
322
|
- spec/defra_ruby/validators_spec.rb
|
282
323
|
- spec/defra_ruby/validators/companies_house_service_spec.rb
|
283
324
|
- spec/defra_ruby/validators/configuration_spec.rb
|
325
|
+
- spec/defra_ruby/validators/phone_number_validator_spec.rb
|
326
|
+
- spec/defra_ruby/validators/position_validator_spec.rb
|
327
|
+
- spec/defra_ruby/validators/grid_reference_validator_spec.rb
|
328
|
+
- spec/defra_ruby/validators/business_type_validator_spec.rb
|
284
329
|
- spec/defra_ruby/validators/companies_house_number_validator_spec.rb
|
330
|
+
- spec/defra_ruby/validators/token_validator_spec.rb
|
285
331
|
- spec/defra_ruby/validators/true_false_validator_spec.rb
|
332
|
+
- spec/defra_ruby/validators/location_validator_spec.rb
|
333
|
+
- spec/defra_ruby/validators/email_validator_spec.rb
|
286
334
|
- spec/examples.txt
|
287
335
|
- spec/cassettes/company_no_not_found.yml
|
288
336
|
- spec/cassettes/company_no_valid.yml
|
@@ -291,10 +339,13 @@ test_files:
|
|
291
339
|
- spec/support/i18n.rb
|
292
340
|
- spec/support/vcr.rb
|
293
341
|
- spec/support/pry.rb
|
294
|
-
- spec/support/dotenv.rb
|
295
342
|
- spec/support/defra_ruby_validators.rb
|
296
343
|
- spec/support/helpers/translator.rb
|
344
|
+
- spec/support/helpers/text_generator.rb
|
297
345
|
- spec/support/shared_examples/validators/selection_validator.rb
|
298
346
|
- spec/support/shared_examples/validators/invalid_record.rb
|
347
|
+
- spec/support/shared_examples/validators/presence_validator.rb
|
348
|
+
- spec/support/shared_examples/validators/characters_validator.rb
|
349
|
+
- spec/support/shared_examples/validators/length_validator.rb
|
299
350
|
- spec/support/shared_examples/validators/valid_record.rb
|
300
351
|
- spec/support/shared_examples/validators/validator.rb
|
data/spec/support/dotenv.rb
DELETED