govuk_content_models 42.0.0 → 42.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/app/traits/attachable.rb +2 -2
  4. data/govuk_content_models.gemspec +1 -2
  5. data/lib/govuk_content_models/version.rb +1 -1
  6. metadata +3 -83
  7. data/test/fixtures/uploads/image.jpg +0 -0
  8. data/test/models/action_test.rb +0 -13
  9. data/test/models/artefact_action_test.rb +0 -130
  10. data/test/models/artefact_external_link_test.rb +0 -32
  11. data/test/models/artefact_test.rb +0 -482
  12. data/test/models/business_support/business_size_test.rb +0 -25
  13. data/test/models/business_support/business_type_test.rb +0 -25
  14. data/test/models/business_support/location_test.rb +0 -25
  15. data/test/models/business_support/purpose_test.rb +0 -29
  16. data/test/models/business_support/sector_test.rb +0 -25
  17. data/test/models/business_support/stage_test.rb +0 -25
  18. data/test/models/business_support/support_type_test.rb +0 -25
  19. data/test/models/business_support_edition_test.rb +0 -282
  20. data/test/models/campaign_edition_test.rb +0 -91
  21. data/test/models/completed_transaction_edition_test.rb +0 -56
  22. data/test/models/downtime_test.rb +0 -93
  23. data/test/models/edition_scheduled_for_publishing_test.rb +0 -91
  24. data/test/models/edition_test.rb +0 -1185
  25. data/test/models/help_page_edition_test.rb +0 -43
  26. data/test/models/licence_edition_test.rb +0 -105
  27. data/test/models/local_service_test.rb +0 -6
  28. data/test/models/local_transaction_edition_test.rb +0 -37
  29. data/test/models/overview_dashboard_test.rb +0 -46
  30. data/test/models/parted_test.rb +0 -26
  31. data/test/models/prerendered_entity_tests.rb +0 -46
  32. data/test/models/rendered_manual_test.rb +0 -10
  33. data/test/models/simple_smart_answer_edition_test.rb +0 -211
  34. data/test/models/simple_smart_answer_node_test.rb +0 -134
  35. data/test/models/simple_smart_answer_option_test.rb +0 -97
  36. data/test/models/time_zone_test.rb +0 -48
  37. data/test/models/transaction_edition_test.rb +0 -36
  38. data/test/models/travel_advice_edition_test.rb +0 -469
  39. data/test/models/user_test.rb +0 -155
  40. data/test/models/video_edition_test.rb +0 -64
  41. data/test/models/workflow_test.rb +0 -498
  42. data/test/test_helper.rb +0 -61
  43. data/test/traits/attachable_test.rb +0 -244
  44. data/test/validators/link_validator_test.rb +0 -86
  45. data/test/validators/safe_html_validator_test.rb +0 -83
  46. data/test/validators/slug_validator_test.rb +0 -109
