govuk_content_models 24.2.0 → 25.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
@@ -1,3 +1,8 @@
1
+ ## 25.0.0
2
+
3
+ - Removes the `alternative_title` field from the `Edition` class.
4
+ - Adds methods to return major updates for an `Edition`.
5
+
1
6
  ## 24.2.0
2
7
 
3
8
  - Adds the `public_timestamp` and `latest_change_note` fields to the `Artefact`
@@ -17,7 +17,6 @@ class Edition
17
17
  field :created_at, type: DateTime, default: lambda { Time.zone.now }
18
18
  field :publish_at, type: DateTime
19
19
  field :overview, type: String
20
- field :alternative_title, type: String
21
20
  field :slug, type: String
22
21
  field :department, type: String
23
22
  field :rejected_count, type: Integer, default: 0
@@ -49,6 +48,7 @@ class Edition
49
48
  where(:assigned_to_id.exists => false)
50
49
  end
51
50
  }
51
+ scope :major_updates, lambda { where(major_change: true) }
52
52
 
53
53
  validates :title, presence: true
54
54
  validates :version_number, presence: true, uniqueness: {scope: :panopticon_id}
@@ -110,6 +110,28 @@ class Edition
110
110
  !scheduled_for_publishing? && subsequent_siblings.in_progress.empty?
111
111
  end
112
112
 
113
+ def major_updates_in_series
114
+ history.published.major_updates
115
+ end
116
+
117
+ def latest_major_update
118
+ major_updates_in_series.first
119
+ end
120
+
121
+ def latest_change_note
122
+ if latest_major_update.present?
123
+ latest_major_update.change_note
124
+ end
125
+ end
126
+
127
+ def public_updated_at
128
+ if latest_major_update.present?
129
+ latest_major_update.updated_at
130
+ elsif (first_published_edition = series.published.order(version_number: "asc").first)
131
+ first_published_edition.updated_at
132
+ end
133
+ end
134
+
113
135
  def meta_data
114
136
  PublicationMetadata.new self
115
137
  end
@@ -125,9 +147,9 @@ class Edition
125
147
 
126
148
  def indexable_content_without_parts
127
149
  if respond_to?(:body)
128
- "#{alternative_title} #{Govspeak::Document.new(body).to_text}".strip
150
+ "#{Govspeak::Document.new(body).to_text}".strip
129
151
  else
130
- alternative_title
152
+ ""
131
153
  end
132
154
  end
133
155
 
@@ -162,7 +184,6 @@ class Edition
162
184
  real_fields_to_merge = fields_to_copy(edition_class) + [
163
185
  :panopticon_id,
164
186
  :overview,
165
- :alternative_title,
166
187
  :slug,
167
188
  :department,
168
189
  :browse_pages,
@@ -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 = "24.2.0"
3
+ VERSION = "25.0.0"
4
4
  end
@@ -137,12 +137,10 @@ class EditionTest < ActiveSupport::TestCase
137
137
  panopticon_id: @artefact.id,
138
138
  version_number: 1,
139
139
  department: "Test dept",
140
- overview: "I am a test overview",
141
- alternative_title: "Alternative test title")
140
+ overview: "I am a test overview")
142
141
  clone_edition = edition.build_clone
143
142
  assert_equal clone_edition.department, "Test dept"
144
143
  assert_equal clone_edition.overview, "I am a test overview"
145
- assert_equal clone_edition.alternative_title, "Alternative test title"
146
144
  assert_equal clone_edition.version_number, 2
147
145
  end
148
146
 
@@ -194,7 +192,6 @@ class EditionTest < ActiveSupport::TestCase
194
192
  version_number: 1,
195
193
  department: "Test dept",
196
194
  overview: "I am a test overview",
197
- alternative_title: "Alternative test title",
198
195
  video_url: "http://www.youtube.com/watch?v=dQw4w9WgXcQ"
199
196
  )
200
197
  new_edition = edition.build_clone AnswerEdition
@@ -205,7 +202,6 @@ class EditionTest < ActiveSupport::TestCase
205
202
  assert_equal new_edition.state, "draft"
