govuk_content_models 12.1.0 → 12.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 12.2.0
2
+
3
+ * Add ManualChangeHistory model and artefact kind.
4
+
1
5
  ## 12.1.0
2
6
 
3
7
  * Add LinkValidator, which checks that links in Govspeak fields are properly
@@ -83,6 +83,7 @@ class Artefact
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
85
  "specialist-publisher" => ["manual",
86
+ "manual-change-history",
86
87
  "manual-section",
87
88
  "specialist-document"],
88
89
  "finder-api" => ["finder"],
@@ -0,0 +1,18 @@
1
+ require "prerendered_entity"
2
+
3
+ class ManualChangeHistory
4
+ include Mongoid::Document
5
+ include Mongoid::Timestamps
6
+ extend PrerenderedEntity
7
+
8
+ field :updates, type: Array
9
+ field :slug, type: String
10
+ field :manual_slug, type: String
11
+
12
+ index "slug", unique: true
13
+
14
+ validates :slug, uniqueness: true
15
+ validates_with SafeHtml
16
+
17
+ GOVSPEAK_FIELDS = []
18
+ end
@@ -7,6 +7,7 @@ class SlugValidator < ActiveModel::EachValidator
7
7
  HelpPageValidator,
8
8
  GovernmentPageValidator,
9
9
  ManualPageValidator,
10
+ ManualChangeHistoryValidator,
10
11
  SpecialistDocumentPageValidator,
11
12
  BrowsePageValidator,
12
13
  DefaultValidator
@@ -18,7 +19,11 @@ class SlugValidator < ActiveModel::EachValidator
18
19
  protected
19
20
  class InstanceValidator < Struct.new(:record, :attribute, :value)
20
21
  def starts_with?(expected_prefix)
21
- value.to_s[0...expected_prefix.size] == expected_prefix
22
+ value.to_s.start_with?(expected_prefix)
23
+ end
24
+
25
+ def ends_with?(expected_suffix)
26
+ value.to_s.end_with?(expected_suffix)
22
27
  end
23
28
 
24
29
  def of_kind?(expected_kind)
@@ -121,7 +126,45 @@ protected
121
126
 
122
127
  def validate_guidance_prefix!
123
128
  unless starts_with?('guidance/')
124
- record.errors[attribute] << 'Manual slugs must have a guidance/ prefix'
129
+ record.errors[attribute] << 'must have a guidance/ prefix'
130
+ end
131
+ end
132
+
133
+ def validate_parts_as_slugs!
134
+ unless url_parts.all? { |url_part| valid_slug?(url_part) }
135
+ record.errors[attribute] << 'must be usable in a URL'
136
+ end
137
+ end
138
+ end
139
+
140
+ class ManualChangeHistoryValidator < InstanceValidator
141
+ def applicable?
142
+ of_kind?('manual-change-history')
143
+ end
144
+
145
+ def validate!
146
+ validate_number_of_parts!
147
+ validate_guidance_prefix!
148
+ validate_updates_suffix!
149
+ validate_parts_as_slugs!
150
+ end
151
+
152
+ private
153
+ def validate_number_of_parts!
154
+ unless url_parts.size == 3
155
+ record.errors[attribute] << 'must contain three path parts'
156
+ end
157
+ end
158
+
159
+ def validate_guidance_prefix!
160
+ unless starts_with?('guidance/')
161
+ record.errors[attribute] << 'must have a guidance/ prefix'
162
+ end
163
+ end
164
+
165
+ def validate_updates_suffix!
166
+ unless ends_with?('/updates')
167
+ record.errors[attribute] << 'must have a /updates suffix'
125
168
  end
126
169
  end
127
170
 
@@ -1,4 +1,4 @@
1
1
  module GovukContentModels
2
2
  # Changing this causes Jenkins to tag and release the gem into the wild
3
- VERSION = "12.1.0"
3
+ VERSION = "12.2.0"
4
4
  end
