govuk_content_models 8.5.0 → 8.6.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
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
class RenderedSpecialistDocument
|
|
2
2
|
include Mongoid::Document
|
|
3
|
+
include Mongoid::Timestamps
|
|
3
4
|
|
|
4
5
|
field :slug, type: String
|
|
5
6
|
field :title, type: String
|
|
@@ -19,4 +20,16 @@ class RenderedSpecialistDocument
|
|
|
19
20
|
|
|
20
21
|
validates :slug, uniqueness: true
|
|
21
22
|
validates_with SafeHtml
|
|
23
|
+
|
|
24
|
+
def self.create_or_update_by_slug!(attributes)
|
|
25
|
+
RenderedSpecialistDocument.find_or_initialize_by(
|
|
26
|
+
slug: attributes.fetch(:slug)
|
|
27
|
+
).tap do |doc|
|
|
28
|
+
doc.update_attributes!(attributes)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.find_by_slug(slug)
|
|
33
|
+
where(slug: slug).first
|
|
34
|
+
end
|
|
22
35
|
end
|
|
@@ -269,6 +269,17 @@ FactoryGirl.define do
|
|
|
269
269
|
case_state 'open'
|
|
270
270
|
end
|
|
271
271
|
|
|
272
|
+
factory :rendered_specialist_document do
|
|
273
|
+
sequence(:slug) {|n| "test-rendered-specialist-document-#{n}" }
|
|
274
|
+
sequence(:title) {|n| "Test Rendered Specialist Document #{n}" }
|
|
275
|
+
summary "My summary"
|
|
276
|
+
body "<p>My body</p>"
|
|
277
|
+
opened_date '2013-04-20'
|
|
278
|
+
market_sector 'some-market-sector'
|
|
279
|
+
case_type 'a-case-type'
|
|
280
|
+
case_state 'open'
|
|
281
|
+
end
|
|
282
|
+
|
|
272
283
|
factory :simple_smart_answer_edition do
|
|
273
284
|
panopticon_id {
|
|
274
285
|
a = create(:artefact)
|
|
@@ -49,4 +49,35 @@ class RenderedSpecialistDocumentTest < ActiveSupport::TestCase
|
|
|
49
49
|
found = RenderedSpecialistDocument.where(slug: r.slug).first
|
|
50
50
|
assert_equal sample_headers, found.headers
|
|
51
51
|
end
|
|
52
|
+
|
|
53
|
+
test ".create_or_update_by_slug!" do
|
|
54
|
+
slug = "a-slug"
|
|
55
|
+
original_body = "Original body"
|
|
56
|
+
|
|
57
|
+
version1_attrs= {
|
|
58
|
+
slug: slug,
|
|
59
|
+
body: original_body,
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
created = RenderedSpecialistDocument.create_or_update_by_slug!(version1_attrs)
|
|
63
|
+
|
|
64
|
+
assert created.is_a?(RenderedSpecialistDocument)
|
|
65
|
+
assert created.persisted?
|
|
66
|
+
|
|
67
|
+
version2_attrs = version1_attrs.merge(
|
|
68
|
+
body: "Updated body",
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
version2 = RenderedSpecialistDocument.create_or_update_by_slug!(version2_attrs)
|
|
72
|
+
|
|
73
|
+
assert version2.persisted?
|
|
74
|
+
assert_equal "Updated body", version2.body
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
test ".find_by_slug" do
|
|
78
|
+
created = RenderedSpecialistDocument.create!(slug: "find-by-this-slug")
|
|
79
|
+
found = RenderedSpecialistDocument.find_by_slug("find-by-this-slug")
|
|
80
|
+
|
|
81
|
+
assert_equal created, found
|
|
82
|
+
end
|
|
52
83
|
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: 8.
|
|
4
|
+
version: 8.6.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-03-
|
|
12
|
+
date: 2014-03-13 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: 4252404017043972541
|
|
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: 4252404017043972541
|
|
476
476
|
requirements: []
|
|
477
477
|
rubyforge_project:
|
|
478
478
|
rubygems_version: 1.8.23
|