206
203
  assert_equal new_edition.department, "Test dept"
207
204
  assert_equal new_edition.overview, "I am a test overview"
208
- assert_equal new_edition.alternative_title, "Alternative test title"
209
205
  assert_equal new_edition.whole_body, edition.whole_body
210
206
  end
211
207
 
@@ -216,8 +212,7 @@ class EditionTest < ActiveSupport::TestCase
216
212
  panopticon_id: @artefact.id,
217
213
  version_number: 1,
218
214
  department: "Test dept",
219
- overview: "I am a test overview",
220
- alternative_title: "Alternative test title"
215
+ overview: "I am a test overview"
221
216
  )
222
217
  new_edition = edition.build_clone AnswerEdition
223
218
 
@@ -227,7 +222,6 @@ class EditionTest < ActiveSupport::TestCase
227
222
  assert_equal new_edition.state, "draft"
228
223
  assert_equal new_edition.department, "Test dept"
229
224
  assert_equal new_edition.overview, "I am a test overview"
230
- assert_equal new_edition.alternative_title, "Alternative test title"
231
225
  assert_equal new_edition.whole_body, edition.whole_body
232
226
  end
233
227
 
@@ -239,7 +233,6 @@ class EditionTest < ActiveSupport::TestCase
239
233
  version_number: 1,
240
234
  department: "Test dept",
241
235
  overview: "I am a test overview",
242
- alternative_title: "Alternative test title",
243
236
  more_information: "More information",
244
237
  alternate_methods: "Alternate methods"
245
238
  )
@@ -251,7 +244,6 @@ class EditionTest < ActiveSupport::TestCase
251
244
  assert_equal new_edition.state, "draft"
252
245
  assert_equal new_edition.department, "Test dept"
253
246
  assert_equal new_edition.overview, "I am a test overview"
254
- assert_equal new_edition.alternative_title, "Alternative test title"
255
247
  assert_equal new_edition.whole_body, edition.whole_body
256
248
  end
257
249
 
@@ -263,7 +255,6 @@ class EditionTest < ActiveSupport::TestCase
263
255
  version_number: 1,
264
256
  department: "Test dept",
265
257
  overview: "I am a test overview",
266
- alternative_title: "Alternative test title",
267
258
  body: "Test body"
268
259
  )
269
260
  new_edition = edition.build_clone TransactionEdition
@@ -274,7 +265,6 @@ class EditionTest < ActiveSupport::TestCase
274
265
  assert_equal new_edition.state, "draft"
275
266
  assert_equal new_edition.department, "Test dept"
276
267
  assert_equal new_edition.overview, "I am a test overview"
277
- assert_equal new_edition.alternative_title, "Alternative test title"
278
268
  assert_equal new_edition.more_information, "Test body"
279
269
  end
280
270
 
@@ -286,7 +276,6 @@ class EditionTest < ActiveSupport::TestCase
286
276
  version_number: 1,
287
277
  department: "Test dept",
288
278
  overview: "I am a test overview",
289
- alternative_title: "Alternative test title",
290
279
  video_url: "http://www.youtube.com/watch?v=dQw4w9WgXcQ"
291
280
  )
292
281
  new_edition = edition.build_clone TransactionEdition
@@ -297,7 +286,6 @@ class EditionTest < ActiveSupport::TestCase
297
286
  assert_equal new_edition.state, "draft"
298
287
  assert_equal new_edition.department, "Test dept"
299
288
  assert_equal new_edition.overview, "I am a test overview"
300
- assert_equal new_edition.alternative_title, "Alternative test title"
301
289
  assert_equal new_edition.more_information, edition.whole_body
302
290
  end
303
291
 
@@ -309,7 +297,6 @@ class EditionTest < ActiveSupport::TestCase
309
297
  version_number: 1,
310
298
  department: "Test dept",
311
299
  overview: "I am a test overview",
312
- alternative_title: "Alternative test title"
313
300
  )
314
301
  new_edition = edition.build_clone TransactionEdition
315
302
 
@@ -319,7 +306,6 @@ class EditionTest < ActiveSupport::TestCase
319
306
  assert_equal new_edition.state, "draft"
