metadata_presenter 2.16.8 → 2.16.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/app/validators/metadata_presenter/base_validator.rb +10 -5
  3. data/app/validators/metadata_presenter/date_after_validator.rb +3 -1
  4. data/app/validators/metadata_presenter/date_before_validator.rb +3 -1
  5. data/app/validators/metadata_presenter/date_validator.rb +8 -0
  6. data/app/validators/metadata_presenter/max_length_validator.rb +1 -1
  7. data/app/validators/metadata_presenter/maximum_validator.rb +3 -1
  8. data/app/validators/metadata_presenter/min_length_validator.rb +1 -1
  9. data/app/validators/metadata_presenter/minimum_validator.rb +3 -1
  10. data/default_metadata/component/autocomplete.json +12 -0
  11. data/default_metadata/string/error.accept.json +1 -1
  12. data/default_metadata/string/error.date.json +1 -1
  13. data/default_metadata/string/error.date_after.json +1 -1
  14. data/default_metadata/string/error.date_before.json +1 -1
  15. data/default_metadata/string/error.max_length.json +1 -1
  16. data/default_metadata/string/error.max_word.json +1 -1
  17. data/default_metadata/string/error.maximum.json +1 -1
  18. data/default_metadata/string/error.min_length.json +1 -1
  19. data/default_metadata/string/error.min_word.json +1 -1
  20. data/default_metadata/string/error.minimum.json +1 -1
  21. data/default_metadata/string/error.number.json +1 -1
  22. data/default_metadata/string/error.required.json +2 -2
  23. data/default_metadata/string/error.virus_scan.json +1 -1
  24. data/lib/metadata_presenter/version.rb +1 -1
  25. data/schemas/component/autocomplete.json +17 -0
  26. data/schemas/definition/select.json +29 -0
  27. data/schemas/definition/select_option.json +34 -0
  28. metadata +6 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93038b7e9c9adb0d310d3968281af77181bcef76140f5b881180a25479cf4e9d
4
- data.tar.gz: '0279f5f31f6dc8069602bf81b790e7a8e66ca1f289892338c9041455d7a9706d'
3
+ metadata.gz: 8834b6fb7919c4e0ab3f01148847e46e20d1036638181a1dc63b727b2bab18b1
4
+ data.tar.gz: 621cd45d12d5a7833f5e058c94fe5add3bd4d0822d3eaa5c8bf17fc26f8c58a6
5
5
  SHA512:
6
- metadata.gz: 78517da984452d5a94c5840973a5273b20de9f75722021fff9cef12f76082a4e6d977e82cbe04349a94fee02e92deadb40f772b410af004eec65c61f51934367
7
- data.tar.gz: 61836c9156090c9abd84ad3feecf70c03573dcc78126672cf6ea98232a2aea8598e9bac3d8315bb8517cf9b1ba1af2c47c1b01ca3b037ca8e333f026cda3c717
6
+ metadata.gz: 0e78f3eaf0b94ce9a2e2272d74d56cc1492f141000b97cff1648ee4f92edcd8a42483b641900cd27e7ac8c6e15fd6c04a28974cf052910cc04501cb91748b44d
7
+ data.tar.gz: 6ae2ef27d6a74a7374e37f4d081b692063aa0c2989b45cbd6b7b779967f8cd025055cb451db09f81241e1edf60c433f147fcf13ba278d78f45cf9070a544bfcc
@@ -75,10 +75,9 @@ module MetadataPresenter
75
75
  # is not present
76
76
  def default_error_message
77
77
  default_error_message_key = "error.#{schema_key}"
78
- default_message = Rails
79
- .application
80
- .config
81
- .default_metadata[default_error_message_key]
78
+ default_message = Rails.application
79
+ .config
80
+ .default_metadata[default_error_message_key]
82
81
 
83
82
  if default_message.present?
84
83
  default_message['value'] % error_message_hash
@@ -116,10 +115,16 @@ module MetadataPresenter
116
115
  def error_message_hash
117
116
  {
118
117
  control: component.humanised_title,
119
- schema_key.to_sym => component.validation[schema_key]
118
+ schema_key.to_sym => validation_value
120
119
  }
