govuk_schemas 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/govuk_schemas/random.rb +19 -1
- data/lib/govuk_schemas/random_example.rb +17 -21
- data/lib/govuk_schemas/random_item_generator.rb +1 -1
- data/lib/govuk_schemas/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f0717cb5ebb1dc03c12f035a91dcf2f45558e27
|
4
|
+
data.tar.gz: 6ed611cdea54b588141d7c031aaed8e568c46a2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0280cc2e9eaaa76c79442c1ad3fa8bf33cac8c13f4028c8cada49b53f4d2b81a12330be014c5720994e343a45c9658a646cf13e67884b1b0b1b1d6b6f8a12a15
|
7
|
+
data.tar.gz: feb12a918c28c94a0c1f7ac88a12371be71d8ce4784a0eabd382498cbecc7d1f5ba8709c721cd6280d788f177e83b96e440c88c1114429a1cd954d2166c6e246
|
data/CHANGELOG.md
CHANGED
data/lib/govuk_schemas/random.rb
CHANGED
@@ -28,6 +28,11 @@ module GovukSchemas
|
|
28
28
|
"/" + rand(1..5).times.map { SecureRandom.uuid }.join('/')
|
29
29
|
end
|
30
30
|
|
31
|
+
def govuk_campaign_url
|
32
|
+
subdomain = rand(1..5).times.map { ('a'..'z').to_a.sample(rand(1..5)).join }.join('.')
|
33
|
+
"https://#{subdomain}.campaign.gov.uk#{base_path}"
|
34
|
+
end
|
35
|
+
|
31
36
|
def string(minimum_chars = nil, maximum_chars = nil)
|
32
37
|
minimum_chars = minimum_chars || 0
|
33
38
|
maximum_chars = maximum_chars || 100
|
@@ -60,10 +65,23 @@ module GovukSchemas
|
|
60
65
|
Utils.parameterize(WORDS.sample(rand(1..10)).join('-'))
|
61
66
|
when "^/(([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})+(/([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)*)?(\\?([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)?(#([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)?$"
|
62
67
|
base_path
|
68
|
+
when "^https://([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[A-Za-z0-9])?\\.)+campaign\\.gov\\.uk(/(([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})+(/([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)*)?(\\?([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)?(#([a-zA-Z0-9._~!$&'()*+,;=:@-]|%[0-9a-fA-F]{2})*)?)?$"
|
69
|
+
govuk_campaign_url
|
63
70
|
when '[a-z0-9\-_]'
|
64
71
|
"#{SecureRandom.hex}-#{SecureRandom.hex}"
|
65
72
|
else
|
66
|
-
raise
|
73
|
+
raise <<-doc
|
74
|
+
Don't know how to generate random string for pattern #{pattern.inspect}
|
75
|
+
|
76
|
+
This propably means you've introduced a new regex in govuk-content-schemas.
|
77
|
+
Because it's very hard to generate a valid string from a regex alone,
|
78
|
+
we have to specify a method to generate random data for each regex in
|
79
|
+
the schemas.
|
80
|
+
|
81
|
+
To fix this:
|
82
|
+
|
83
|
+
- Add your regex to `lib/govuk_schemas/random.rb`
|
84
|
+
doc
|
67
85
|
end
|
68
86
|
end
|
69
87
|
end
|
@@ -69,7 +69,7 @@ module GovukSchemas
|
|
69
69
|
errors = validation_errors_for(item)
|
70
70
|
|
71
71
|
if errors.any?
|
72
|
-
raise InvalidContentGenerated, error_message_custom(item, errors)
|
72
|
+
raise InvalidContentGenerated, error_message_custom(item, hash, errors)
|
73
73
|
end
|
74
74
|
|
75
75
|
item
|
@@ -83,13 +83,13 @@ module GovukSchemas
|
|
83
83
|
|
84
84
|
def error_message(item, errors)
|
85
85
|
<<err
|
86
|
-
An invalid content item was generated
|
87
|
-
means that either you've merged the content item with invalid values, or there's
|
88
|
-
a bug in the generator that causes it to output invalid values. Below you'll find
|
89
|
-
the generated payload, the validation errors and the schema that was used.
|
90
|
-
Together these should be sufficient to debug the issue.
|
86
|
+
An invalid content item was generated.
|
91
87
|
|
92
|
-
|
88
|
+
This probably means there's a bug in the generator that causes it to output
|
89
|
+
invalid values. Below you'll find the generated payload, the validation errors
|
90
|
+
and the schema that was used.
|
91
|
+
|
92
|
+
Validation errors:
|
93
93
|
--------------------------
|
94
94
|
|
95
95
|
#{JSON.pretty_generate(errors)}
|
@@ -98,33 +98,29 @@ Generated payload:
|
|
98
98
|
--------------------------
|
99
99
|
|
100
100
|
#{JSON.pretty_generate([item])}
|
101
|
-
|
102
|
-
Schema:
|
103
|
-
--------------------------
|
104
|
-
|
105
|
-
#{JSON.pretty_generate(@schema)}
|
106
101
|
err
|
107
102
|
end
|
108
103
|
|
109
|
-
def error_message_custom(item, errors)
|
104
|
+
def error_message_custom(item, custom_values, errors)
|
105
|
+
error_messages = errors.map { |e| "- #{e[:message]}\n" }.join
|
106
|
+
|
110
107
|
<<err
|
111
|
-
|
112
|
-
means you've merged the content item with invalid values.
|
108
|
+
The content item you are trying to generate is invalid against the schema.
|
113
109
|
|
114
|
-
|
110
|
+
Validation errors:
|
115
111
|
--------------------------
|
116
112
|
|
117
|
-
#{
|
113
|
+
#{error_messages}
|
118
114
|
|
119
|
-
|
115
|
+
Custom values provided:
|
120
116
|
--------------------------
|
121
117
|
|
122
|
-
#{JSON.pretty_generate(
|
118
|
+
#{JSON.pretty_generate(custom_values)}
|
123
119
|
|
124
|
-
|
120
|
+
Generated payload:
|
125
121
|
--------------------------
|
126
122
|
|
127
|
-
#{JSON.pretty_generate(
|
123
|
+
#{JSON.pretty_generate([item])}
|
128
124
|
err
|
129
125
|
end
|
130
126
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_schemas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|