govuk_schemas 5.0.2 → 5.0.3

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
  SHA256:
3
- metadata.gz: b4a46de8726a08e51bbe527cfb95d351a24998bf9bc9b2f3fd273529cf5c080a
4
- data.tar.gz: 615c093ccede2446126bef34dd2e64f9c325ba5f9ed212b160ec57e442054522
3
+ metadata.gz: cb7171db237b01bb19991d1675d3d150731997d20fa4fb2f28c7b0868e0f723f
4
+ data.tar.gz: 90872e26de2b1ccc70b1b4e3ade137eaeb6a3221bfa0cf65c69d6c81ae045c44
5
5
  SHA512:
6
- metadata.gz: bd2bba00a69249ae7b6e8dbc27ecbbb7a029d14dce3a9ce4c765ab3ca050dd68a1299a6263da238dc1759efcea6a74c83e95329fee9450655568ee9fbea98cc0
7
- data.tar.gz: 29a6b200fc9c41c35961bbb6398878f59e8bc948d565c813df2a73051e179a16e05343a5e0821bc4c5624c2185a4233aeb41822a6792a869690fb081d73eefac
6
+ metadata.gz: 8789569b6d515a80312e5aae98f33c68d7ec1972f487d8e7eb599d1b7a0cb4bd4b77d9cc9e952df9a149e2d5a32e5794a6de3f974411ec491ccc2a05d9527c37
7
+ data.tar.gz: ff677fa7341044673cca7573fd14e07bf2de126b163c09c2c3d576850a6b52c7ee4206c1d2d4439db7339e2c9e8ff2191c687c3338d21f967033c275d5092cd8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 5.0.3
2
+
3
+ * Add support for `email` string types
4
+ * Use `Faker` gem to generate emails and URLs
5
+ * Improve error messages when an unknown type is given in `GovukSchemas::RandomContentGenerator#string_for_type`
6
+
1
7
  # 5.0.2
2
8
 
3
9
  * Fix issue where customised schema validation message was incorrect for a modified payload
@@ -22,10 +22,11 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "json-schema", ">= 2.8", "< 4.4"
23
23
 
24
24
  spec.add_development_dependency "climate_control"
25
+ spec.add_development_dependency "faker", "~> 3.4.1"
25
26
  spec.add_development_dependency "pry-byebug"
26
27
  spec.add_development_dependency "rake", "~> 13.0"
27
28
  spec.add_development_dependency "rspec", "~> 3.4"
28
- spec.add_development_dependency "rubocop-govuk", "4.17.1"
29
+ spec.add_development_dependency "rubocop-govuk", "4.18.0"
29
30
 
30
31
  spec.required_ruby_version = ">= 3.1.4"
31
32
  end
@@ -1,3 +1,5 @@
1
+ require "faker"
2
+
1
3
  module GovukSchemas
2
4
  # @private
3
5
  class RandomContentGenerator
@@ -5,6 +7,7 @@ module GovukSchemas
5
7
 
6
8
  def initialize(random: Random.new)
7
9
  @random = random
10
+ Faker::Config.random = @random
8
11
  end
9
12
 
10
13
  def string_for_type(type)
@@ -13,8 +16,20 @@ module GovukSchemas
13
16
  time
14
17
  when "uri"
15
18
  uri
19
+ when "email"
20
+ Faker::Internet.email
16
21
  else
17
- raise "Unknown attribute type `#{type}`"
22
+ raise <<~DOC
23
+ Unsupported JSON schema type `#{type}`
24
+
25
+ Supported formats are:
26
+ - date-time
27
+ - uri
28
+ - email
29
+
30
+ This can be fixed by adding a type to the `string_for_type` method in
31
+ `lib/govuk_schemas/random_content_generator.rb` in https://github.com/alphagov/govuk_schemas
32
+ DOC
18
33
  end
19
34
  end
20
35
 
@@ -25,7 +40,7 @@ module GovukSchemas
25
40
 
26
41
  # TODO: make this more random with query string, optional anchor.
27
42
  def uri
28
- "http://example.com#{base_path}#{anchor}"
43
+ "#{Faker::Internet.url(path: base_path)}#{anchor}"
29
44
  end
30
45
 
31
46
  def base_path
@@ -33,10 +48,8 @@ module GovukSchemas
33
48
  end
34
49
 
35
50
  def govuk_subdomain_url
36
- subdomain = @random.rand(2..4).times.map {
37
- ("a".."z").to_a.sample(@random.rand(3..8), random: @random).join
38
- }.join(".")
39
- "https://#{subdomain}.gov.uk#{base_path}"
51
+ host = Faker::Internet.domain_name(subdomain: true, domain: "gov.uk")
52
+ Faker::Internet.url(host:, path: base_path)
40
53
  end
41
54
 
42
55
  def string(minimum_chars = nil, maximum_chars = nil)
@@ -1,4 +1,4 @@
1
1
  module GovukSchemas
2
2
  # @private
3
- VERSION = "5.0.2".freeze
3
+ VERSION = "5.0.3".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: 5.0.2
4
+ version: 5.0.3
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: 2024-05-23 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -44,6 +44,20 @@ dependencies:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: faker
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 3.4.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 3.4.1
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: pry-byebug
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +106,14 @@ dependencies:
92
106
  requirements:
93
107
  - - '='
94
108
  - !ruby/object:Gem::Version
95
- version: 4.17.1
109
+ version: 4.18.0
96
110
  type: :development
97
111
  prerelease: false
98
112
  version_requirements: !ruby/object:Gem::Requirement
99
113
  requirements:
100
114
  - - '='
101
115
  - !ruby/object:Gem::Version
102
- version: 4.17.1
116
+ version: 4.18.0
103
117
  description: Gem to generate test data based on GOV.UK content schemas
104
118
  email:
105
119
  - govuk-dev@digital.cabinet-office.gov.uk
@@ -152,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
166
  - !ruby/object:Gem::Version
153
167
  version: '0'
154
168
  requirements: []
155
- rubygems_version: 3.5.10
169
+ rubygems_version: 3.5.14
156
170
  signing_key:
157
171
  specification_version: 4
158
172
  summary: Gem to generate test data based on GOV.UK content schemas