320
307
  assert_equal new_edition.department, "Test dept"
321
308
  assert_equal new_edition.overview, "I am a test overview"
322
- assert_equal new_edition.alternative_title, "Alternative test title"
323
309
  assert_equal new_edition.more_information, edition.whole_body
324
310
  end
325
311
 
@@ -331,7 +317,6 @@ class EditionTest < ActiveSupport::TestCase
331
317
  version_number: 1,
332
318
  department: "Test dept",
333
319
  overview: "I am a test overview",
334
- alternative_title: "Alternative test title"
335
320
  )
336
321
  new_edition = edition.build_clone GuideEdition
337
322
 
@@ -341,7 +326,6 @@ class EditionTest < ActiveSupport::TestCase
341
326
  assert_equal new_edition.state, "draft"
342
327
  assert_equal new_edition.department, "Test dept"
343
328
  assert_equal new_edition.overview, "I am a test overview"
344
- assert_equal new_edition.alternative_title, "Alternative test title"
345
329
  end
346
330
 
347
331
  test "Cloning between types with parts" do
@@ -998,10 +982,10 @@ class EditionTest < ActiveSupport::TestCase
998
982
  end
999
983
 
1000
984
  context "for a single part thing" do
1001
- should "have the normalised content of that part" do
1002
- edition = FactoryGirl.create(:guide_edition, :state => 'ready', :title => 'one part thing', :alternative_title => 'alternative one part thing', panopticon_id: FactoryGirl.create(:artefact).id)
985
+ should "have an empty string for an edition with no body" do
986
+ edition = FactoryGirl.create(:guide_edition, :state => 'ready', :title => 'one part thing', panopticon_id: FactoryGirl.create(:artefact).id)
1003
987
  edition.publish
1004
- assert_equal "alternative one part thing", edition.indexable_content
988
+ assert_equal "", edition.indexable_content
1005
989
  end
1006
990
  end
1007
991
 
@@ -1091,4 +1075,67 @@ class EditionTest < ActiveSupport::TestCase
1091
1075
  assert_equal edition.browse_pages, new_edition.browse_pages
1092
1076
  end
1093
1077
  end
1078
+
1079
+ context "#latest_major_update" do
1080
+ should 'return the most recent published edition with a major change' do
1081
+ edition1 = FactoryGirl.create(:answer_edition, major_change: true,
1082
+ change_note: 'published',
1083
+ state: 'published',
1084
+ version_number: 1)
1085
+ edition2 = edition1.build_clone
1086
+
1087
+ edition2.update_attributes!(major_change: true, change_note: 'changed', state: 'published')
1088
+ edition1.update_attributes!(state: 'archived')
1089
+
1090
+ edition3 = edition2.build_clone
1091
+
1092
+ assert_equal edition2.id, edition3.latest_major_update.id
1093
+ end
1094
+ end
1095
+
1096
+ context "#latest_change_note" do
1097
+ should 'return the change note of the latest major update' do
1098
+ edition1 = FactoryGirl.create(:answer_edition, major_change: true,
1099
+ change_note: 'a change note',
1100
+ state: 'published')
1101
+ edition2 = edition1.build_clone
1102
+
1103
+ assert_equal 'a change note', edition2.latest_change_note
1104
+ end
1105
+
1106
+ should 'return nil if there is no major update in the edition series' do
1107
+ edition1 = FactoryGirl.create(:answer_edition, major_change: false,
1108
+ state: 'published')
1109
+ assert_equal nil, edition1.latest_change_note
1110
+ end
1111
+ end
1112
+
1113
+ context '#public_updated_at' do
1114
+ should 'return the updated_at timestamp of the latest major update' do
1115
+ edition1 = FactoryGirl.create(:answer_edition, major_change: true,
1116
+ change_note: 'a change note',
1117
+ updated_at: 1.minute.ago,
1118
+ state: 'published')
1119
+ edition2 = edition1.build_clone
1120
+
1121
+ assert_equal edition1.updated_at, edition2.public_updated_at
1122
+ end
1123
+
1124
+ should 'return the timestamp of the first published edition when there are no major updates' do
1125
+ edition1 = FactoryGirl.create(:answer_edition, major_change: false,
1126
+ updated_at: 1.minute.ago,
1127
+ state: 'published')
1128
+ edition2 = edition1.build_clone
1129
+
1130
+ assert_equal edition1.updated_at, edition2.public_updated_at
1131
+ end
1132
+
1133
+ should 'return nil if there are no major updates and no published editions' do
1134
+ edition1 = FactoryGirl.create(:answer_edition, major_change: false,
1135
+ updated_at: 1.minute.ago,
1136
+ state: 'draft')
1137
+
1138
+ assert_equal nil, edition1.public_updated_at
1139
+ end
1140
+ end
1094
1141
  end
