govuk_content_models 10.2.2 → 10.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -1
- data/app/models/artefact.rb +2 -1
- data/app/validators/slug_validator.rb +16 -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
data/app/models/artefact.rb
CHANGED
@@ -122,7 +122,8 @@ class Artefact
|
|
122
122
|
"transparency",
|
123
123
|
"world_location_news_article",
|
124
124
|
"worldwide_priority",
|
125
|
-
"written_statement"]
|
125
|
+
"written_statement"],
|
126
|
+
"panopticon" => ["specialist_sector"],
|
126
127
|
}.freeze
|
127
128
|
|
128
129
|
FORMATS = FORMATS_BY_DEFAULT_OWNING_APP.values.flatten
|
@@ -7,6 +7,7 @@ class SlugValidator < ActiveModel::EachValidator
|
|
7
7
|
HelpPageValidator,
|
8
8
|
GovernmentPageValidator,
|
9
9
|
SpecialistDocumentPageValidator,
|
10
|
+
BrowsePageValidator,
|
10
11
|
DefaultValidator
|
11
12
|
].map { |klass| klass.new(record, attribute, value) }
|
12
13
|
|
@@ -114,6 +115,21 @@ protected
|
|
114
115
|
end
|
115
116
|
end
|
116
117
|
|
118
|
+
class BrowsePageValidator < InstanceValidator
|
119
|
+
def applicable?
|
120
|
+
of_kind?('specialist_sector')
|
121
|
+
end
|
122
|
+
|
123
|
+
def validate!
|
124
|
+
unless [1, 2].include?(url_parts.size)
|
125
|
+
record.errors[attribute] << "must contains one or two path parts"
|
126
|
+
end
|
127
|
+
unless url_parts.all? { |url_part| valid_slug?(url_part) }
|
128
|
+
record.errors[attribute] << "must be usable in a URL"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
117
133
|
class DefaultValidator < InstanceValidator
|
118
134
|
def applicable?
|
119
135
|
true
|
@@ -85,4 +85,22 @@ class SlugTest < ActiveSupport::TestCase
|
|
85
85
|
refute document_with_slug("some-finder/my-specialist-document/not-allowed", kind: "specialist-document").valid?
|
86
86
|
end
|
87
87
|
end
|
88
|
+
|
89
|
+
context "Specialist sector browse pages" do
|
90
|
+
should "allow a single path part" do
|
91
|
+
assert document_with_slug("oil-and-gas", kind: "specialist_sector").valid?
|
92
|
+
end
|
93
|
+
|
94
|
+
should "allow two path parts" do
|
95
|
+
assert document_with_slug("oil-and-gas/fields-and-wells", kind: "specialist_sector").valid?
|
96
|
+
end
|
97
|
+
|
98
|
+
should "not allow three path parts" do
|
99
|
+
refute document_with_slug("oil-and-gas/fields-and-wells/development", kind: "specialist_sector").valid?
|
100
|
+
end
|
101
|
+
|
102
|
+
should "not allow invalid path segments" do
|
103
|
+
refute document_with_slug("oil-and-gas/not.a.valid.slug", kind: "specialist_sector").valid?
|
104
|
+
end
|
105
|
+
end
|
88
106
|
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: 10.
|
4
|
+
version: 10.3.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-04-
|
12
|
+
date: 2014-04-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bson_ext
|
@@ -465,7 +465,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
465
465
|
version: '0'
|
466
466
|
segments:
|
467
467
|
- 0
|
468
|
-
hash: -
|
468
|
+
hash: -1098545351621195273
|
469
469
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
470
470
|
none: false
|
471
471
|
requirements:
|
@@ -474,7 +474,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
474
474
|
version: '0'
|
475
475
|
segments:
|
476
476
|
- 0
|
477
|
-
hash: -
|
477
|
+
hash: -1098545351621195273
|
478
478
|
requirements: []
|
479
479
|
rubyforge_project:
|
480
480
|
rubygems_version: 1.8.23
|