121
120
  end
122
121
 
122
+ # The validation configuration value
123
+ # Override if additional formatting of the value is required
124
+ def validation_value
125
+ component.validation[schema_key]
126
+ end
127
+
123
128
  # Method signature to be overwrite in the subclass if you do not want to allow
124
129
  # blank values. We should not allow blank when performing the required
125
130
  # validation.
@@ -1,6 +1,8 @@
1
1
  module MetadataPresenter
2
- class DateAfterValidator < BaseValidator
2
+ class DateAfterValidator < DateValidator
3
3
  def invalid_answer?
4
+ return if super
5
+
4
6
  answer_date = "#{user_answer.year}-#{user_answer.month}-#{user_answer.day}"
5
7
  Date.parse(answer_date).iso8601 < Date.parse(component.validation[schema_key]).iso8601
6
8
  end
@@ -1,6 +1,8 @@
1
1
  module MetadataPresenter
2
- class DateBeforeValidator < BaseValidator
2
+ class DateBeforeValidator < DateValidator
3
3
  def invalid_answer?
4
+ return if super
5
+
4
6
  answer_date = "#{user_answer.year}-#{user_answer.month}-#{user_answer.day}"
5
7
  Date.parse(answer_date).iso8601 > Date.parse(component.validation[schema_key]).iso8601
6
8
  end
@@ -1,5 +1,7 @@
1
1
  module MetadataPresenter
2
2
  class DateValidator < BaseValidator
3
+ DATE_STRING_VALIDATIONS = %w[date_after date_before].freeze
4
+
3
5
  def invalid_answer?
4
6
  Date.strptime(
5
7
  "#{user_answer.year}-#{user_answer.month}-#{user_answer.day}",
@@ -10,5 +12,11 @@ module MetadataPresenter
10
12
  rescue Date::Error
11
13
  true
12
14
  end
15
+
16
+ def validation_value
17
+ return unless schema_key.in?(DATE_STRING_VALIDATIONS)
18
+
19
+ Date.parse(component.validation[schema_key]).strftime('%d %m %Y')
20
+ end
13
21
  end
14
22
  end
@@ -1,7 +1,7 @@
1
1
  module MetadataPresenter
2
2
  class MaxLengthValidator < BaseValidator
3
3
  def invalid_answer?
4
- user_answer.to_s.size > component.validation[schema_key]
4
+ user_answer.to_s.size > component.validation[schema_key].to_i
5
5
  end
6
6
  end
7
7
  end
@@ -1,6 +1,8 @@
1
1
  module MetadataPresenter
2
- class MaximumValidator < BaseValidator
2
+ class MaximumValidator < NumberValidator
3
3
  def invalid_answer?
4
+ return if super
5
+
4
6
  Float(user_answer, exception: false) > Float(component.validation[schema_key], exception: false)
5
7
  end
6
8
  end
@@ -1,7 +1,7 @@
1
1
  module MetadataPresenter
2
2
  class MinLengthValidator < BaseValidator
3
3
  def invalid_answer?
4
- user_answer.to_s.size < component.validation[schema_key]
4
+ user_answer.to_s.size < component.validation[schema_key].to_i
5
5
  end
6
6
  end
7
7
  end
@@ -1,6 +1,8 @@
1
1
  module MetadataPresenter
2
- class MinimumValidator < BaseValidator
2
+ class MinimumValidator < NumberValidator
3
3
  def invalid_answer?
4
+ return if super
5
+
4
6
  Float(user_answer, exception: false) < Float(component.validation[schema_key], exception: false)
5
7
  end
6
8
  end
@@ -0,0 +1,12 @@
1
+ {
2
+ "_id": "component.autocomplete",
3
+ "_type": "autocomplete",
4
+ "errors": {},
5
+ "hint": "",
6
+ "options": [],
7
+ "name": "component-name",
8
+ "legend": "Question",
9
+ "validation": {
10
+ "required": true
11
+ }
12
+ }
@@ -2,5 +2,5 @@
2
2
  "_id": "error.accept",
3
3
  "_type": "string.error",
4
4
  "description": "File uploaded is wrong type",
5
- "value": "%{control} was not uploaded successfully as it is the wrong type"
5
+ "value": "\"%{control}\" was not uploaded successfully as it is the wrong type"
6
6
  }