@@ -0,0 +1,10 @@
1
+ require "test_helper"
2
+ require "models/prerendered_entity_tests"
3
+
4
+ class ManualChangeHistoryTest < ActiveSupport::TestCase
5
+ include PrerenderedEntityTests
6
+
7
+ def model_class
8
+ ManualChangeHistory
9
+ end
10
+ end
@@ -104,6 +104,38 @@ class SlugTest < ActiveSupport::TestCase
104
104
  end
105
105
  end
106
106
 
107
+ context "Manual change history" do
108
+ should "allow slugs of the form guidance/manual-slug/updates" do
109
+ assert document_with_slug("guidance/a-manual/updates",
110
+ kind: "manual-change-history").valid?
111
+ end
112
+
113
+ should "refuse slugs that don't start with guidance/" do
114
+ refute document_with_slug("manuals/a-manual/updates",
115
+ kind: "manual-change-history").valid?
116
+ end
117
+
118
+ should "refuse slugs that don't end with /updates" do
119
+ refute document_with_slug("guidance/a-manual/change-history",
120
+ kind: "manual-change-history").valid?
121
+ end
122
+
123
+ should "refuse slugs that don't have a manual-slug" do
124
+ refute document_with_slug("guidance/change-history",
125
+ kind: "manual-change-history").valid?
126
+ end
127
+
128
+ should "refuse slugs that have extra sections" do
129
+ refute document_with_slug("guidance/a-manual/a-section/updates",
130
+ kind: "manual-change-history").valid?
131
+ end
132
+
133
+ should "not allow invalid path segments" do
134
+ refute document_with_slug("guidance/bad.manual.slug/updates",
135
+ kind: "manual-change-history").valid?
136
+ end
137
+ end
138
+
107
139
  context "Manual pages" do
108
140
  should "allow slugs starting guidance/" do
109
141
  refute document_with_slug("manuals/a-manual", kind: "manual").valid?
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: 12.1.0
4
+ version: 12.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-06-12 00:00:00.000000000 Z
12
+ date: 2014-06-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
@@ -370,6 +370,7 @@ files:
370
370
  - app/models/local_interaction.rb
371
371
  - app/models/local_service.rb
372
372
  - app/models/local_transaction_edition.rb
373
+ - app/models/manual_change_history.rb
373
374
  - app/models/overview_dashboard.rb
374
375
  - app/models/part.rb
375
376
  - app/models/parted.rb
@@ -429,6 +430,7 @@ files:
429
430
  - test/models/local_authority_test.rb
430
431
  - test/models/local_service_test.rb
431
432
  - test/models/local_transaction_edition_test.rb
433
+ - test/models/manual_change_history_test.rb
432
434
  - test/models/overview_dashboard_test.rb
433
435
  - test/models/prerendered_entity_tests.rb
434
436
  - test/models/rendered_manual_test.rb
@@ -466,7 +468,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
466
468
  version: '0'
467
469
  segments:
468
470
  - 0
469
- hash: 4316099945977506650
471
+ hash: -3252707521846681022
470
472
  required_rubygems_version: !ruby/object:Gem::Requirement
471
473
  none: false
472
474
  requirements:
@@ -475,7 +477,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
475
477
  version: '0'
476
478
  segments:
477
479
  - 0
478
- hash: 4316099945977506650
480
+ hash: -3252707521846681022
479
481
  requirements: []
480
482
  rubyforge_project:
481
483
  rubygems_version: 1.8.23
@@ -508,6 +510,7 @@ test_files:
508
510
  - test/models/local_authority_test.rb
509
511
  - test/models/local_service_test.rb
510
512
  - test/models/local_transaction_edition_test.rb
513
+ - test/models/manual_change_history_test.rb
511
514
  - test/models/overview_dashboard_test.rb
512
515
  - test/models/prerendered_entity_tests.rb
513
516
  - test/models/rendered_manual_test.rb