govuk_content_models 11.1.0 → 11.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.
- data/CHANGELOG.md +9 -1
- data/app/models/artefact.rb +3 -1
- data/app/validators/slug_validator.rb +32 -0
- data/lib/govuk_content_models/version.rb +1 -1
- data/test/validators/slug_validator_test.rb +18 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
## 11.2.0
|
|
2
|
+
|
|
3
|
+
* Added manual and manual-section formats with custom slug validation.
|
|
4
|
+
|
|
5
|
+
## 11.1.0
|
|
6
|
+
|
|
7
|
+
* Add area field to business support editions.
|
|
8
|
+
|
|
1
9
|
## 11.0.1
|
|
2
10
|
|
|
3
|
-
*
|
|
11
|
+
* Destroying an edition lets siblings know.
|
|
4
12
|
|
|
5
13
|
## 11.0.0
|
|
6
14
|
|
data/app/models/artefact.rb
CHANGED
|
@@ -82,7 +82,9 @@ class Artefact
|
|
|
82
82
|
"smartanswers" => ["smart-answer"],
|
|
83
83
|
"custom-application" => ["custom-application"], # In this case the owning_app is overriden. eg calendars, licencefinder
|
|
84
84
|
"travel-advice-publisher" => ["travel-advice"],
|
|
85
|
-
"specialist-publisher" => ["
|
|
85
|
+
"specialist-publisher" => ["manual",
|
|
86
|
+
"manual-section",
|
|
87
|
+
"specialist-document"],
|
|
86
88
|
"finder-api" => ["finder"],
|
|
87
89
|
"whitehall" => ["announcement",
|
|
88
90
|
"authored_article",
|
|
@@ -6,6 +6,7 @@ class SlugValidator < ActiveModel::EachValidator
|
|
|
6
6
|
ForeignTravelAdvicePageValidator,
|
|
7
7
|
HelpPageValidator,
|
|
8
8
|
GovernmentPageValidator,
|
|
9
|
+
ManualPageValidator,
|
|
9
10
|
SpecialistDocumentPageValidator,
|
|
10
11
|
BrowsePageValidator,
|
|
11
12
|
DefaultValidator
|
|
@@ -100,6 +101,37 @@ protected
|
|
|
100
101
|
end
|
|
101
102
|
end
|
|
102
103
|
|
|
104
|
+
class ManualPageValidator < InstanceValidator
|
|
105
|
+
def applicable?
|
|
106
|
+
of_kind?('manual') || of_kind?('manual-section')
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def validate!
|
|
110
|
+
validate_number_of_parts!
|
|
111
|
+
validate_guidance_prefix!
|
|
112
|
+
validate_parts_as_slugs!
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
private
|
|
116
|
+
def validate_number_of_parts!
|
|
117
|
+
unless [2, 3].include?(url_parts.size)
|
|
118
|
+
record.errors[attribute] << 'must contains two or three path parts'
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def validate_guidance_prefix!
|
|
123
|
+
unless starts_with?('guidance/')
|
|
124
|
+
record.errors[attribute] << 'Manual slugs must have a guidance/ prefix'
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def validate_parts_as_slugs!
|
|
129
|
+
unless url_parts.all? { |url_part| valid_slug?(url_part) }
|
|
130
|
+
record.errors[attribute] << 'must be usable in a URL'
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
103
135
|
class SpecialistDocumentPageValidator < InstanceValidator
|
|
104
136
|
def applicable?
|
|
105
137
|
of_kind?('specialist-document')
|
|
@@ -103,4 +103,22 @@ class SlugTest < ActiveSupport::TestCase
|
|
|
103
103
|
refute document_with_slug("oil-and-gas/not.a.valid.slug", kind: "specialist_sector").valid?
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
|
+
|
|
107
|
+
context "Manual pages" do
|
|
108
|
+
should "allow slugs starting guidance/" do
|
|
109
|
+
refute document_with_slug("manuals/a-manual", kind: "manual").valid?
|
|
110
|
+
assert document_with_slug("guidance/a-manual", kind: "manual").valid?
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
should "allow two or three path parts" do
|
|
114
|
+
refute document_with_slug("guidance", kind: "manual").valid?
|
|
115
|
+
assert document_with_slug("guidance/a-manual", kind: "manual").valid?
|
|
116
|
+
assert document_with_slug("guidance/a-manual/a-section", kind: "manual-section").valid?
|
|
117
|
+
refute document_with_slug("guidance/a-manual/a-section/a-subsection", kind: "manual-section").valid?
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
should "not allow invalid path segments" do
|
|
121
|
+
refute document_with_slug("guidance/bad.manual.slug", kind: "manual").valid?
|
|
122
|
+
end
|
|
123
|
+
end
|
|
106
124
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: govuk_content_models
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 11.
|
|
4
|
+
version: 11.2.0
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2014-
|
|
12
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bson_ext
|
|
@@ -463,7 +463,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
463
463
|
version: '0'
|
|
464
464
|
segments:
|
|
465
465
|
- 0
|
|
466
|
-
hash:
|
|
466
|
+
hash: 1863412532211958025
|
|
467
467
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
468
468
|
none: false
|
|
469
469
|
requirements:
|
|
@@ -472,7 +472,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
472
472
|
version: '0'
|
|
473
473
|
segments:
|
|
474
474
|
- 0
|
|
475
|
-
hash:
|
|
475
|
+
hash: 1863412532211958025
|
|
476
476
|
requirements: []
|
|
477
477
|
rubyforge_project:
|
|
478
478
|
rubygems_version: 1.8.23
|