@@ -2,5 +2,5 @@
2
2
  "_id": "error.date",
3
3
  "_type": "string.error",
4
4
  "description": "Input (date) is not a valid date",
5
- "value": "Enter a valid date for %{control}"
5
+ "value": "Enter a valid date for \"%{control}\""
6
6
  }
@@ -2,5 +2,5 @@
2
2
  "_id": "error.date_after",
3
3
  "_type": "string.error",
4
4
  "description": "Input (date) is earlier than allowed",
5
- "value": "Enter a later date for %{control}"
5
+ "value": "Your answer for \"%{control}\" must be %{date_after} or later"
6
6
  }
@@ -2,5 +2,5 @@
2
2
  "_id": "error.date_before",
3
3
  "_type": "string.error",
4
4
  "description": "Input (date) is later than allowed",
5
- "value": "Enter an earlier date for %{control}"
5
+ "value": "Your answer for \"%{control}\" must be %{date_before} or earlier"
6
6
  }
@@ -2,5 +2,5 @@
2
2
  "_id": "error.max_length",
3
3
  "_type": "string.error",
4
4
  "description": "Input (string) is too long",
5
- "value": "Your answer for '%{control}' is too long (%{max_length} characters at most)"
5
+ "value": "Your answer for \"%{control}\" must be %{max_length} characters or fewer"
6
6
  }
@@ -2,5 +2,5 @@
2
2
  "_id": "error.max_word",
3
3
  "_type": "string.error",
4
4
  "description": "Input (number) is higher than the maximum number of words allowed",
5
- "value": "Enter a lower number of words for %{control}"
5
+ "value": "Your answer for \"%{control}\" must be %{max_word} words or fewer"
6
6
  }
@@ -2,5 +2,5 @@
2
2
  "_id": "error.maximum",
3
3
  "_type": "string.error",
4
4
  "description": "Input (number) is larger than the maximum allowed",
5
- "value": "Enter a lower number for %{control}"
5
+ "value": "Your answer for \"%{control}\" must be %{maximum} or lower"
6
6
  }
@@ -2,5 +2,5 @@
2
2
  "_id": "error.min_length",
3
3
  "_type": "string.error",
4
4
  "description": "Input (string) is too short",
5
- "value": "Your answer for '%{control}' is too short (%{min_length} characters at least)"
5
+ "value": "Your answer for \"%{control}\" must be %{min_length} characters or more"
6
6
  }
@@ -2,5 +2,5 @@
2
2
  "_id": "error.min_word",
3
3
  "_type": "string.error",
4
4
  "description": "Input (number) is lower than the minimum number of words allowed",
5
- "value": "Enter a higher number of words for %{control}"
5
+ "value": "Your answer for \"%{control}\" must be %{min_word} words or more"
6
6
  }
@@ -2,5 +2,5 @@
2
2
  "_id": "error.minimum",
3
3
  "_type": "string.error",
4
4
  "description": "Input (number) is lower than the minimum allowed",
5
- "value": "Enter a higher number for %{control}"
5
+ "value": "Your answer for \"%{control}\" must be %{minimum} or higher"
6
6
  }
@@ -2,5 +2,5 @@
2
2
  "_id": "error.number",
3
3
  "_type": "string.error",
4
4
  "description": "Input (number) is not a number",
5
- "value": "Enter a number for %{control}"
5
+ "value": "Enter a number for \"%{control}\""
6
6
  }
@@ -2,6 +2,6 @@
2
2
  "_id": "error.required",
3
3
  "_type": "string.error",
4
4
  "description": "Input is required",
5
- "value": "Enter an answer for %{control}",
6
- "value:cy": "Rhowch ateb i {control}"
5
+ "value": "Enter an answer for \"%{control}\"",
6
+ "value:cy": "Rhowch ateb i \"{control}\""
7
7
  }
@@ -2,6 +2,6 @@
2
2
  "_id": "error.virus_scan",
