govuk_content_models 29.0.1 → 29.1.0

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
  SHA1:
3
- metadata.gz: 75e08e3144ef51eba2493c273fc127e383d80364
4
- data.tar.gz: cc5c02fd3d0aef0b5219a6b4d0e38a911326f29a
3
+ metadata.gz: a121fff0d81773c3acfd3666904c3b81770213fa
4
+ data.tar.gz: 10b3f0778399eb518163df1cffd4b70e84572b61
5
5
  SHA512:
6
- metadata.gz: ee74ac88cfbaa85dc1d9bf879998b7ee3f8a9320f9617427e2f0a119346d3ea257fddbd04c575b154e6a827bbc50eda7b3c51bf2d149ec7cec0580c83e33b51f
7
- data.tar.gz: 5305758f70dfce47c17a97e04b2b58cdf2d13382eab4e4b090ebabebadff6d073994b7c77cf44c4ae70d8f3dce1239b1e75f4e2e643f2d77295ef6003bf7aed7
6
+ metadata.gz: c54a371b42da309fce13c72b3be6085b5e90005aa93d92b8c7d33d3d176cbc1fae047d4556a0b06bad938efe4fb6dfca5ce5b090e8489350b9a538de00efedb8
7
+ data.tar.gz: ac2f04839f067d3801fb17691df3293d9c1a2ddf6a3c0296571e2c30fe97b23b7a678bd9183eeb69c317549edda3f0355d1e82f2097d1a66fbd5b2beabf7d7f1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 29.1.0
4
+ - Allow detailed guide slugs to start with /guidance
5
+
3
6
  ## 29.0.1
4
7
 
5
8
  - Bugfix: updated_at field on non-archive editions was being updated whenever an Artefact was saved. Now only do so when the slug has changed.
@@ -37,7 +37,6 @@ class Artefact
37
37
  field "publication_id", type: String
38
38
  field "description", type: String
39
39
  field "state", type: String, default: "draft"
40
- field "specialist_body", type: String
41
40
  field "language", type: String, default: "en"
42
41
  field "need_extended_font", type: Boolean, default: false
43
42
  field "latest_change_note", type: String
@@ -75,17 +74,6 @@ class Artefact
75
74
  "smartanswers" => ["smart-answer"],
76
75
  "custom-application" => ["custom-application"], # In this case the owning_app is overriden. eg calendars, licencefinder
77
76
  "travel-advice-publisher" => ["travel-advice"],
78
- "specialist-publisher" => ["aaib_report",
79
- "cma_case",
80
- "countryside_stewardship_grant",
81
- "drug_safety_update",
82
- "european_structural_investment_fund",
83
- "international_development_fund",
84
- "maib_report",
85
- "manual",
86
- "medical_safety_alert",
87
- "raib_report",
88
- "vehicle_recalls_and_faults_alert"],
89
77
  "finder-api" => ["finder",
90
78
  "finder_email_signup"],
91
79
  "whitehall" => ["announcement",
@@ -7,9 +7,8 @@ class SlugValidator < ActiveModel::EachValidator
7
7
  HelpPageValidator,
8
8
  FinderEmailSignupValidator,
9
9
  GovernmentPageValidator,
10
- ManualPageValidator,
11
- SpecialistDocumentPageValidator,
12
10
  BrowsePageValidator,
11
+ DetailedGuideValidator,
13
12
  DefaultValidator
14
13
  ].map { |klass| klass.new(record, attribute, value) }
15
14
 
@@ -116,75 +115,28 @@ protected
116
115
  end
117
116
  end
118
117
 
119
- class ManualPageValidator < InstanceValidator
120
- def applicable?
121
- of_kind?('manual')
122
- end
123
-
124
- def validate!
125
- validate_number_of_parts!
126
- validate_guidance_prefix!
127
- validate_parts_as_slugs!
128
- end
129
-
130
- private
131
- def validate_number_of_parts!
132
- unless [2, 3].include?(url_parts.size)
133
- record.errors[attribute] << 'must contains two or three path parts'
134
- end
135
- end
136
-
137
- def validate_guidance_prefix!
138
- unless starts_with?('guidance/')
139
- record.errors[attribute] << 'must have a guidance/ prefix'
140
- end
141
- end
142
-
143
- def validate_parts_as_slugs!
144
- unless url_parts.all? { |url_part| valid_slug?(url_part) }
145
- record.errors[attribute] << 'must be usable in a URL'
146
- end
147
- end
148
- end
149
-
150
- class SpecialistDocumentPageValidator < InstanceValidator
118
+ class BrowsePageValidator < InstanceValidator
151
119
  def applicable?