@@ -1,134 +0,0 @@
1
- require "test_helper"
2
-
3
- class SimpleSmartAnswerNodeTest < ActiveSupport::TestCase
4
-
5
- context "given a smart answer exists" do
6
- setup do
7
- @edition = FactoryGirl.create(:simple_smart_answer_edition)
8
-
9
- @atts = {
10
- title: "How much wood could a woodchuck chuck if a woodchuck could chuck wood?",
11
- slug: "how-much-wood-could-a-woodchuck-chuck-if-a-woodchuck-could-chuck-wood",
12
- body: "This is a serious question.",
13
- kind: "question"
14
- }
15
- end
16
-
17
- should "be able to create a valid node" do
18
- @node = @edition.nodes.build(@atts)
19
-
20
- assert @node.save!
21
-
22
- @edition.reload
23
-
24
- assert_equal "how-much-wood-could-a-woodchuck-chuck-if-a-woodchuck-could-chuck-wood", @edition.nodes.first.slug
25
- assert_equal "How much wood could a woodchuck chuck if a woodchuck could chuck wood?", @edition.nodes.first.title
26
- assert_equal "This is a serious question.", @edition.nodes.first.body
27
- end
28
-
29
- should "not be valid without a slug" do
30
- @node = @edition.nodes.build( @atts.merge(slug: "") )
31
-
32
- assert ! @node.valid?
33
- assert_equal [:slug], @node.errors.keys
34
- end
35
-
36
- should "not be valid with an invalid slug" do
37
- @node = @edition.nodes.build(@atts)
38
-
39
- [
40
- 'under_score',
41
- 'space space',
42
- 'punct.u&ation',
43
- ].each do |slug|
44
- @node.slug = slug
45
- refute @node.valid?
46
- end
47
- end
48
-
49
- should "not be valid without a title" do
50
- @node = @edition.nodes.build( @atts.merge(title: "") )
51
-
52
- assert ! @node.valid?
53
- assert_equal [:title], @node.errors.keys
54
- end
55
-
56
- should "not be valid without a kind" do
57
- @node = @edition.nodes.build(@atts.merge(:kind => nil))
58
- assert ! @node.valid?
59
-
60
- assert_equal [:kind], @node.errors.keys
61
- end
62
-
63
- should "not be valid with a kind other than 'question' or 'outcome'" do
64
- @node = @edition.nodes.build(@atts.merge(:kind => 'blah'))
65
- assert ! @node.valid?
66
-
67
- assert_equal [:kind], @node.errors.keys
68
- end
69
-
70
- should "create options using nested attributes" do
71
- @node = @edition.nodes.create!(@atts.merge(:options_attributes => [
72
- { :label => "Yes", :next_node => "yes" },
73
- { :label => "No", :next_node => "no" }
74
- ]))
75
-
76
- @node.reload
77
- assert_equal 2, @node.options.count
78
- assert_equal ["Yes", "No"], @node.options.all.map(&:label)
79
- assert_equal ["yes", "no"], @node.options.all.map(&:next_node)
80
- end
81
-
82
- should "destroy options using nested attributes" do
83
- @node = @edition.nodes.create!(@atts.merge(:options_attributes => [
84
- { :label => "Yes", :next_node => "yes" },
85
- { :label => "No", :next_node => "no" }
86
- ]))
87
- assert_equal 2, @node.options.count
88
-
89
- @node.update_attributes!(:options_attributes => {
90
- "1" => { "id" => @node.options.first.id, "_destroy" => "1" }
91
- })
92
- @node.reload
93
-
94
- assert_equal 1, @node.options.count
95
- assert_equal ["No"], @node.options.all.map(&:label)
96
- assert_equal ["no"], @node.options.all.map(&:next_node)
97
- end
98
-
99
- should "not be valid if an outcome has options" do
100
- @node = @edition.nodes.build(@atts.merge(:kind => 'outcome', options_attributes: [
101
- { :label => "Yes", :next_node => "yes" },
102
- { :label => "No", :next_node => "no" }
103
- ]))
104
- assert ! @node.valid?
105
-
106
- assert_equal [:options], @node.errors.keys
107
- end
108
-
109
- should "be able to create an outcome without options" do
110
- @node = @edition.nodes.build(@atts.merge(:kind => 'outcome', :options_attributes => [] ))
111
-
112
- assert @node.valid?
113
- assert @node.save!
114
- end
115
-
116
- should "be returned in order" do
117
- @nodes = [
118
- @edition.nodes.create(@atts.merge(:title => "Third", :order => 3)),
119
- @edition.nodes.create(@atts.merge(:title => "First", :order => 1)),
120
- @edition.nodes.create(@atts.merge(:title => "Second", :order => 2)),
121
- ]
122
-
123
- assert_equal ["First","Second","Third"], @edition.nodes.all.map(&:title)
124
- end
125
-
126
- should "expose the simple smart answer edition" do
127
- @node = @edition.nodes.build(@atts)
128
-
129
- assert_equal @node.edition, @edition
130
- end
131
-
132
- end
133
-
134
- end
@@ -1,97 +0,0 @@
1
- require "test_helper"
2
-
3
- class SimpleSmartAnswerOptionTest < ActiveSupport::TestCase
4
-
5
- context "given a smart answer exists with a node" do
6
- setup do
7
- @node = SimpleSmartAnswerEdition::Node.new(:slug => "question1", :title => "Question One?", :kind => "question")
8
- @edition = FactoryGirl.create(:simple_smart_answer_edition, :nodes => [
9
- @node,
10
- SimpleSmartAnswerEdition::Node.new(:slug => "outcome1", :title => "Outcome One", :kind => "outcome")
11
- ])
12
-
13
- @atts = {
14
- label: "Yes",
15
- next_node: "yes"
16
- }
17
- end
18
-
19
- should "be able to create a valid option" do
20
- @option = @node.options.build(@atts)
21
-
22
- assert @option.save!
23
- @node.reload
24
-
25
- assert_equal "Yes", @node.options.first.label
26
- assert_equal "yes", @node.options.first.next_node
27
- end
28
-
29
- should "not be valid without a label" do
30
- @option = @node.options.build(@atts.merge(label: nil))
31
-
32
- assert !@option.valid?
33
- assert @option.errors.keys.include?(:label)
34
- end
35
-
36
- should "not be valid without the next node" do
37
- @option = @node.options.build(@atts.merge(next_node: nil))
38
-
39
- assert !@option.valid?
40
- assert @option.errors.keys.include?(:next_node)
41
- end
42
-
43
- should "expose the node" do
44
- @option = @node.options.create(@atts)
45
- @option.reload
46
-
47
- assert_equal @node, @option.node
48
- end
49
-
50
- should "return in order" do
51
- @options = [
52
- @node.options.create(@atts.merge(:label => "Third", :next_node => "baz", :order => 3)),
53
- @node.options.create(@atts.merge(:label => "First", :next_node => "foo", :order => 1)),
54
- @node.options.create(@atts.merge(:label => "Second", :next_node => "bar", :order => 2)),
55
- ]
56
-
57
- assert_equal ["First","Second","Third"], @node.options.all.map(&:label)
58
- assert_equal ["foo","bar","baz"], @node.options.all.map(&:next_node)
59
- end
60
-
61
- context "slug" do
62
- should "generate a slug from the label if blank" do
63
- @option = @node.options.build(@atts)
64
-
65
- assert @option.valid?
66
- assert_equal "yes", @option.slug
67
- end
68
-
69
- should "keep the slug up to date if the label changes" do
70
- @option = @node.options.create(@atts.merge(slug: "most-likely"))
71
- @option.label = "Most of the times"
72
- assert @option.valid?
73
- assert_equal "most-of-the-times", @option.slug
74
- end
75
-
76
- should "not overwrite a given slug" do
77
- @option = @node.options.build(@atts.merge(:slug => "fooey"))
78
-
79
- assert @option.valid?
80
- assert_equal "fooey", @option.slug
81
- end
82
-
83
- should "not be valid with an invalid slug" do
84
- @option = @node.options.build(@atts)
85
-
86
- [
87
- 'under_score',
88
- 'space space',
89
- 'punct.u&ation',
90
- ].each do |slug|
91
- @option.slug = slug
92
- refute @option.valid?
93
- end
94
- end
95
- end
96
- end
97
- end
@@ -1,48 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TimeZoneTest < ActiveSupport::TestCase
4
- def first_day_of_summer_time
5
- Time.zone.parse("2013-04-01")
6
- end
7
-
8
- def wintertime
9
- Time.zone.parse("2013-01-01")
10
- end
11
-
12
- context "use_activesupport_time_zone is set to true, Time.zone is set to 'London'" do
13
- setup do
14
- # This context has already been set in the local mongoid.yml, and in test_helper.rb
15
- end
16
-
17
- should "still store the date in UTC" do
18
- Timecop.freeze(wintertime) do
19
- FactoryGirl.create(:artefact)
20
- assert_equal 'UTC', Artefact.last[:created_at].zone
21
- assert_equal 'GMT', Artefact.last.created_at.zone
22
- end
23
- end
24
-
25
- should "use the Time.zone time zone for dot-methods" do
26
- Timecop.freeze(wintertime) do
27
- FactoryGirl.create(:artefact)
28
- assert_equal 'GMT', Artefact.last.created_at.zone
29
- end
30
- end
31
-
32
- context "it is currently British Summer Time" do
33
- should "still store the date in UTC" do
34
- Timecop.freeze(first_day_of_summer_time) do
35
- FactoryGirl.create(:artefact)
36
- assert_equal 'UTC', Artefact.last[:created_at].zone
37
- end
38
- end
39
-
40
- should "use the time zone with offset for dot-methods" do
41
- Timecop.freeze(first_day_of_summer_time) do
42
- FactoryGirl.create(:artefact)
43
- assert_equal 'BST', Artefact.last.created_at.zone
44
- end
45
- end
46
- end
47
- end
48
- end
@@ -1,36 +0,0 @@
1
- require 'test_helper'
2
-
3
- class TransactionEditionTest < ActiveSupport::TestCase
4
-
5
- setup do
6
- @artefact = FactoryGirl.create(:artefact)
7
- end
8
-
9
- context 'Department analytics profiles' do
10
- should "only allow valid Google Analytics profiles" do
11
- transaction = FactoryGirl.create(:transaction_edition, panopticon_id: @artefact.id)
12
-
13
- ['invalid', 'ua-12345', 'UA-1234A-1'].each do |id|
14
- transaction.department_analytics_profile = id
15
- refute transaction.valid?
16
- end
17
-
18
- ['ua-123456-1', 'UA-00-10'].each do |id|
19
- transaction.department_analytics_profile = id
20
- assert transaction.valid?
21
- end
22
- end
23
- end
24
-
25
- context "indexable_content" do
26
- should "include the introduction without markup" do
27
- transaction = FactoryGirl.create(:transaction_edition, introduction: "## introduction", more_information: "", panopticon_id: @artefact.id)
28
- assert_equal "introduction", transaction.indexable_content
29
- end
30
-
31
- should "include the more_information without markup" do
32
- transaction = FactoryGirl.create(:transaction_edition, more_information: "## more info", introduction: "", panopticon_id: @artefact.id)
33
- assert_equal "more info", transaction.indexable_content
34
- end
35
- end
36
- end
@@ -1,469 +0,0 @@
1
- # encoding: UTF-8
2
-
3
- require "test_helper"
4
-
5
- class TravelAdviceEditionTest < ActiveSupport::TestCase
6
-
7
- should "have correct fields" do
8
- ed = TravelAdviceEdition.new
9
- ed.title = "Travel advice for Aruba"
10
- ed.overview = "This gives travel advice for Aruba"
11
- ed.country_slug = 'aruba'
12
- ed.alert_status = [ 'avoid_all_but_essential_travel_to_parts', 'avoid_all_travel_to_parts' ]
13
- ed.summary = "This is the summary of stuff going on in Aruba"
14
- ed.version_number = 4
15
- ed.image_id = "id_from_the_asset_manager_for_an_image"
16
- ed.document_id = "id_from_the_asset_manager_for_a_document"
17
- ed.published_at = Time.zone.parse('2013-02-21T14:56:22Z')
18
- ed.minor_update = true
19
- ed.change_description = "Some things"
20
- ed.synonyms = ["Foo", "Bar"]
21
- ed.parts.build(:title => "Part One", :slug => "one")
22
- ed.save!
23
-
24
- ed = TravelAdviceEdition.first
25
- assert_equal "Travel advice for Aruba", ed.title
26
- assert_equal "This gives travel advice for Aruba", ed.overview
27
- assert_equal 'aruba', ed.country_slug
28
- assert_equal [ 'avoid_all_but_essential_travel_to_parts', 'avoid_all_travel_to_parts' ], ed.alert_status
29
- assert_equal "This is the summary of stuff going on in Aruba", ed.summary
30
- assert_equal 4, ed.version_number
31
- assert_equal "id_from_the_asset_manager_for_an_image", ed.image_id
32
- assert_equal "id_from_the_asset_manager_for_a_document", ed.document_id
33
- assert_equal Time.zone.parse('2013-02-21T14:56:22Z'), ed.published_at
34
- assert_equal true, ed.minor_update
35
- assert_equal ["Foo", "Bar"], ed.synonyms
36
- assert_equal "Some things", ed.change_description
37
- assert_equal "Part One", ed.parts.first.title
38
- end
39
-
40
- context "validations" do
41
- setup do
42
- @ta = FactoryGirl.build(:travel_advice_edition)
43
- end
44
-
45
- should "require a country slug" do
46
- @ta.country_slug = ''
47
- assert ! @ta.valid?
48
- assert_includes @ta.errors.messages[:country_slug], "can't be blank"
49
- end
50
-
51
- should "require a title" do
52
- @ta.title = ''
53
- assert ! @ta.valid?
54
- assert_includes @ta.errors.messages[:title], "can't be blank"
55
- end
56
-
57
- context "on state" do
58
- should "only allow one edition in draft per slug" do
59
- another_edition = FactoryGirl.create(:travel_advice_edition,
60
- :country_slug => @ta.country_slug)
61
- @ta.state = 'draft'
62
- assert ! @ta.valid?
63
- assert_includes @ta.errors.messages[:state], "is already taken"
64
- end
65
-
66
- should "only allow one edition in published per slug" do
67
- another_edition = FactoryGirl.create(:published_travel_advice_edition,
68
- :country_slug => @ta.country_slug)
69
- @ta.state = 'published'
70
- assert ! @ta.valid?
71
- assert_includes @ta.errors.messages[:state], "is already taken"
72
- end
73
-
74
- should "allow multiple editions in archived per slug" do
75
- another_edition = FactoryGirl.create(:archived_travel_advice_edition,
76
- :country_slug => @ta.country_slug)
77
- @ta.save!
78
- @ta.state = 'archived'
79
- assert @ta.valid?
80
- end
81
-
82
- should "not conflict with itself when validating uniqueness" do
83
- @ta.state = 'draft'
84
- @ta.save!
85
- assert @ta.valid?
86
- end
87
- end
88
-
89
- context "preventing editing of non-draft" do
90
- should "not allow published editions to be edited" do
91
- ta = FactoryGirl.create(:published_travel_advice_edition)
92
- ta.title = "Fooey"
93
- assert ! ta.valid?
94
- assert_includes ta.errors.messages[:state], "must be draft to modify"
95
- end
96
-
97
- should "not allow archived editions to be edited" do
98
- ta = FactoryGirl.create(:archived_travel_advice_edition)
99
- ta.title = "Fooey"
100
- assert ! ta.valid?
101
- assert_includes ta.errors.messages[:state], "must be draft to modify"
102
- end
103
-
104
- should "allow publishing draft editions" do
105
- ta = FactoryGirl.create(:travel_advice_edition)
106
- assert ta.publish
107
- end
108
-
109
- should "allow 'save & publish'" do
110
- ta = FactoryGirl.create(:travel_advice_edition)
111
- ta.title = 'Foo'
112
- assert ta.publish
113
- end
114
-
115
- should "allow archiving published editions" do
116
- ta = FactoryGirl.create(:published_travel_advice_edition)
117
- assert ta.archive
118
- end
119
-
120
- should "NOT allow 'save & archive'" do
121
- ta = FactoryGirl.create(:published_travel_advice_edition)
122
- ta.title = 'Foo'
123
- assert ! ta.archive
124
- assert_includes ta.errors.messages[:state], "must be draft to modify"
125
- end
126
- end
127
-
128
- context "on alert status" do
129
- should "not permit invalid values in the array" do
130
- @ta.alert_status = [ 'avoid_all_but_essential_travel_to_parts', 'something_else', 'blah' ]
131
- assert ! @ta.valid?
132
- assert_includes @ta.errors.messages[:alert_status], "is not in the list"
133
- end
134
-
135
- should "permit an empty array" do
136
- @ta.alert_status = [ ]
137
- assert @ta.valid?
138
- end
139
-
140
- # Test that accessing an Array field doesn't mark it as dirty.
141
- # mongoid/dirty#changes method is patched in lib/mongoid/monkey_patches.rb
142
- # See https://github.com/mongoid/mongoid/issues/2311 for details.
143
- should "track changes to alert status accurately" do
144
- @ta.alert_status = [ ]
145
- @ta.alert_status
146
- assert @ta.valid?
147
- end
148
- end
149
-
150
- context "on version_number" do
151
- should "require a version_number" do
152
- @ta.save # version_number is automatically populated on create, so save it first.
153
- @ta.version_number = ''
154
- refute @ta.valid?
155
- assert_includes @ta.errors.messages[:version_number], "can't be blank"
156
- end
157
-
158
- should "require a unique version_number per slug" do
159
- another_edition = FactoryGirl.create(:archived_travel_advice_edition,
160
- :country_slug => @ta.country_slug,
161
- :version_number => 3)
162
- @ta.version_number = 3
163
- refute @ta.valid?
164
- assert_includes @ta.errors.messages[:version_number], "is already taken"
165
- end
166
-
167
- should "allow matching version_numbers for different slugs" do
168
- another_edition = FactoryGirl.create(:archived_travel_advice_edition,
169
- :country_slug => 'wibble',
170
- :version_number => 3)
171
- @ta.version_number = 3
172
- assert @ta.valid?
173
- end
174
- end
175
-
176
- context "on minor update" do
177
- should "not allow first version to be minor update" do
178
- @ta.minor_update = true
179
- refute @ta.valid?
180
- assert_includes @ta.errors.messages[:minor_update], "can't be set for first version"
181
- end
182
-
183
- should "allow other versions to be minor updates" do
184
- FactoryGirl.create(:published_travel_advice_edition, :country_slug => @ta.country_slug)
185
- @ta.minor_update = true
186
- assert @ta.valid?
187
- end
188
- end
189
-
190
- context "on change_description" do
191
- should "be required on publish" do
192
- @ta.save! # Can't save directly as published, have to save as draft first
193
- @ta.change_description = ""
194
- @ta.state = "published"
195
- refute @ta.valid?
196
- assert_includes @ta.errors.messages[:change_description], "can't be blank on publish"
197
- end
198
-
199
- should "not be required on publish for a minor update" do
200
- FactoryGirl.create(:archived_travel_advice_edition, :country_slug => @ta.country_slug)
201
- @ta.version_number = 2 # version one can't be minor update
202
- @ta.save! # Can't save directly as published, have to save as draft first
203
- @ta.change_description = ""
204
- @ta.minor_update = true
205
- @ta.state = "published"
206
- assert @ta.valid?
207
- end
208
-
209
- should "not be required when just saving a draft" do
210
- @ta.change_description = ""
211
- assert @ta.valid?
212
- end
213
- end
214
- end
215
-
216
- should "have a published scope" do
217
- e1 = FactoryGirl.create(:draft_travel_advice_edition)
218
- e2 = FactoryGirl.create(:published_travel_advice_edition)
219
- e3 = FactoryGirl.create(:archived_travel_advice_edition)
220
- e4 = FactoryGirl.create(:published_travel_advice_edition)
221
-
222
- assert_equal [e2, e4].sort, TravelAdviceEdition.published.to_a.sort
223
- end
224
-
225
- context "fields on a new edition" do
226
- should "be in draft state" do
227
- assert TravelAdviceEdition.new.draft?
228
- end
229
-
230
- context "populating version_number" do
231
- should "set version_number to 1 if there are no existing versions for the country" do
232
- ed = TravelAdviceEdition.new(:country_slug => 'foo')
233
- ed.valid?
234
- assert_equal 1, ed.version_number
235
- end
236
-
237
- should "set version_number to the next available version" do
238
- FactoryGirl.create(:archived_travel_advice_edition, :country_slug => 'foo', :version_number => 1)
239
- FactoryGirl.create(:archived_travel_advice_edition, :country_slug => 'foo', :version_number => 2)
240
- FactoryGirl.create(:published_travel_advice_edition, :country_slug => 'foo', :version_number => 4)
241
-
242
- ed = TravelAdviceEdition.new(:country_slug => 'foo')
243
- ed.valid?
244
- assert_equal 5, ed.version_number
245
- end
246
-
247
- should "do nothing if version_number is already set" do
248
- ed = TravelAdviceEdition.new(:country_slug => 'foo', :version_number => 42)
249
- ed.valid?
250
- assert_equal 42, ed.version_number
251
- end
252
-
253
- should "do nothing if country_slug is not set" do
254
- ed = TravelAdviceEdition.new(:country_slug => '')
255
- ed.valid?
256
- assert_equal nil, ed.version_number
257
- end
258
- end
259
-
260
- should "not be minor_update" do
261
- assert_equal false, TravelAdviceEdition.new.minor_update
262
- end
263
- end
264
-
265
- context "building a new version" do
266
- setup do
267
- @ed = FactoryGirl.create(:travel_advice_edition,
268
- :title => "Aruba",
269
- :overview => "Aruba is not near Wales",
270
- :country_slug => "aruba",
271
- :summary => "## The summary",
272
- :alert_status => ["avoid_all_but_essential_travel_to_whole_country", "avoid_all_travel_to_parts"],
273
- :image_id => "id_from_the_asset_manager_for_an_image",
274
- :document_id => "id_from_the_asset_manager_for_a_document")
275
- @ed.parts.build(:title => "Fooey", :slug => 'fooey', :body => "It's all about Fooey")
276
- @ed.parts.build(:title => "Gooey", :slug => 'gooey', :body => "It's all about Gooey")
277
- @ed.save!
278
- @ed.publish!
279
- end
280
-
281
- should "build a new instance with the same fields" do
282
- new_ed = @ed.build_clone
283
- assert new_ed.new_record?
284
- assert new_ed.valid?
285
- assert_equal @ed.title, new_ed.title
286
- assert_equal @ed.country_slug, new_ed.country_slug
287
- assert_equal @ed.overview, new_ed.overview
288
- assert_equal @ed.summary, new_ed.summary
289
- assert_equal @ed.image_id, new_ed.image_id
290
- assert_equal @ed.document_id, new_ed.document_id
291
- assert_equal @ed.alert_status, new_ed.alert_status
292
- end
293
-
294
- should "copy the edition's parts" do
295
- new_ed = @ed.build_clone
296
- assert_equal ['Fooey', 'Gooey'], new_ed.parts.map(&:title)
297
- end
298
- end
299
-
300
- context "previous_version" do
301
- setup do
302
- @ed1 = FactoryGirl.create(:archived_travel_advice_edition, :country_slug => 'foo')
303
- @ed2 = FactoryGirl.create(:archived_travel_advice_edition, :country_slug => 'foo')
304
- @ed3 = FactoryGirl.create(:archived_travel_advice_edition, :country_slug => 'foo')
305
- end
306
-
307
- should "return the previous version" do
308
- assert_equal @ed2, @ed3.previous_version
309
- assert_equal @ed1, @ed2.previous_version
310
- end
311
-
312
- should "return nil if there is no previous version" do
313
- assert_equal nil, @ed1.previous_version
314
- end
315
- end
316
-
317
- context "publishing" do
318
- setup do
319
- @published = FactoryGirl.create(:published_travel_advice_edition, :country_slug => 'aruba',
320
- :published_at => 3.days.ago, :change_description => 'Stuff changed')
321
- @ed = FactoryGirl.create(:travel_advice_edition, :country_slug => 'aruba')
322
- @published.reload
323
- end
324
-
325
- should "publish the edition and archive related editions" do
326
- @ed.publish!
327
- @published.reload
328
- assert @ed.published?
329
- assert @published.archived?
330
- end
331
-
332
- context "setting the published date" do
333
- should "set the published_at to now for a normal update" do
334
- Timecop.freeze(1.day.from_now) do
335
- @ed.publish!
336
- # The to_i is necessary to account for the difference in milliseconds
337
- # Time from the db only has a resolution in seconds, whereas Time.zone.now is more accurate
338
- assert_equal Time.zone.now.utc.to_i, @ed.published_at.to_i
339
- end
340
- end
341
-
342
- should "set the published_at to the previous version's published_at for a minor update" do
343
- @ed.minor_update = true
344
- @ed.publish!
345
- assert_equal @published.published_at, @ed.published_at
346
- end
347
- end
348
-
349
- should "set the change_description to the previous version's change_description for a minor update" do
350
- @ed.minor_update = true
351
- @ed.publish!
352
- assert_equal @published.change_description, @ed.change_description
353
- end
354
- end
355
-
356
- context "setting the reviewed at date" do
357
- setup do
358
- @published = FactoryGirl.create(:published_travel_advice_edition, :country_slug => 'aruba',
359
- :published_at => 3.days.ago, :change_description => 'Stuff changed')
360
- @published.reviewed_at = 2.days.ago
361
- @published.save!
362
- @published.reload
363
-
364
- Timecop.freeze(1.days.ago) do
365
- # this is done to make sure there's a significant difference in time
366
- # between creating the edition and it being published
367
- @ed = FactoryGirl.create(:travel_advice_edition, :country_slug => 'aruba')
368
- end
369
- end
370
-
371
- should "be updated to published time when edition is published" do
372
- @ed.change_description = "Did some stuff"
373
- @ed.publish!
374
- assert_equal @ed.published_at, @ed.reviewed_at
375
- end
376
-
377
- should "be set to the previous version's reviewed_at when a minor update is published" do
378
- @ed.minor_update = true
379
- @ed.publish!
380
- assert_equal @published.reviewed_at, @ed.reviewed_at
381
- end
382
-
383
- should "be able to be updated without affecting other dates" do
384
- published_at = @ed.published_at
385
- Timecop.freeze(1.day.from_now) do
386
- @ed.reviewed_at = Time.zone.now
387
- assert_equal published_at, @ed.published_at
388
- end
389
- end
390
-
391
- should "be able to update reviewed_at on a published edition" do
392
- @ed.minor_update = true
393
- @ed.publish!
394
- Timecop.freeze(1.day.from_now) do
395
- new_time = Time.zone.now
396
- @ed.reviewed_at = new_time
397
- @ed.save!
398
- assert_equal new_time.utc.to_i, @ed.reviewed_at.to_i
399
- end
400
- end
401
- end
402
-
403
- context "indexable content" do
404
- setup do
405
- @edition = FactoryGirl.build(:travel_advice_edition)
406
- end
407
-
408
- should "return summary and all part titles and bodies" do
409
- @edition.summary = "The Summary"
410
- @edition.parts << Part.new(:title => "Part One", :body => "Some text")
411
- @edition.parts << Part.new(:title => "More info", :body => "Some more information")
412
- assert_equal "The Summary Part One Some text More info Some more information", @edition.indexable_content
413
- end
414
-
415
- should "convert govspeak to plain text" do
416
- @edition.summary = "## The Summary"
417
- @edition.parts << Part.new(:title => "Part One", :body => "* Some text")
418
- assert_equal "The Summary Part One Some text", @edition.indexable_content
419
- end
420
- end
421
-
422
- context "actions" do
423
- setup do
424
- @user = FactoryGirl.create(:user)
425
- @old = FactoryGirl.create(:archived_travel_advice_edition, :country_slug => 'foo')
426
- @edition = FactoryGirl.create(:draft_travel_advice_edition, :country_slug => 'foo')
427
- end
428
-
429
- should "not have any actions by default" do
430
- assert_equal 0, @edition.actions.size
431
- end
432
-
433
- should "add a 'create' action" do
434
- @edition.build_action_as(@user, Action::CREATE)
435
- assert_equal 1, @edition.actions.size
436
- assert_equal Action::CREATE, @edition.actions.first.request_type
437
- assert_equal @user, @edition.actions.first.requester
438
- end
439
-
440
- should "add a 'new' action with a comment" do
441
- @edition.build_action_as(@user, Action::NEW_VERSION, "a comment for the new version")
442
- assert_equal 1, @edition.actions.size
443
- assert_equal "a comment for the new version", @edition.actions.first.comment
444
- end
445
-
446
- context "publish_as" do
447
- should "add a 'publish' action with change_description as comment on publish" do
448
- @edition.change_description = "## My hovercraft is full of eels!"
449
- @edition.publish_as(@user)
450
- @edition.reload
451
- assert_equal 1, @edition.actions.size
452
- action = @edition.actions.last
453
- assert_equal Action::PUBLISH, action.request_type
454
- assert_equal @user, action.requester
455
- assert_equal "My hovercraft is full of eels!", action.comment
456
- end
457
-
458
- should "add a 'publish' action with 'Minor update' as comment on publish of a minor_update" do
459
- @edition.minor_update = true
460
- @edition.publish_as(@user)
461
- @edition.reload
462
- assert_equal 1, @edition.actions.size
463
- action = @edition.actions.last
464
- assert_equal Action::PUBLISH, action.request_type
465
- assert_equal "Minor update", action.comment
466
- end
467
- end
468
- end
469
- end