@@ -27,7 +27,7 @@ class WorkflowTest < ActiveSupport::TestCase
27
27
  user = User.create(name: "Ben")
28
28
  other_user = User.create(name: "James")
29
29
 
30
- guide = user.create_edition(:guide, panopticon_id: @artefact.id, overview: "My Overview", title: "My Title", slug: "my-title", alternative_title: "My Other Title")
30
+ guide = user.create_edition(:guide, panopticon_id: @artefact.id, overview: "My Overview", title: "My Title", slug: "my-title")
31
31
  edition = guide
32
32
 
33
33
  request_review(user, edition)
@@ -141,7 +141,7 @@ class WorkflowTest < ActiveSupport::TestCase
141
141
  user = User.create(name: "Ben")
142
142
  other_user = User.create(name: "James")
143
143
 
144
- edition = user.create_edition(:guide, panopticon_id: @artefact.id, overview: "My Overview", title: "My Title", slug: "my-title", alternative_title: "My Other Title")
144
+ edition = user.create_edition(:guide, panopticon_id: @artefact.id, overview: "My Overview", title: "My Title", slug: "my-title")
145
145
 
146
146
  request_review(user, edition)
147
147
  approve_review(other_user, edition)
@@ -158,7 +158,7 @@ class WorkflowTest < ActiveSupport::TestCase
158
158
  user = User.create(name: "Ben")
159
159
  other_user = User.create(name: "James")
160
160
 
161
- guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title", alternative_title: "My Other Title")
161
+ guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title")
162
162
  edition = guide
163
163
 
164
164
  request_review(user, edition)
@@ -173,7 +173,7 @@ class WorkflowTest < ActiveSupport::TestCase
173
173
  user = User.create(name: "Ben")
174
174
  other_user = User.create(name: "James")
175
175
 
176
- guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title", alternative_title: "My Other Title")
176
+ guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title")
177
177
  edition = guide
178
178
 
179
179
  request_review(user, edition)
@@ -189,7 +189,7 @@ class WorkflowTest < ActiveSupport::TestCase
189
189
  user = User.create(name: "Ben")
190
190
  other_user = User.create(name: "James")
191
191
 
192
- guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title", alternative_title: "My Other Title")
192
+ guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title")
193
193
  edition = guide
194
194
 
195
195
  request_review(user, edition)
@@ -206,7 +206,7 @@ class WorkflowTest < ActiveSupport::TestCase
206
206
  other_user = User.create(name: "James")
207
207
  another_user = User.create(name: "Fiona")
208
208
 
209
- guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title", alternative_title: "My Other Title")
209
+ guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title")
210
210
  edition = guide
211
211
 
212
212
  request_review(user, edition)
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: 24.2.0
4
+ version: 25.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-11-21 00:00:00.000000000 Z
12
+ date: 2014-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
@@ -476,7 +476,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
476
476
  version: '0'
477
477
  segments:
478
478
  - 0
479
- hash: 950024458355486311
479
+ hash: -823528571067115172
480
480
  required_rubygems_version: !ruby/object:Gem::Requirement
481
481
  none: false
482
482
  requirements:
@@ -485,7 +485,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
485
485
  version: '0'
486
486
  segments:
487
487
  - 0
488
- hash: 950024458355486311
488
+ hash: -823528571067115172
489
489
  requirements: []
490
490
  rubyforge_project:
491
491
  rubygems_version: 1.8.23