152
- of_kind?(acceptable_formats)
120
+ of_kind?('specialist_sector')
153
121
  end
154
122
 
155
123
  def validate!
156
- unless url_parts.size == 2
157
- record.errors[attribute] << "must be of form <finder-slug>/<specialist-document-slug>"
124
+ unless [1, 2].include?(url_parts.size)
125
+ record.errors[attribute] << "must contains one or two path parts"
158
126
  end
159
127
  unless url_parts.all? { |url_part| valid_slug?(url_part) }
160
128
  record.errors[attribute] << "must be usable in a URL"
161
129
  end
162
130
  end
163
-
164
- private
165
- def acceptable_formats
166
- Artefact::FORMATS_BY_DEFAULT_OWNING_APP["specialist-publisher"] - unacceptable_formats
167
- end
168
-
169
- def unacceptable_formats
170
- [
171
- "manual",
172
- ]
173
- end
174
131
  end
175
132
 
176
- class BrowsePageValidator < InstanceValidator
133
+ class DetailedGuideValidator < InstanceValidator
177
134
  def applicable?
178
- of_kind?('specialist_sector')
135
+ of_kind?('detailed_guide')
179
136
  end
180
137
 
181
138
  def validate!
182
- unless [1, 2].include?(url_parts.size)
183
- record.errors[attribute] << "must contains one or two path parts"
184
- end
185
- unless url_parts.all? { |url_part| valid_slug?(url_part) }
186
- record.errors[attribute] << "must be usable in a URL"
187
- end
139
+ record.errors[attribute] << "must be a valid URL either at the root or under 'guidance/'" unless value.match(%r{^(guidance/)?[a-z0-9\-_]+$})
188
140
  end
189
141
  end
190
142
 
@@ -252,25 +252,6 @@ FactoryGirl.define do
252
252
  end
253
253
  end
254
254
 
255
- factory :rendered_specialist_document do
256
- sequence(:slug) {|n| "test-rendered-specialist-document-#{n}" }
257
- sequence(:title) {|n| "Test Rendered Specialist Document #{n}" }
258
- summary "My summary"
259
- body "<p>My body</p>"
260
- details({
261
- "opened_date" => "2013-04-20",
262
- "market_sector" => "some-market-sector",
263
- "case_type" => "a-case-type",
264
- "case_state" => "open",
265
- })
266
- end
267
-
268
- factory :rendered_manual do
269
- sequence(:slug) {|n| "test-rendered-manual-#{n}" }
270
- sequence(:title) {|n| "Test Rendered Manual #{n}" }
271
- summary "My summary"
272
- end
273
-
274
255
  factory :simple_smart_answer_edition, :parent => :edition, :class => "SimpleSmartAnswerEdition" do
275
256
  title "Simple smart answer"
276
257
  body "Introduction to the smart answer"
@@ -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 = "29.0.1"
3
+ VERSION = "29.1.0"
4
4
  end
@@ -424,15 +424,6 @@ class ArtefactTest < ActiveSupport::TestCase
424
424
  assert artefact.any_editions_published?
425
425
  end
426
426
 
427
- test "should have a specialist_body field present for markdown content" do
428
- artefact = Artefact.create!(slug: "parent", name: "Harry Potter", kind: "guide", owning_app: "x")
429
- refute_includes artefact.attributes, "specialist_body"
430
-
431
- artefact.specialist_body = "Something wicked this way comes"
432
- assert_includes artefact.attributes, "specialist_body"
433
- assert_equal "Something wicked this way comes", artefact.specialist_body
434
- end
435
-
436
427
  test "should have 'video' as a supported FORMAT" do
437
428
  assert_includes Artefact::FORMATS, "video"
438
429
  end
@@ -76,16 +76,6 @@ class SlugTest < ActiveSupport::TestCase
76
76
  end
77
77
  end
78
78
 