3
3
  "_type": "string.error",
4
4
  "description": "File uploaded contains virus",
5
- "value": "%{control} was not uploaded successfully because it contains a virus"
5
+ "value": "\"%{control}\" was not uploaded successfully because it contains a virus"
6
6
  }
7
7
 
@@ -1,3 +1,3 @@
1
1
  module MetadataPresenter
2
- VERSION = '2.16.8'.freeze
2
+ VERSION = '2.16.11'.freeze
3
3
  end
@@ -0,0 +1,17 @@
1
+ {
2
+ "$id": "http://gov.uk/schema/v1.0.0/autocomplete",
3
+ "_name": "autocomplete",
4
+ "title": "Autocomplete",
5
+ "description": "Let users select one option from an auto-completing list",
6
+ "type": "object",
7
+ "allOf": [
8
+ {
9
+ "$ref": "definition.select"
10
+ }
11
+ ],
12
+ "properties": {
13
+ "_type": {
14
+ "const": "autocomplete"
15
+ }
16
+ }
17
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "$id": "http://gov.uk/schema/v1.0.0/definition/select",
3
+ "_name": "definition.select",
4
+ "title": "Select component definition",
5
+ "allOf": [
6
+ {
7
+ "$ref": "definition.field"
8
+ },
9
+ {
10
+ "$ref": "definition.width_class.input"
11
+ }
12
+ ],
13
+ "properties": {
14
+ "items": {
15
+ "title": "Options",
16
+ "description": "Items that users can select",
17
+ "type": "array",
18
+ "items": {
19
+ "$ref": "definition.select_option"
20
+ }
21
+ }
22
+ },
23
+ "required": [
24
+ "items"
25
+ ],
26
+ "category": [
27
+ "select"
28
+ ]
29
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "$id": "http://gov.uk/schema/v1.0.0/definition/select_option",
3
+ "_name": "definition.select_option",
4
+ "title": "Select option",
5
+ "description": "Component that provides a select option",
6
+ "type": "object",
7
+ "properties": {
8
+ "_type": {
9
+ "const": "select_option"
10
+ },
11
+ "text": {
12
+ "title": "Option text",
13
+ "description": "Text displayed to users for that option",
14
+ "type": "string",
15
+ "content": true
16
+ },
17
+ "value": {
18
+ "title": "Option value",
19
+ "description": "Value assigned when users select option",
20
+ "type": "string"
21
+ }
22
+ },
23
+ "allOf": [
24
+ {
25
+ "$ref": "definition.component"
26
+ }
27
+ ],
28
+ "required": [
29
+ "value"
30
+ ],
31
+ "category": [
32
+ "select_option"
33
+ ]
34
+ }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metadata_presenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.16.8
4
+ version: 2.16.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - MoJ Forms
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-20 00:00:00.000000000 Z
11
+ date: 2022-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: govuk_design_system_formbuilder
@@ -365,6 +365,7 @@ files:
365
365
  - config/initializers/schemas.rb
366
366
  - config/initializers/supported_components.rb
367
367
  - config/routes.rb
368
+ - default_metadata/component/autocomplete.json
368
369
  - default_metadata/component/checkboxes.json
369
370
  - default_metadata/component/content.json
370
371
  - default_metadata/component/date.json
@@ -448,6 +449,7 @@ files:
448
449
  - lib/metadata_presenter/test_helpers.rb
449
450
  - lib/metadata_presenter/version.rb
450
451
  - lib/tasks/metadata_presenter_tasks.rake
452
+ - schemas/component/autocomplete.json
451
453
  - schemas/component/checkboxes.json
452
454
  - schemas/component/content.json
453
455
  - schemas/component/date.json
@@ -493,6 +495,8 @@ files:
493
495
  - schemas/definition/page.json
494
496
  - schemas/definition/radio.json
495
497
  - schemas/definition/repeatable.json
498
+ - schemas/definition/select.json
499
+ - schemas/definition/select_option.json
496
500
  - schemas/definition/width_class.input.json
497
501
  - schemas/definition/width_class.json
498
502
  - schemas/errors/errors.json