govuk_content_models 26.2.0 → 27.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 27.0.0
2
+
3
+ - Corrected to return public timestamp of first edition when no major changes
4
+ - Adds a unique index on the `uid` field for a `User`. (breaking change)
5
+
6
+ ## 26.3.0 (yanked)
7
+ - Corrected to return public timestamp of first edition when no major changes
8
+ - Yanked due to the unintended inclusion of a breaking change.
9
+
1
10
  ## 26.2.0
2
11
  - Adds `reviewer` `String` field to `Edition` class.
3
12
 
@@ -42,6 +42,7 @@ class Edition
42
42
  state_machine.states.map(&:name).each do |state|
43
43
  scope state, where(state: state)
44
44
  end
45
+ scope :archived_or_published, where(:state.in => ["archived", "published"])
45
46
  scope :in_progress, where(:state.nin => ["archived", "published"])
46
47
  scope :assigned_to, lambda { |user|
47
48
  if user
@@ -66,6 +67,7 @@ class Edition
66
67
  index "assigned_to_id"
67
68
  index [["panopticon_id", Mongo::ASCENDING], ["version_number", Mongo::ASCENDING]], :unique => true
68
69
  index "state"
70
+ index "updated_at"
69
71
 
70
72
  class << self; attr_accessor :fields_to_clone end
71
73
  @fields_to_clone = []
@@ -129,11 +131,19 @@ class Edition
129
131
  def public_updated_at
130
132
  if latest_major_update.present?
131
133
  latest_major_update.updated_at
132
- elsif (first_published_edition = series.published.order(version_number: "asc").first)
133
- first_published_edition.updated_at
134
+ elsif has_ever_been_published?
135
+ first_edition_of_published.updated_at
134
136
  end
135
137
  end
136
138
 
139
+ def has_ever_been_published?
140
+ series.map(&:state).include?('published')
141
+ end
142
+
143
+ def first_edition_of_published
144
+ series.archived_or_published.order(version_number: "asc").first
145
+ end
146
+
137
147
  def meta_data
138
148
  PublicationMetadata.new self
139
149
  end
data/app/models/user.rb CHANGED
@@ -23,6 +23,7 @@ class User
23
23
  field "organisation_slug", type: String
24
24
  field "disabled", type: Boolean, default: false
25
25
 
26
+ index "uid", unique: true
26
27
  index "disabled"
27
28
 
28
29
  GOVSPEAK_FIELDS = []
@@ -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 = "26.2.0"
3
+ VERSION = "27.0.0"
4
4
  end
@@ -599,8 +599,8 @@ class EditionTest < ActiveSupport::TestCase
599
599
  end
600
600
 
601
601
  test "should be assigned to the last assigned recipient" do
602
- alice = User.create(name: "alice")
603
- bob = User.create(name: "bob")
602
+ alice = FactoryGirl.create(:user, name: "alice")
603
+ bob = FactoryGirl.create(:user, name: "bob")
604
604
  edition = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id, state: "ready")
605
605
  alice.assign(edition, bob)
606
606
  assert_equal bob, edition.assigned_to
@@ -1132,11 +1132,17 @@ class EditionTest < ActiveSupport::TestCase
1132
1132
 
1133
1133
  should 'return the timestamp of the first published edition when there are no major updates' do
1134
1134
  edition1 = FactoryGirl.create(:answer_edition, major_change: false,
1135
- updated_at: 1.minute.ago,
1135
+ updated_at: 2.minute.ago,
1136
1136
  state: 'published')
1137
1137
  edition2 = edition1.build_clone
1138
+ Timecop.freeze(1.minute.ago) do
1139
+ #added to allow significant amount of time between edition updated_at values
1140
+ edition2.update_attributes!(state: 'published', major_change: false)
1141
+ end
1142
+ edition1.update_attributes!(state: 'archived', major_change: false)
1138
1143
 
1139
1144
  assert_equal edition1.updated_at, edition2.public_updated_at
1145
+ assert_not_equal edition2.updated_at, edition2.public_updated_at
1140
1146
  end
1141
1147
 
1142
1148
  should 'return nil if there are no major updates and no published editions' do
@@ -1147,4 +1153,38 @@ class EditionTest < ActiveSupport::TestCase
1147
1153
  assert_equal nil, edition1.public_updated_at
1148
1154
  end
1149
1155
  end
1156
+
1157
+ context '#has_ever_been_published?' do
1158
+ should 'return true if any edition has a published state' do
1159
+ edition1 = FactoryGirl.create(:answer_edition, major_change: false,
1160
+ updated_at: 2.minute.ago,
1161
+ state: 'published')
1162
+ edition2 = edition1.build_clone
1163
+ edition2.update_attributes!(state: 'archived', major_change: false)
1164
+ edition4 = FactoryGirl.create(:answer_edition, major_change: false,
1165
+ updated_at: 2.minute.ago,
1166
+ state: 'draft')
1167
+
1168
+ assert_equal true, edition1.has_ever_been_published?
1169
+ assert_equal true, edition2.has_ever_been_published?
1170
+ assert_equal false, edition4.has_ever_been_published?
1171
+ end
1172
+ end
1173
+
1174
+ context '#first_edition_of_published' do
1175
+ should 'return the first edition of a series that has at least one edition state published' do
1176
+ edition1 = FactoryGirl.create(:answer_edition, major_change: false,
1177
+ updated_at: 2.minute.ago,
1178
+ state: 'published')
1179
+ edition2 = edition1.build_clone
1180
+ edition1.update_attributes!(state: 'archived', major_change: false)
1181
+ edition2.update_attributes!(state: 'published', major_change: false)
1182
+ edition3 = edition2.build_clone
1183
+ edition3.update_attributes!(state: 'archived', major_change: false)
1184
+
1185
+ assert_equal edition1, edition1.first_edition_of_published
1186
+ assert_equal edition1, edition2.first_edition_of_published
1187
+ assert_equal edition1, edition3.first_edition_of_published
1188
+ end
1189
+ end
1150
1190
  end
@@ -112,8 +112,8 @@ class UserTest < ActiveSupport::TestCase
112
112
  end
113
113
 
114
114
  test "Edition becomes assigned to user when user is assigned an edition" do
115
- boss_user = User.create(:name => "Mat")
116
- worker_user = User.create(:name => "Grunt")
115
+ boss_user = FactoryGirl.create(:user, :name => "Mat")
116
+ worker_user = FactoryGirl.create(:user, :name => "Grunt")
117
117
 
118
118
  publication = boss_user.create_edition(:answer, title: "test answer", slug: "test", panopticon_id: @artefact.id)
119
119
  boss_user.assign(publication, worker_user)
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: 26.2.0
4
+ version: 27.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-12-05 00:00:00.000000000 Z
12
+ date: 2014-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bson_ext
@@ -475,7 +475,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
475
475
  version: '0'
476
476
  segments:
477
477
  - 0
478
- hash: -724937649554228680
478
+ hash: 1210122604192578351
479
479
  required_rubygems_version: !ruby/object:Gem::Requirement
480
480
  none: false
481
481
  requirements:
@@ -484,7 +484,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
484
484
  version: '0'
485
485
  segments:
486
486
  - 0
487
- hash: -724937649554228680
487
+ hash: 1210122604192578351
488
488
  requirements: []
489
489
  rubyforge_project:
490
490
  rubygems_version: 1.8.23