79
- context "Specialist documents" do
80
- should "all url nested one level deep" do
81
- assert document_with_slug("some-finder/my-specialist-document", kind: "cma_case").valid?;
82
- end
83
-
84
- should "not allow deeper nesting" do
85
- refute document_with_slug("some-finder/my-specialist-document/not-allowed", kind: "cma_case").valid?
86
- end
87
- end
88
-
89
79
  context "Specialist sector browse pages" do
90
80
  should "allow a single path part" do
91
81
  assert document_with_slug("oil-and-gas", kind: "specialist_sector").valid?
@@ -104,19 +94,18 @@ class SlugTest < ActiveSupport::TestCase
104
94
  end
105
95
  end
106
96
 
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?
97
+ context "Detailed guides slugs" do
98
+ should "allow a '/' in the slug" do
99
+ assert document_with_slug("guidance/british-forces-overseas-posting-cyprus", kind: "detailed_guide").valid?
111
100
  end
112
101
 
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?
102
+ should "allow only one '/' in the slug" do
103
+ refute document_with_slug("guidance/british-forces-overseas-posting-cyprus/more-information", kind: "detailed_guide").valid?
116
104
  end
117
105
 
118
- should "not allow invalid path segments" do
119
- refute document_with_slug("guidance/bad.manual.slug", kind: "manual").valid?
106
+ should "ensure it allows slugs that start at the root" do
107
+ assert document_with_slug("british-forces-overseas-posting-cyprus", kind: "detailed_guide").valid?
120
108
  end
109
+ #TODO: disallow this once guidance migration has been complete
121
110
  end
122
111
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_content_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 29.0.1
4
+ version: 29.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Battley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-28 00:00:00.000000000 Z
11
+ date: 2015-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bson_ext
@@ -307,10 +307,7 @@ files:
307
307
  - app/models/part.rb
308
308
  - app/models/parted.rb
309
309
  - app/models/place_edition.rb
310
- - app/models/prerendered_entity.rb
311
310
  - app/models/programme_edition.rb
312
- - app/models/rendered_manual.rb
313
- - app/models/rendered_specialist_document.rb
314
311
  - app/models/simple_smart_answer_edition.rb
315
312
  - app/models/simple_smart_answer_edition/node.rb
316
313
  - app/models/simple_smart_answer_edition/node/option.rb
@@ -360,7 +357,6 @@ files:
360
357
  - lib/govuk_content_models/version.rb
361
358
  - lib/mongoid/monkey_patches.rb
362
359
  - test/fixtures/contactotron_api_response.json
363
- - test/fixtures/specialist_document_fixtures.rb
364
360
  - test/fixtures/uploads/image.jpg
365
361
  - test/models/action_test.rb
366
362
  - test/models/artefact_action_test.rb
@@ -388,9 +384,6 @@ files:
388
384
  - test/models/local_transaction_edition_test.rb
389
385
  - test/models/overview_dashboard_test.rb
390
386
  - test/models/parted_test.rb
391
- - test/models/prerendered_entity_tests.rb
392
- - test/models/rendered_manual_test.rb
393
- - test/models/rendered_specialist_document_test.rb
394
387
  - test/models/simple_smart_answer_edition_test.rb
395
388
  - test/models/simple_smart_answer_node_test.rb
396
389
  - test/models/simple_smart_answer_option_test.rb
@@ -436,7 +429,6 @@ specification_version: 4
436
429
  summary: Shared models for Panopticon and Publisher, as a Rails Engine
437
430
  test_files:
438
431
  - test/fixtures/contactotron_api_response.json
439
- - test/fixtures/specialist_document_fixtures.rb
440
432
  - test/fixtures/uploads/image.jpg
441
433
  - test/models/action_test.rb
442
434
  - test/models/artefact_action_test.rb
@@ -464,9 +456,6 @@ test_files:
464
456
  - test/models/local_transaction_edition_test.rb
465
457
  - test/models/overview_dashboard_test.rb
466
458
  - test/models/parted_test.rb
467
- - test/models/prerendered_entity_tests.rb
468
- - test/models/rendered_manual_test.rb
469
- - test/models/rendered_specialist_document_test.rb
470
459
  - test/models/simple_smart_answer_edition_test.rb
471
460
  - test/models/simple_smart_answer_node_test.rb
472
461
  - test/models/simple_smart_answer_option_test.rb
