govuk_content_models 11.4.0 → 12.0.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
|
@@ -233,17 +233,6 @@ FactoryGirl.define do
|
|
|
233
233
|
end
|
|
234
234
|
end
|
|
235
235
|
|
|
236
|
-
factory :specialist_document_edition do
|
|
237
|
-
sequence(:slug) {|n| "test-specialist-document-#{n}" }
|
|
238
|
-
sequence(:title) {|n| "Test Specialist Document #{n}" }
|
|
239
|
-
summary "My summary"
|
|
240
|
-
body "My body"
|
|
241
|
-
opened_date '2013-04-20'
|
|
242
|
-
market_sector 'some-market-sector'
|
|
243
|
-
case_type 'a-case-type'
|
|
244
|
-
case_state 'open'
|
|
245
|
-
end
|
|
246
|
-
|
|
247
236
|
factory :rendered_specialist_document do
|
|
248
237
|
sequence(:slug) {|n| "test-rendered-specialist-document-#{n}" }
|
|
249
238
|
sequence(:title) {|n| "Test Rendered Specialist Document #{n}" }
|
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:
|
|
4
|
+
version: 12.0.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-09 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bson_ext
|
|
@@ -381,7 +381,6 @@ files:
|
|
|
381
381
|
- app/models/simple_smart_answer_edition.rb
|
|
382
382
|
- app/models/simple_smart_answer_edition/node.rb
|
|
383
383
|
- app/models/simple_smart_answer_edition/node/option.rb
|
|
384
|
-
- app/models/specialist_document_edition.rb
|
|
385
384
|
- app/models/tag.rb
|
|
386
385
|
- app/models/transaction_edition.rb
|
|
387
386
|
- app/models/travel_advice_edition.rb
|
|
@@ -437,7 +436,6 @@ files:
|
|
|
437
436
|
- test/models/simple_smart_answer_edition_test.rb
|
|
438
437
|
- test/models/simple_smart_answer_node_test.rb
|
|
439
438
|
- test/models/simple_smart_answer_option_test.rb
|
|
440
|
-
- test/models/specialist_document_edition_test.rb
|
|
441
439
|
- test/models/tag_test.rb
|
|
442
440
|
- test/models/time_zone_test.rb
|
|
443
441
|
- test/models/transaction_edition_test.rb
|
|
@@ -467,7 +465,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
467
465
|
version: '0'
|
|
468
466
|
segments:
|
|
469
467
|
- 0
|
|
470
|
-
hash:
|
|
468
|
+
hash: 3589363428373326753
|
|
471
469
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
472
470
|
none: false
|
|
473
471
|
requirements:
|
|
@@ -476,7 +474,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
476
474
|
version: '0'
|
|
477
475
|
segments:
|
|
478
476
|
- 0
|
|
479
|
-
hash:
|
|
477
|
+
hash: 3589363428373326753
|
|
480
478
|
requirements: []
|
|
481
479
|
rubyforge_project:
|
|
482
480
|
rubygems_version: 1.8.23
|
|
@@ -516,7 +514,6 @@ test_files:
|
|
|
516
514
|
- test/models/simple_smart_answer_edition_test.rb
|
|
517
515
|
- test/models/simple_smart_answer_node_test.rb
|
|
518
516
|
- test/models/simple_smart_answer_option_test.rb
|
|
519
|
-
- test/models/specialist_document_edition_test.rb
|
|
520
517
|
- test/models/tag_test.rb
|
|
521
518
|
- test/models/time_zone_test.rb
|
|
522
519
|
- test/models/transaction_edition_test.rb
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
require "state_machine"
|
|
2
|
-
|
|
3
|
-
class SpecialistDocumentEdition
|
|
4
|
-
include Mongoid::Document
|
|
5
|
-
include Mongoid::Timestamps
|
|
6
|
-
|
|
7
|
-
field :document_id, type: String
|
|
8
|
-
field :version_number, type: Integer, default: 1
|
|
9
|
-
|
|
10
|
-
field :title, type: String
|
|
11
|
-
field :created_at, type: DateTime, default: lambda { Time.zone.now }
|
|
12
|
-
field :slug, type: String
|
|
13
|
-
|
|
14
|
-
field :summary, type: String
|
|
15
|
-
field :body, type: String
|
|
16
|
-
field :opened_date, type: Date
|
|
17
|
-
field :closed_date, type: Date
|
|
18
|
-
field :case_type, type: String
|
|
19
|
-
field :case_state, type: String
|
|
20
|
-
field :market_sector, type: String
|
|
21
|
-
field :outcome_type, type: String
|
|
22
|
-
|
|
23
|
-
field :state, type: String
|
|
24
|
-
|
|
25
|
-
embeds_many :attachments, cascade_callbacks: true
|
|
26
|
-
|
|
27
|
-
state_machine initial: :draft do
|
|
28
|
-
event :publish do
|
|
29
|
-
transition draft: :published
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
event :archive do
|
|
33
|
-
transition all => :archived, :unless => :archived?
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
GOVSPEAK_FIELDS = [:body]
|
|
38
|
-
|
|
39
|
-
def whole_body
|
|
40
|
-
self.body
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
scope :draft, where(state: "draft")
|
|
44
|
-
scope :published, where(state: "published")
|
|
45
|
-
scope :archived, where(state: "archived")
|
|
46
|
-
|
|
47
|
-
validates :title, presence: true
|
|
48
|
-
validates :summary, presence: true
|
|
49
|
-
validates :body, presence: true
|
|
50
|
-
validates :opened_date, presence: true
|
|
51
|
-
validates :market_sector, presence: true
|
|
52
|
-
validates :case_type, presence: true
|
|
53
|
-
validates :case_state, presence: true
|
|
54
|
-
validates :version_number, presence: true
|
|
55
|
-
validates :document_id, presence: true
|
|
56
|
-
validates_with SafeHtml
|
|
57
|
-
|
|
58
|
-
index "document_id"
|
|
59
|
-
index "state"
|
|
60
|
-
|
|
61
|
-
def series
|
|
62
|
-
::SpecialistDocumentEdition.where(document_id: document_id)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def siblings
|
|
66
|
-
series.excludes(id: id)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def previous_siblings
|
|
70
|
-
siblings.where(:version_number.lt => version_number)
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def subsequent_siblings
|
|
74
|
-
siblings.where(:version_number.gt => version_number)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def latest_edition?
|
|
78
|
-
subsequent_siblings.empty?
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def build_attachment(attributes)
|
|
82
|
-
attachments.build(attributes.merge(
|
|
83
|
-
filename: attributes.fetch(:file).original_filename
|
|
84
|
-
))
|
|
85
|
-
end
|
|
86
|
-
end
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# encoding: UTF-8
|
|
2
|
-
|
|
3
|
-
require "test_helper"
|
|
4
|
-
require "fixtures/specialist_document_fixtures"
|
|
5
|
-
|
|
6
|
-
class SpecialistDocumentEditionTest < ActiveSupport::TestCase
|
|
7
|
-
include SpecialistDocumentFixtures
|
|
8
|
-
|
|
9
|
-
setup do
|
|
10
|
-
@original_asset_api_client = Attachable.asset_api_client
|
|
11
|
-
@success_response = stub("asset manager response", id: "/test-id", file_url: "/test-id/document.pdf")
|
|
12
|
-
Attachable.asset_api_client = stub("asset_api_client")
|
|
13
|
-
Attachable.asset_api_client.stubs(:create_asset).returns(@success_response)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
teardown do
|
|
17
|
-
Attachable.asset_api_client = @original_asset_api_client
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
should "have correct fields" do
|
|
21
|
-
edition = SpecialistDocumentEdition.new(basic_specialist_document_fields)
|
|
22
|
-
|
|
23
|
-
assert_equal basic_specialist_document_fields[:title], edition.title
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
should "be persistable" do
|
|
27
|
-
edition = SpecialistDocumentEdition.create!(basic_specialist_document_fields)
|
|
28
|
-
|
|
29
|
-
found = SpecialistDocumentEdition.where(slug: edition.slug).first
|
|
30
|
-
assert_equal found.attributes, edition.attributes
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context "building attachments" do
|
|
34
|
-
should "build an attachment" do
|
|
35
|
-
edition = SpecialistDocumentEdition.new
|
|
36
|
-
file = OpenStruct.new(original_filename: "document.pdf")
|
|
37
|
-
|
|
38
|
-
edition.build_attachment(title: "baz", file: file)
|
|
39
|
-
|
|
40
|
-
attachment = edition.attachments.first
|
|
41
|
-
assert_equal "baz", attachment.title
|
|
42
|
-
assert_equal "document.pdf", attachment.filename
|
|
43
|
-
assert_equal file, attachment.instance_variable_get(:@file_file)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
should "persist attachment record when document saved" do
|
|
47
|
-
Attachable.asset_api_client.stubs(:create_asset)
|
|
48
|
-
|
|
49
|
-
edition = SpecialistDocumentEdition.new(basic_specialist_document_fields)
|
|
50
|
-
file = OpenStruct.new(original_filename: "document.pdf")
|
|
51
|
-
|
|
52
|
-
edition.build_attachment(title: "baz", file: file)
|
|
53
|
-
edition.save!
|
|
54
|
-
|
|
55
|
-
found = SpecialistDocumentEdition.where(slug: edition.slug).first
|
|
56
|
-
|
|
57
|
-
assert_equal 1, found.attachments.count
|
|
58
|
-
assert_equal "baz", found.attachments.first.title
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
should "transmit attached file to asset manager when document saved" do
|
|
62
|
-
edition = SpecialistDocumentEdition.new(basic_specialist_document_fields)
|
|
63
|
-
file = OpenStruct.new(original_filename: "document.pdf")
|
|
64
|
-
|
|
65
|
-
Attachable.asset_api_client.expects(:create_asset).with(file: file).returns(@success_response)
|
|
66
|
-
|
|
67
|
-
edition.build_attachment(title: "baz", file: file)
|
|
68
|
-
edition.save!
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
should "be able to remove an attachment from the list of attachments" do
|
|
72
|
-
attributes = basic_specialist_document_fields.merge(
|
|
73
|
-
attachments: [Attachment.new(title: "example", filename: "example.pdf")]
|
|
74
|
-
)
|
|
75
|
-
edition = SpecialistDocumentEdition.create!(attributes)
|
|
76
|
-
assert_equal 1, edition.attachments.count
|
|
77
|
-
|
|
78
|
-
edition.attachments = []
|
|
79
|
-
edition.save!
|
|
80
|
-
|
|
81
|
-
edition.reload
|
|
82
|
-
assert_equal [], edition.attachments
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|