govuk_content_models 26.1.0 → 26.2.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 +3 -0
- data/app/models/edition.rb +2 -1
- data/app/models/workflow.rb +4 -0
- data/app/validators/reviewer_validator.rb +20 -0
- data/lib/govuk_content_models/version.rb +1 -1
- data/test/models/edition_test.rb +9 -0
- data/test/models/workflow_test.rb +14 -1
- metadata +5 -4
data/CHANGELOG.md
CHANGED
data/app/models/edition.rb
CHANGED
|
@@ -26,6 +26,7 @@ class Edition
|
|
|
26
26
|
field :additional_topics, type: Array, default: []
|
|
27
27
|
|
|
28
28
|
field :assignee, type: String
|
|
29
|
+
field :reviewer, type: String
|
|
29
30
|
field :creator, type: String
|
|
30
31
|
field :publisher, type: String
|
|
31
32
|
field :archiver, type: String
|
|
@@ -56,7 +57,7 @@ class Edition
|
|
|
56
57
|
validates :panopticon_id, presence: true
|
|
57
58
|
validates_with SafeHtml
|
|
58
59
|
validates_with LinkValidator, on: :update
|
|
59
|
-
validates_with TopicValidator, BrowsePageValidator
|
|
60
|
+
validates_with TopicValidator, BrowsePageValidator, ReviewerValidator
|
|
60
61
|
validates_presence_of :change_note, if: :major_change
|
|
61
62
|
|
|
62
63
|
before_save :check_for_archived_artefact
|
data/app/models/workflow.rb
CHANGED
|
@@ -28,6 +28,10 @@ module Workflow
|
|
|
28
28
|
edition.publish_at = nil
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
before_transition on: [:approve_review, :request_amendments] do |edition, transition|
|
|
32
|
+
edition.reviewer = nil
|
|
33
|
+
end
|
|
34
|
+
|
|
31
35
|
after_transition on: :publish do |edition, transition|
|
|
32
36
|
edition.was_published
|
|
33
37
|
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class ReviewerValidator < ActiveModel::Validator
|
|
2
|
+
def validate(record)
|
|
3
|
+
if record.reviewer
|
|
4
|
+
validate_reviewer_in_review(record)
|
|
5
|
+
validate_reviewer_not_assignee(record)
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
def validate_reviewer_in_review(record)
|
|
11
|
+
unless record.in_review?
|
|
12
|
+
record.errors.add(:reviewer, "can only be set when in review")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
def validate_reviewer_not_assignee(record)
|
|
16
|
+
if record.assigned_to and record.reviewer == record.assigned_to.name
|
|
17
|
+
record.errors.add(:reviewer, "can't be the assignee")
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/test/models/edition_test.rb
CHANGED
|
@@ -131,6 +131,15 @@ class EditionTest < ActiveSupport::TestCase
|
|
|
131
131
|
end
|
|
132
132
|
end
|
|
133
133
|
|
|
134
|
+
test "reviewer cannot be the assignee" do
|
|
135
|
+
user = FactoryGirl.create(:user)
|
|
136
|
+
edition = Edition.new(title: "Edition", version_number: 1, panopticon_id: 123,
|
|
137
|
+
state: "in_review", review_requested_at: Time.zone.now, assigned_to: user)
|
|
138
|
+
edition.reviewer = user.name
|
|
139
|
+
refute edition.valid?
|
|
140
|
+
assert edition.errors.has_key?(:reviewer)
|
|
141
|
+
end
|
|
142
|
+
|
|
134
143
|
test "it should build a clone" do
|
|
135
144
|
edition = FactoryGirl.create(:guide_edition,
|
|
136
145
|
state: "published",
|
|
@@ -118,6 +118,14 @@ class WorkflowTest < ActiveSupport::TestCase
|
|
|
118
118
|
assert_in_delta Time.zone.now.to_f, guide.review_requested_at.to_f, 1.0
|
|
119
119
|
end
|
|
120
120
|
|
|
121
|
+
test "a guide not in review cannot have a reviewer" do
|
|
122
|
+
guide = template_guide
|
|
123
|
+
refute guide.in_review?
|
|
124
|
+
guide.reviewer = "Bob"
|
|
125
|
+
refute guide.valid?
|
|
126
|
+
assert guide.errors.has_key?(:reviewer)
|
|
127
|
+
end
|
|
128
|
+
|
|
121
129
|
test "guide workflow" do
|
|
122
130
|
user = User.create(name: "Ben")
|
|
123
131
|
other_user = User.create(name: "James")
|
|
@@ -210,9 +218,14 @@ class WorkflowTest < ActiveSupport::TestCase
|
|
|
210
218
|
edition = guide
|
|
211
219
|
|
|
212
220
|
request_review(user, edition)
|
|
221
|
+
|
|
222
|
+
edition.reviewer = other_user
|
|
223
|
+
edition.save!
|
|
224
|
+
|
|
213
225
|
approve_review(other_user, edition)
|
|
214
|
-
|
|
226
|
+
assert_nil edition.reviewer
|
|
215
227
|
|
|
228
|
+
request_amendments(other_user, edition)
|
|
216
229
|
assert_equal "More amendments are required", edition.actions.last.comment
|
|
217
230
|
end
|
|
218
231
|
|
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.
|
|
4
|
+
version: 26.2.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-
|
|
12
|
+
date: 2014-12-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: bson_ext
|
|
@@ -378,6 +378,7 @@ files:
|
|
|
378
378
|
- app/traits/taggable.rb
|
|
379
379
|
- app/validators/browse_page_validator.rb
|
|
380
380
|
- app/validators/link_validator.rb
|
|
381
|
+
- app/validators/reviewer_validator.rb
|
|
381
382
|
- app/validators/safe_html.rb
|
|
382
383
|
- app/validators/slug_validator.rb
|
|
383
384
|
- app/validators/tag_id_validator.rb
|
|
@@ -474,7 +475,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
474
475
|
version: '0'
|
|
475
476
|
segments:
|
|
476
477
|
- 0
|
|
477
|
-
hash:
|
|
478
|
+
hash: -724937649554228680
|
|
478
479
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
479
480
|
none: false
|
|
480
481
|
requirements:
|
|
@@ -483,7 +484,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
483
484
|
version: '0'
|
|
484
485
|
segments:
|
|
485
486
|
- 0
|
|
486
|
-
hash:
|
|
487
|
+
hash: -724937649554228680
|
|
487
488
|
requirements: []
|
|
488
489
|
rubyforge_project:
|
|
489
490
|
rubygems_version: 1.8.23
|