@@ -1,13 +0,0 @@
1
- module PrerenderedEntity
2
- def create_or_update_by_slug!(attributes)
3
- find_or_initialize_by(
4
- slug: attributes.fetch(:slug)
5
- ).tap do |doc|
6
- doc.update_attributes!(attributes)
7
- end
8
- end
9
-
10
- def find_by_slug(slug)
11
- where(slug: slug).first
12
- end
13
- end
@@ -1,17 +0,0 @@
1
- require "prerendered_entity"
2
-
3
- class RenderedManual
4
- include Mongoid::Document
5
- include Mongoid::Timestamps
6
- extend PrerenderedEntity
7
-
8
- field :manual_id, type: String
9
- field :slug, type: String
10
- field :title, type: String
11
- field :summary, type: String
12
- field :section_groups, type: Array
13
-
14
- index "slug", unique: true
15
-
16
- validates_uniqueness_of :slug
17
- end
@@ -1,19 +0,0 @@
1
- require "prerendered_entity"
2
-
3
- class RenderedSpecialistDocument
4
- include Mongoid::Document
5
- include Mongoid::Timestamps
6
- extend PrerenderedEntity
7
-
8
- field :slug, type: String
9
- field :title, type: String
10
- field :summary, type: String
11
- field :body, type: String
12
- field :published_at, type: DateTime
13
-
14
- field :details, type: Hash
15
-
16
- index "slug", unique: true
17
-
18
- validates :slug, uniqueness: true
19
- end
@@ -1,16 +0,0 @@
1
- module SpecialistDocumentFixtures
2
- def basic_specialist_document_fields
3
- {
4
- slug: 'cma-cases/merger-investigation-2014',
5
- title: "Merger Investigation 2014",
6
- summary: "This is the summary of stuff going on in the Merger Investigation 2014",
7
- state: "published",
8
- body: "A body",
9
- opened_date: '2012-04-21',
10
- document_id: 'a-document-id',
11
- market_sector: 'oil-and-gas',
12
- case_type: 'some-case-type',
13
- case_state: 'open'
14
- }
15
- end
16
- end
@@ -1,46 +0,0 @@
1
- # include in a test class and define a #model_class instance method
2
-
3
- module PrerenderedEntityTests
4
- def test_duplicate_slug_not_allowed
5
- model_class.create(slug: "my-slug")
6
- second = model_class.create(slug: "my-slug")
7
-
8
- refute second.valid?
9
- assert_equal 1, model_class.count
10
- end
11
-
12
- def test_has_no_govspeak_fields
13
- refute model_class.const_defined?(:GOVSPEAK_FIELDS)
14
- end
15
-
16
- def test_create_or_update_by_slug
17
- slug = "a-slug"
18
- original_body = "Original body"
19
-
20
- version1_attrs= {
21
- slug: slug,
22
- body: original_body,
23
- }
24
-
25
- created = model_class.create_or_update_by_slug!(version1_attrs)
26
-
27
- assert created.is_a?(model_class)
28
- assert created.persisted?
29
-
30
- version2_attrs = version1_attrs.merge(
31
- body: "Updated body",
32
- )
33
-
34
- version2 = model_class.create_or_update_by_slug!(version2_attrs)
35
-
36
- assert version2.persisted?
37
- assert_equal "Updated body", version2.body
38
- end
39
-
40
- def test_find_by_slug
41
- created = model_class.create!(slug: "find-by-this-slug")
42
- found = model_class.find_by_slug("find-by-this-slug")
43
-
44
- assert_equal created, found
45
- end
46
- end
@@ -1,10 +0,0 @@
1
- require "test_helper"
2
- require_relative "prerendered_entity_tests"
3
-
4
- class RenderedManualTest < ActiveSupport::TestCase
5
- include PrerenderedEntityTests
6
-
7
- def model_class
8
- RenderedManual
9
- end
10
- end
@@ -1,12 +0,0 @@
1
- require "test_helper"
2
- require "fixtures/specialist_document_fixtures"
3
- require "models/prerendered_entity_tests"
4
-
5
- class RenderedSpecialistDocumentTest < ActiveSupport::TestCase
6
- include SpecialistDocumentFixtures
7
- include PrerenderedEntityTests
8
-
9
- def model_class
10
- RenderedSpecialistDocument
11
- end
12
- end