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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0284fbbf0aea21ee8b9dd454dc8934f9c9da9b0b
4
- data.tar.gz: e0555905e01eeb2dada139cb1f43f4030d5bc6ae
3
+ metadata.gz: 6f0717cb5ebb1dc03c12f035a91dcf2f45558e27
4
+ data.tar.gz: 6ed611cdea54b588141d7c031aaed8e568c46a2a
5
5
  SHA512:
6
- metadata.gz: 9c4f413d705359a75802147e74a7cd2c58d122f8ae16d8dc464259ac63394f7260709f7c3fec1a8eff490f4552d31d8c63abfdb5b778522c38a1d21e6f8ed05a
7
- data.tar.gz: d949094bfa6c8a7ac8894daa1a58a6fffee3520b193099c8742ccc3c20a5cb70f133919e1bed5f4cab692c49f4c307c7a3bd85c9a452733d4f09f7032bb4c71d
6
+ metadata.gz: 0280cc2e9eaaa76c79442c1ad3fa8bf33cac8c13f4028c8cada49b53f4d2b81a12330be014c5720994e343a45c9658a646cf13e67884b1b0b1b1d6b6f8a12a15
7
+ data.tar.gz: feb12a918c28c94a0c1f7ac88a12371be71d8ce4784a0eabd382498cbecc7d1f5ba8709c721cd6280d788f177e83b96e440c88c1114429a1cd954d2166c6e246
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.0.0
2
+
3
+ * Add regex for GOV.UK campaign URLs
4
+ * Improve error messages
5
+
1
6
  # 0.2.0
2
7
 
3
8
  * Add a new regex for the new application validation in the schema
@@ -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 "Regex pattern not found: #{pattern.inspect}"
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 by `RandomExample`. This probably
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
- Errors:
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
- An invalid content item was generated by `RandomExample`. This probably
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
- Errors:
110
+ Validation errors:
115
111
  --------------------------
116
112
 
117
- #{JSON.pretty_generate(errors)}
113
+ #{error_messages}
118
114
 
119
- Generated payload:
115
+ Custom values provided:
120
116
  --------------------------
121
117
 
122
- #{JSON.pretty_generate([item])}
118
+ #{JSON.pretty_generate(custom_values)}
123
119
 
124
- Schema:
120
+ Generated payload:
125
121
  --------------------------
126
122
 
127
- #{JSON.pretty_generate(@schema)}
123
+ #{JSON.pretty_generate([item])}
128
124
  err
129
125
  end
130
126
  end
@@ -123,7 +123,7 @@ module GovukSchemas
123
123
  def lookup_json_pointer(ref)
124
124
  elements = ref.split('/')
125
125
  elements.shift
126
- @schema.dig(*elements)
126
+ @schema.dig(*elements) || raise("Definition `#{ref}` not found in the schema")
127
127
  end
128
128
  end
129
129
  end
@@ -1,4 +1,4 @@
1
1
  module GovukSchemas
2
2
  # @private
3
- VERSION = "0.2.0".freeze
3
+ VERSION = "1.0.0".freeze
4
4
  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.2.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-09-26 00:00:00.000000000 Z
11
+ date: 2016-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema