govuk_content_models 11.3.0 → 11.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +4 -0
- data/app/models/prerendered_entity.rb +13 -0
- data/app/models/rendered_manual.rb +20 -0
- data/app/models/rendered_specialist_document.rb +3 -12
- data/lib/govuk_content_models/test_helpers/factories.rb +6 -0
- data/lib/govuk_content_models/version.rb +1 -1
- data/test/models/prerendered_entity_tests.rb +46 -0
- data/test/models/rendered_manual_test.rb +10 -0
- data/test/models/rendered_specialist_document_test.rb +6 -43
- metadata +10 -4
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,13 @@
|
|
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
|
@@ -0,0 +1,20 @@
|
|
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
|
+
GOVSPEAK_FIELDS = []
|
17
|
+
|
18
|
+
validates_with SafeHtml
|
19
|
+
validates_uniqueness_of :slug
|
20
|
+
end
|
@@ -1,6 +1,9 @@
|
|
1
|
+
require "prerendered_entity"
|
2
|
+
|
1
3
|
class RenderedSpecialistDocument
|
2
4
|
include Mongoid::Document
|
3
5
|
include Mongoid::Timestamps
|
6
|
+
extend PrerenderedEntity
|
4
7
|
|
5
8
|
field :document_id, type: String
|
6
9
|
field :slug, type: String
|
@@ -25,16 +28,4 @@ class RenderedSpecialistDocument
|
|
25
28
|
|
26
29
|
validates :slug, uniqueness: true
|
27
30
|
validates_with SafeHtml
|
28
|
-
|
29
|
-
def self.create_or_update_by_slug!(attributes)
|
30
|
-
RenderedSpecialistDocument.find_or_initialize_by(
|
31
|
-
slug: attributes.fetch(:slug)
|
32
|
-
).tap do |doc|
|
33
|
-
doc.update_attributes!(attributes)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.find_by_slug(slug)
|
38
|
-
where(slug: slug).first
|
39
|
-
end
|
40
31
|
end
|
@@ -255,6 +255,12 @@ FactoryGirl.define do
|
|
255
255
|
case_state 'open'
|
256
256
|
end
|
257
257
|
|
258
|
+
factory :rendered_manual do
|
259
|
+
sequence(:slug) {|n| "test-rendered-manual-#{n}" }
|
260
|
+
sequence(:title) {|n| "Test Rendered Manual #{n}" }
|
261
|
+
summary "My summary"
|
262
|
+
end
|
263
|
+
|
258
264
|
factory :simple_smart_answer_edition, :parent => :edition, :class => "SimpleSmartAnswerEdition" do
|
259
265
|
title "Simple smart answer"
|
260
266
|
body "Introduction to the smart answer"
|
@@ -0,0 +1,46 @@
|
|
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
|
+
assert_equal [], model_class::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,8 +1,14 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
require "fixtures/specialist_document_fixtures"
|
3
|
+
require "models/prerendered_entity_tests"
|
3
4
|
|
4
5
|
class RenderedSpecialistDocumentTest < ActiveSupport::TestCase
|
5
6
|
include SpecialistDocumentFixtures
|
7
|
+
include PrerenderedEntityTests
|
8
|
+
|
9
|
+
def model_class
|
10
|
+
RenderedSpecialistDocument
|
11
|
+
end
|
6
12
|
|
7
13
|
def label_fields
|
8
14
|
{
|
@@ -49,18 +55,6 @@ class RenderedSpecialistDocumentTest < ActiveSupport::TestCase
|
|
49
55
|
assert_equal 1, RenderedSpecialistDocument.where(slug: r.slug).count
|
50
56
|
end
|
51
57
|
|
52
|
-
test "duplicate slugs disallowed" do
|
53
|
-
RenderedSpecialistDocument.create(slug: "my-slug")
|
54
|
-
second = RenderedSpecialistDocument.create(slug: "my-slug")
|
55
|
-
|
56
|
-
refute second.valid?
|
57
|
-
assert_equal 1, RenderedSpecialistDocument.count
|
58
|
-
end
|
59
|
-
|
60
|
-
test "has no govspeak fields" do
|
61
|
-
assert_equal [], RenderedSpecialistDocument::GOVSPEAK_FIELDS
|
62
|
-
end
|
63
|
-
|
64
58
|
test "can store headers hash" do
|
65
59
|
sample_headers = [
|
66
60
|
{
|
@@ -76,35 +70,4 @@ class RenderedSpecialistDocumentTest < ActiveSupport::TestCase
|
|
76
70
|
found = RenderedSpecialistDocument.where(slug: r.slug).first
|
77
71
|
assert_equal sample_headers, found.headers
|
78
72
|
end
|
79
|
-
|
80
|
-
test ".create_or_update_by_slug!" do
|
81
|
-
slug = "a-slug"
|
82
|
-
original_body = "Original body"
|
83
|
-
|
84
|
-
version1_attrs= {
|
85
|
-
slug: slug,
|
86
|
-
body: original_body,
|
87
|
-
}
|
88
|
-
|
89
|
-
created = RenderedSpecialistDocument.create_or_update_by_slug!(version1_attrs)
|
90
|
-
|
91
|
-
assert created.is_a?(RenderedSpecialistDocument)
|
92
|
-
assert created.persisted?
|
93
|
-
|
94
|
-
version2_attrs = version1_attrs.merge(
|
95
|
-
body: "Updated body",
|
96
|
-
)
|
97
|
-
|
98
|
-
version2 = RenderedSpecialistDocument.create_or_update_by_slug!(version2_attrs)
|
99
|
-
|
100
|
-
assert version2.persisted?
|
101
|
-
assert_equal "Updated body", version2.body
|
102
|
-
end
|
103
|
-
|
104
|
-
test ".find_by_slug" do
|
105
|
-
created = RenderedSpecialistDocument.create!(slug: "find-by-this-slug")
|
106
|
-
found = RenderedSpecialistDocument.find_by_slug("find-by-this-slug")
|
107
|
-
|
108
|
-
assert_equal created, found
|
109
|
-
end
|
110
73
|
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.4.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
|
+
date: 2014-06-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bson_ext
|
@@ -374,7 +374,9 @@ files:
|
|
374
374
|
- app/models/part.rb
|
375
375
|
- app/models/parted.rb
|
376
376
|
- app/models/place_edition.rb
|
377
|
+
- app/models/prerendered_entity.rb
|
377
378
|
- app/models/programme_edition.rb
|
379
|
+
- app/models/rendered_manual.rb
|
378
380
|
- app/models/rendered_specialist_document.rb
|
379
381
|
- app/models/simple_smart_answer_edition.rb
|
380
382
|
- app/models/simple_smart_answer_edition/node.rb
|
@@ -429,6 +431,8 @@ files:
|
|
429
431
|
- test/models/local_service_test.rb
|
430
432
|
- test/models/local_transaction_edition_test.rb
|
431
433
|
- test/models/overview_dashboard_test.rb
|
434
|
+
- test/models/prerendered_entity_tests.rb
|
435
|
+
- test/models/rendered_manual_test.rb
|
432
436
|
- test/models/rendered_specialist_document_test.rb
|
433
437
|
- test/models/simple_smart_answer_edition_test.rb
|
434
438
|
- test/models/simple_smart_answer_node_test.rb
|
@@ -463,7 +467,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
463
467
|
version: '0'
|
464
468
|
segments:
|
465
469
|
- 0
|
466
|
-
hash:
|
470
|
+
hash: 2714656676464909163
|
467
471
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
468
472
|
none: false
|
469
473
|
requirements:
|
@@ -472,7 +476,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
472
476
|
version: '0'
|
473
477
|
segments:
|
474
478
|
- 0
|
475
|
-
hash:
|
479
|
+
hash: 2714656676464909163
|
476
480
|
requirements: []
|
477
481
|
rubyforge_project:
|
478
482
|
rubygems_version: 1.8.23
|
@@ -506,6 +510,8 @@ test_files:
|
|
506
510
|
- test/models/local_service_test.rb
|
507
511
|
- test/models/local_transaction_edition_test.rb
|
508
512
|
- test/models/overview_dashboard_test.rb
|
513
|
+
- test/models/prerendered_entity_tests.rb
|
514
|
+
- test/models/rendered_manual_test.rb
|
509
515
|
- test/models/rendered_specialist_document_test.rb
|
510
516
|
- test/models/simple_smart_answer_edition_test.rb
|
511
517
|
- test/models/simple_smart_answer_node_test.rb
|