govuk_schemas 6.1.0 → 6.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5588184b2f2aac015bf79217e0311d165ab849fea5ef83ba4d0ce683b300ad46
4
- data.tar.gz: 16b97e02ee44db9130f44cc96ef7796a5e5eb087567a0f353cbbe3d33dad2938
3
+ metadata.gz: 232c587a32f3faa5b2a96754859d3ec61226f8e26c84035e1dd3e169292a9d18
4
+ data.tar.gz: 7d7debcd13ffaedc2170121769717c1a0b47e0e6eda8f2d3ac55f13b074f5219
5
5
  SHA512:
6
- metadata.gz: 18dd2ba2f2fcd59f0b45c6583aa7a78c8ea2599303bff5c4d787aef5a4d22f3631dafaab75830564068317e777e15b96c0ad9d3b8e5ac2b92bed9cfd1cd2746a
7
- data.tar.gz: 4d00b406e14eb8f044d13a27e8d1a120efca36d3e4e96df59869cf9666985cbd642a335239ab2a66ec7baba79077c19a425165f6476c547db1d4699155a8d560
6
+ metadata.gz: ca1478bb2431b30d4d37febb2010a9f22820b3118cf3ed40730afc48d2e28dcec85d7a18a75b18b08bdc45cb74bcb3204ddef22f21d2065ebb70fa039deae432
7
+ data.tar.gz: bf32b71b72196432e7a67caeeb8776435305fc2979b33f971edf176c7ca8c10d7143c6c344fd8c9e91100086735406494d17fe35a947b0842d69bdaf2452ba59
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.2.0
4
+
5
+ * Remove Faker dependency [PR](https://github.com/alphagov/govuk_schemas/pull/172)
6
+
7
+ ## 6.1.1
8
+
9
+ * Add a new regex generator for a content block order item [PR](https://github.com/alphagov/govuk_schemas/pull/170)
10
+
3
11
  ## 6.1.0
4
12
 
5
13
  * Introduce a "one of everything" strategy for RandomSchemaGenerator https://github.com/alphagov/govuk_schemas/pull/168
data/README.md CHANGED
@@ -22,6 +22,13 @@ Make sure you have `publishing-api` cloned in a sibling directory:
22
22
  bundle exec rake
23
23
  ```
24
24
 
25
+ ## Development
26
+
27
+ In order to run the tests successfully you also need [publishing-api](https://github.com/alphagov/publishing-api) checked
28
+ out into the same parent directory as govuk_schemas.
29
+
30
+ The tests can then be run with `bundle exec rspec`.
31
+
25
32
  ## License
26
33
 
27
34
  The gem is available as open source under the terms of the [MIT License](LICENCE).
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = %w[lib]
20
20
 
21
- spec.add_dependency "faker", ">= 3.4.1", "< 3.6.0"
22
21
  # This should be kept in sync with the json-schema version of publishing-api.
23
22
  spec.add_dependency "json-schema", ">= 2.8", "< 6.1"
24
23
 
@@ -1,13 +1,11 @@
1
- require "faker"
2
-
3
1
  module GovukSchemas
4
2
  # @private
5
3
  class RandomContentGenerator
6
- WORDS = %w[Lorem ipsum dolor sit amet consectetur adipiscing elit. Ut suscipit at mauris non bibendum. Ut ac massa est. Aenean tempor imperdiet leo vel interdum. Nam sagittis cursus sem ultricies scelerisque. Quisque porttitor risus vel risus finibus eu sollicitudin nisl aliquet. Sed sed lectus ac dolor molestie interdum. Nam molestie pellentesque purus ac vestibulum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Suspendisse non tempor eros. Mauris eu orci hendrerit volutpat lorem in tristique libero. Duis a nibh nibh.].freeze
4
+ WORDS = %w[Lorem ipsum dolor sit amet consectetur adipiscing elit Ut suscipit at mauris non bibendum Ut ac massa est Aenean tempor imperdiet leo vel interdum Nam sagittis cursus sem ultricies scelerisque Quisque porttitor risus vel risus finibus eu sollicitudin nisl aliquet Sed sed lectus ac dolor molestie interdum Nam molestie pellentesque purus ac vestibulum Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas Suspendisse non tempor eros Mauris eu orci hendrerit volutpat lorem in tristique libero Duis a nibh nibh].freeze
5
+ DOMAIN_SUFFIXES = %w[co.uk com].freeze
7
6
 
8
7
  def initialize(random: Random.new)
9
8
  @random = random
10
- Faker::Config.random = @random
11
9
  end
12
10
 
13
11
  def string_for_type(type)
@@ -17,7 +15,7 @@ module GovukSchemas
17
15
  when "uri"
18
16
  uri
19
17
  when "email"
20
- Faker::Internet.email
18
+ [username, domain_name].join("@")
21
19
  else
22
20
  raise <<~DOC
23
21
  Unsupported JSON schema type `#{type}`
@@ -38,9 +36,9 @@ module GovukSchemas
38
36
  (arbitrary_time + @random.rand(0..500_000_000)).iso8601
39
37
  end
40
38
 
41
- # TODO: make this more random with query string, optional anchor.
42
- def uri
43
- "#{Faker::Internet.url(path: base_path)}#{anchor}"
39
+ # TODO: make this more random with query string
40
+ def uri(domain_suffix: nil, include_anchor: true)
41
+ "https://#{domain_name(domain_suffix:)}#{base_path}#{include_anchor ? anchor : nil}"
44
42
  end
45
43
 
46
44
  def base_path
@@ -48,8 +46,7 @@ module GovukSchemas
48
46
  end
49
47
 
50
48
  def govuk_subdomain_url
51
- host = Faker::Internet.domain_name(subdomain: true, domain: "gov.uk")
52
- Faker::Internet.url(host:, path: base_path)
49
+ uri(domain_suffix: "gov.uk", include_anchor: false)
53
50
  end
54
51
 
55
52
  def string(minimum_chars = nil, maximum_chars = nil)
@@ -66,11 +63,11 @@ module GovukSchemas
66
63
  "##{hex}"
67
64
  end
68
65
 
69
- def random_identifier(separator:)
66
+ def random_identifier(separator: "-")
70
67
  WORDS.sample(@random.rand(1..10), random: @random)
71
- .join("-")
72
- .gsub(/[^a-z0-9\-_]+/i, "-")
73
- .gsub("-", separator)
68
+ .join(separator)
69
+ .gsub(/[^a-z0-9\-_]+/i, separator)
70
+ .downcase
74
71
  end
75
72
 
76
73
  def uuid
@@ -113,6 +110,8 @@ module GovukSchemas
113
110
  govuk_subdomain_url
114
111
  when '[a-z0-9\-_]'
115
112
  "#{hex}-#{hex}"
113
+ when "^addresses|contact_links|email_addresses|telephones.[a-z0-9]+(?:-[a-z0-9]+)*$"
114
+ content_block_order_item
116
115
  else
117
116
  raise <<~DOC
118
117
  Don't know how to generate random string for pattern #{pattern.inspect}
@@ -130,6 +129,25 @@ module GovukSchemas
130
129
 
131
130
  private
132
131
 
132
+ def username
133
+ WORDS.sample(random: @random).downcase
134
+ end
135
+
136
+ def domain_name(domain_suffix: nil)
137
+ [
138
+ WORDS.sample(random: @random).downcase,
139
+ domain_suffix || DOMAIN_SUFFIXES.sample(random: @random),
140
+ ].join(".")
141
+ end
142
+
143
+ def content_block_order_item
144
+ [
145
+ %w[addresses contact_links email_addresses telephones].sample,
146
+ ".",
147
+ random_identifier,
148
+ ].join
149
+ end
150
+
133
151
  def random_letter
134
152
  letters = ("a".."f").to_a
135
153
  letters[@random.rand(0..letters.count - 1)]
@@ -1,4 +1,4 @@
1
1
  module GovukSchemas
2
2
  # @private
3
- VERSION = "6.1.0".freeze
3
+ VERSION = "6.2.0".freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_schemas
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.1.0
4
+ version: 6.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
@@ -9,26 +9,6 @@ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: faker
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - ">="
17
- - !ruby/object:Gem::Version
18
- version: 3.4.1
19
- - - "<"
20
- - !ruby/object:Gem::Version
21
- version: 3.6.0
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- version: 3.4.1
29
- - - "<"
30
- - !ruby/object:Gem::Version
31
- version: 3.6.0
32
12
  - !ruby/object:Gem::Dependency
33
13
  name: json-schema
34
14
  requirement: !ruby/object:Gem::Requirement
@@ -126,7 +106,6 @@ executables: []
126
106
  extensions: []
127
107
  extra_rdoc_files: []
128
108
  files:
129
- - ".github/dependabot.yml"
130
109
  - ".github/workflows/actionlint.yml"
131
110
  - ".github/workflows/autorelease.yml"
132
111
  - ".github/workflows/ci.yml"
@@ -173,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
152
  - !ruby/object:Gem::Version
174
153
  version: '0'
175
154
  requirements: []
176
- rubygems_version: 3.7.1
155
+ rubygems_version: 3.7.2
177
156
  specification_version: 4
178
157
  summary: Gem to generate test data based on GOV.UK content schemas
179
158
  test_files: []
@@ -1,10 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: bundler
4
- directory: /
5
- schedule:
6
- interval: daily
7
- - package-ecosystem: "github-actions"
8
- directory: /
9
- schedule:
10
- interval: daily