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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/app/traits/attachable.rb +2 -2
- data/govuk_content_models.gemspec +1 -2
- data/lib/govuk_content_models/version.rb +1 -1
- metadata +3 -83
- data/test/fixtures/uploads/image.jpg +0 -0
- data/test/models/action_test.rb +0 -13
- data/test/models/artefact_action_test.rb +0 -130
- data/test/models/artefact_external_link_test.rb +0 -32
- data/test/models/artefact_test.rb +0 -482
- data/test/models/business_support/business_size_test.rb +0 -25
- data/test/models/business_support/business_type_test.rb +0 -25
- data/test/models/business_support/location_test.rb +0 -25
- data/test/models/business_support/purpose_test.rb +0 -29
- data/test/models/business_support/sector_test.rb +0 -25
- data/test/models/business_support/stage_test.rb +0 -25
- data/test/models/business_support/support_type_test.rb +0 -25
- data/test/models/business_support_edition_test.rb +0 -282
- data/test/models/campaign_edition_test.rb +0 -91
- data/test/models/completed_transaction_edition_test.rb +0 -56
- data/test/models/downtime_test.rb +0 -93
- data/test/models/edition_scheduled_for_publishing_test.rb +0 -91
- data/test/models/edition_test.rb +0 -1185
- data/test/models/help_page_edition_test.rb +0 -43
- data/test/models/licence_edition_test.rb +0 -105
- data/test/models/local_service_test.rb +0 -6
- data/test/models/local_transaction_edition_test.rb +0 -37
- data/test/models/overview_dashboard_test.rb +0 -46
- data/test/models/parted_test.rb +0 -26
- data/test/models/prerendered_entity_tests.rb +0 -46
- data/test/models/rendered_manual_test.rb +0 -10
- data/test/models/simple_smart_answer_edition_test.rb +0 -211
- data/test/models/simple_smart_answer_node_test.rb +0 -134
- data/test/models/simple_smart_answer_option_test.rb +0 -97
- data/test/models/time_zone_test.rb +0 -48
- data/test/models/transaction_edition_test.rb +0 -36
- data/test/models/travel_advice_edition_test.rb +0 -469
- data/test/models/user_test.rb +0 -155
- data/test/models/video_edition_test.rb +0 -64
- data/test/models/workflow_test.rb +0 -498
- data/test/test_helper.rb +0 -61
- data/test/traits/attachable_test.rb +0 -244
- data/test/validators/link_validator_test.rb +0 -86
- data/test/validators/safe_html_validator_test.rb +0 -83
- data/test/validators/slug_validator_test.rb +0 -109
data/test/models/user_test.rb
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
require "gds-sso/lint/user_test"
|
3
|
-
|
4
|
-
class GDS::SSO::Lint::UserTest
|
5
|
-
def user_class
|
6
|
-
::User
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
class UserTest < ActiveSupport::TestCase
|
11
|
-
def setup
|
12
|
-
@artefact = FactoryGirl.create(:artefact)
|
13
|
-
end
|
14
|
-
|
15
|
-
test "should convert to string using name by preference" do
|
16
|
-
user = User.new(name: "Bob", email: "user@example.com")
|
17
|
-
assert_equal "Bob", user.to_s
|
18
|
-
end
|
19
|
-
|
20
|
-
test "should convert to string using email if name if missing" do
|
21
|
-
user = User.new(email: "user@example.com")
|
22
|
-
assert_equal "user@example.com", user.to_s
|
23
|
-
end
|
24
|
-
|
25
|
-
test "should convert to empty string if name and email are missing" do
|
26
|
-
user = User.new
|
27
|
-
assert_equal "", user.to_s
|
28
|
-
end
|
29
|
-
|
30
|
-
test "should return enabled users" do
|
31
|
-
disabled = FactoryGirl.create(:user, disabled: true)
|
32
|
-
|
33
|
-
FactoryGirl.create(:user).unset(:disabled)
|
34
|
-
FactoryGirl.create(:user, disabled: false)
|
35
|
-
FactoryGirl.create(:user, disabled: nil)
|
36
|
-
|
37
|
-
assert_equal 3, User.enabled.count
|
38
|
-
refute User.enabled.include? disabled
|
39
|
-
end
|
40
|
-
|
41
|
-
test "should create new user with oauth params" do
|
42
|
-
auth_hash = {
|
43
|
-
"uid" => "1234abcd",
|
44
|
-
"info" => {
|
45
|
-
"uid" => "1234abcd",
|
46
|
-
"email" => "user@example.com",
|
47
|
-
"name" => "Luther Blisset"
|
48
|
-
},
|
49
|
-
"extra" => {
|
50
|
-
"user" => {
|
51
|
-
"permissions" => ["signin"],
|
52
|
-
"disabled" => false,
|
53
|
-
}
|
54
|
-
}
|
55
|
-
}
|
56
|
-
user = User.find_for_gds_oauth(auth_hash).reload
|
57
|
-
assert_equal "1234abcd", user.uid
|
58
|
-
assert_equal "user@example.com", user.email
|
59
|
-
assert_equal "Luther Blisset", user.name
|
60
|
-
assert_equal(["signin"], user.permissions)
|
61
|
-
refute user.disabled?
|
62
|
-
end
|
63
|
-
|
64
|
-
test "should find and update the user with oauth params" do
|
65
|
-
attributes = {uid: "1234abcd", name: "Old", email: "old@m.com",
|
66
|
-
permissions: ["everything"]}
|
67
|
-
User.create!(attributes)
|
68
|
-
auth_hash = {
|
69
|
-
"uid" => "1234abcd",
|
70
|
-
"info" => {
|
71
|
-
"email" => "new@m.com",
|
72
|
-
"name" => "New"
|
73
|
-
},
|
74
|
-
"extra" => {
|
75
|
-
"user" => {
|
76
|
-
"permissions" => [],
|
77
|
-
"disabled" => true
|
78
|
-
}
|
79
|
-
}
|
80
|
-
}
|
81
|
-
user = User.find_for_gds_oauth(auth_hash).reload
|
82
|
-
assert_equal "1234abcd", user.uid
|
83
|
-
assert_equal "new@m.com", user.email
|
84
|
-
assert_equal "New", user.name
|
85
|
-
assert_equal([], user.permissions)
|
86
|
-
assert user.disabled?
|
87
|
-
end
|
88
|
-
|
89
|
-
test "should create insecure gravatar URL" do
|
90
|
-
user = User.new(email: "User@example.com")
|
91
|
-
expected = "http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af"
|
92
|
-
assert_equal expected, user.gravatar_url
|
93
|
-
end
|
94
|
-
|
95
|
-
test "should create secure gravatar URL" do
|
96
|
-
user = User.new(email: "user@example.com")
|
97
|
-
expected = "https://secure.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af"
|
98
|
-
assert_equal expected, user.gravatar_url(ssl: true)
|
99
|
-
end
|
100
|
-
|
101
|
-
test "should add escaped s parameter if supplied" do
|
102
|
-
user = User.new(email: "user@example.com")
|
103
|
-
expected = "http://www.gravatar.com/avatar/b58996c504c5638798eb6b511e6f49af?s=foo+bar"
|
104
|
-
assert_equal expected, user.gravatar_url(s: "foo bar")
|
105
|
-
end
|
106
|
-
|
107
|
-
test "creating a transaction with the initial details creates a valid transaction" do
|
108
|
-
user = User.create(:name => "bob")
|
109
|
-
trans = user.create_edition(:transaction, title: "test", slug: "test", panopticon_id: @artefact.id)
|
110
|
-
assert trans.valid?
|
111
|
-
end
|
112
|
-
|
113
|
-
test "user can't okay a publication they've sent for review" do
|
114
|
-
user = User.create(:name => "bob")
|
115
|
-
|
116
|
-
trans = user.create_edition(:transaction, title: "test answer", slug: "test", panopticon_id: @artefact.id)
|
117
|
-
request_review(user, trans)
|
118
|
-
refute approve_review(user, trans)
|
119
|
-
end
|
120
|
-
|
121
|
-
test "Edition becomes assigned to user when user is assigned an edition" do
|
122
|
-
boss_user = FactoryGirl.create(:user, :name => "Mat")
|
123
|
-
worker_user = FactoryGirl.create(:user, :name => "Grunt")
|
124
|
-
|
125
|
-
publication = boss_user.create_edition(:answer, title: "test answer", slug: "test", panopticon_id: @artefact.id)
|
126
|
-
boss_user.assign(publication, worker_user)
|
127
|
-
publication.save
|
128
|
-
publication.reload
|
129
|
-
|
130
|
-
assert_equal(worker_user, publication.assigned_to)
|
131
|
-
end
|
132
|
-
|
133
|
-
test "Edition can be unassigned" do
|
134
|
-
boss_user = FactoryGirl.create(:user, :name => "Mat")
|
135
|
-
worker_user = FactoryGirl.create(:user, :name => "Grunt")
|
136
|
-
|
137
|
-
publication = boss_user.create_edition(:answer, title: "test answer", slug: "test", panopticon_id: @artefact.id)
|
138
|
-
boss_user.assign(publication, worker_user)
|
139
|
-
publication.save
|
140
|
-
publication.reload
|
141
|
-
|
142
|
-
assert_equal(worker_user, publication.assigned_to)
|
143
|
-
|
144
|
-
boss_user.unassign(publication)
|
145
|
-
publication.save
|
146
|
-
publication.reload
|
147
|
-
|
148
|
-
assert_nil publication.assigned_to
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
|
-
test "should default to a collection called 'users'" do
|
153
|
-
assert_equal "users", User.collection_name
|
154
|
-
end
|
155
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class VideoEditionTest < ActiveSupport::TestCase
|
4
|
-
setup do
|
5
|
-
@artefact = FactoryGirl.create(:artefact)
|
6
|
-
end
|
7
|
-
|
8
|
-
should "have correct extra fields" do
|
9
|
-
v = FactoryGirl.build(:video_edition, panopticon_id: @artefact.id)
|
10
|
-
v.video_url = "http://www.youtube.com/watch?v=qySFp3qnVmM"
|
11
|
-
v.video_summary = "Coke smoothie"
|
12
|
-
v.body = "Description of video"
|
13
|
-
v.caption_file_id = 'file-to-an-asset-of-the-caption-file'
|
14
|
-
v.save!
|
15
|
-
|
16
|
-
v = VideoEdition.first
|
17
|
-
assert_equal "http://www.youtube.com/watch?v=qySFp3qnVmM", v.video_url
|
18
|
-
assert_equal "Coke smoothie", v.video_summary
|
19
|
-
assert_equal "Description of video", v.body
|
20
|
-
assert_equal 'file-to-an-asset-of-the-caption-file', v.caption_file_id
|
21
|
-
end
|
22
|
-
|
23
|
-
should "give a friendly (legacy supporting) description of its format" do
|
24
|
-
video = VideoEdition.new
|
25
|
-
assert_equal "Video", video.format
|
26
|
-
end
|
27
|
-
|
28
|
-
context "whole_body" do
|
29
|
-
should "combine the video_summary, video_url and body" do
|
30
|
-
v = FactoryGirl.build(:video_edition,
|
31
|
-
:panopticon_id => @artefact.id,
|
32
|
-
:video_summary => "Coke smoothie",
|
33
|
-
:video_url => "http://www.youtube.com/watch?v=qySFp3qnVmM",
|
34
|
-
:body => "Make a smoothie from a whole can of coke")
|
35
|
-
expected = ["Coke smoothie", "http://www.youtube.com/watch?v=qySFp3qnVmM", "Make a smoothie from a whole can of coke"].join("\n\n")
|
36
|
-
assert_equal expected, v.whole_body
|
37
|
-
end
|
38
|
-
|
39
|
-
should "cope with a field being nil" do
|
40
|
-
v = FactoryGirl.build(:video_edition,
|
41
|
-
:panopticon_id => @artefact.id,
|
42
|
-
:video_summary => nil,
|
43
|
-
:video_url => "http://www.youtube.com/watch?v=qySFp3qnVmM",
|
44
|
-
:body => "Make a smoothie from a whole can of coke")
|
45
|
-
expected = ["", "http://www.youtube.com/watch?v=qySFp3qnVmM", "Make a smoothie from a whole can of coke"].join("\n\n")
|
46
|
-
assert_equal expected, v.whole_body
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
should "clone extra fields when cloning edition" do
|
51
|
-
video = FactoryGirl.create(:video_edition,
|
52
|
-
:panopticon_id => @artefact.id,
|
53
|
-
:state => "published",
|
54
|
-
:video_url => "http://www.youtube.com/watch?v=qySFp3qnVmM",
|
55
|
-
:video_summary => "Coke smoothie",
|
56
|
-
:body => "Description of video")
|
57
|
-
|
58
|
-
new_video = video.build_clone
|
59
|
-
|
60
|
-
assert_equal video.video_url, new_video.video_url
|
61
|
-
assert_equal video.video_summary, new_video.video_summary
|
62
|
-
assert_equal video.body, new_video.body
|
63
|
-
end
|
64
|
-
end
|
@@ -1,498 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
class WorkflowTest < ActiveSupport::TestCase
|
4
|
-
def setup
|
5
|
-
@artefact = FactoryGirl.create(:artefact)
|
6
|
-
end
|
7
|
-
|
8
|
-
def template_users
|
9
|
-
user = FactoryGirl.create(:user, name: "Bob")
|
10
|
-
other_user = FactoryGirl.create(:user, name: "James")
|
11
|
-
return user, other_user
|
12
|
-
end
|
13
|
-
|
14
|
-
def template_programme
|
15
|
-
p = ProgrammeEdition.new(slug:"childcare", title:"Children", panopticon_id: @artefact.id)
|
16
|
-
p.save
|
17
|
-
p
|
18
|
-
end
|
19
|
-
|
20
|
-
def template_guide
|
21
|
-
edition = FactoryGirl.create(:guide_edition, slug: "childcare", title: "One", panopticon_id: @artefact.id)
|
22
|
-
edition.save
|
23
|
-
edition
|
24
|
-
end
|
25
|
-
|
26
|
-
def publisher_and_guide
|
27
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
28
|
-
other_user = FactoryGirl.create(:user, name: "James")
|
29
|
-
|
30
|
-
guide = user.create_edition(:guide, panopticon_id: @artefact.id, overview: "My Overview", title: "My Title", slug: "my-title")
|
31
|
-
edition = guide
|
32
|
-
|
33
|
-
request_review(user, edition)
|
34
|
-
approve_review(other_user, edition)
|
35
|
-
send_fact_check(user, edition)
|
36
|
-
receive_fact_check(user, edition)
|
37
|
-
other_user.progress(edition, { request_type: :approve_fact_check, comment: "Looks good to me" })
|
38
|
-
user.progress(edition, { request_type: :publish, comment: "PUBLISHED!" })
|
39
|
-
return user, guide
|
40
|
-
end
|
41
|
-
|
42
|
-
def template_user_and_published_transaction
|
43
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
44
|
-
other_user = FactoryGirl.create(:user, name: "James")
|
45
|
-
|
46
|
-
transaction = user.create_edition(:transaction, title: "My title", slug: "my-title", panopticon_id: @artefact.id, need_to_know: "Credit card required")
|
47
|
-
transaction.save
|
48
|
-
|
49
|
-
request_review(user, transaction)
|
50
|
-
transaction.save
|
51
|
-
approve_review(other_user, transaction)
|
52
|
-
transaction.save
|
53
|
-
user.progress(transaction, { request_type: :publish, comment: "Let's go"})
|
54
|
-
transaction.save
|
55
|
-
return user, transaction
|
56
|
-
end
|
57
|
-
|
58
|
-
context "#status_text" do
|
59
|
-
should "return a capitalized text representation of the state" do
|
60
|
-
assert_equal 'Ready', FactoryGirl.build(:edition, state: 'ready').status_text
|
61
|
-
end
|
62
|
-
|
63
|
-
should "also return scheduled publishing time when the state is scheduled for publishing" do
|
64
|
-
edition = FactoryGirl.build(:edition, :scheduled_for_publishing)
|
65
|
-
expected_status_text = 'Scheduled for publishing on ' + edition.publish_at.strftime("%d/%m/%Y %H:%M")
|
66
|
-
|
67
|
-
assert_equal expected_status_text, edition.status_text
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "#locked_for_edit?" do
|
72
|
-
should "return true if edition is scheduled for publishing for published" do
|
73
|
-
assert FactoryGirl.build(:edition, :scheduled_for_publishing).locked_for_edits?
|
74
|
-
assert FactoryGirl.build(:edition, :published).locked_for_edits?
|
75
|
-
end
|
76
|
-
|
77
|
-
should "return false if in draft state" do
|
78
|
-
refute FactoryGirl.build(:edition, state: 'draft').locked_for_edits?
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
test "permits the creation of new editions" do
|
83
|
-
user, transaction = template_user_and_published_transaction
|
84
|
-
assert transaction.persisted?
|
85
|
-
assert transaction.published?
|
86
|
-
|
87
|
-
reloaded_transaction = TransactionEdition.find(transaction.id)
|
88
|
-
new_edition = user.new_version(reloaded_transaction)
|
89
|
-
|
90
|
-
assert new_edition.save
|
91
|
-
end
|
92
|
-
|
93
|
-
test "should allow creation of new editions from GuideEdition to AnswerEdition" do
|
94
|
-
user, guide = publisher_and_guide
|
95
|
-
new_edition = user.new_version(guide, AnswerEdition)
|
96
|
-
|
97
|
-
assert_equal "AnswerEdition", new_edition._type
|
98
|
-
end
|
99
|
-
|
100
|
-
test "a new answer is in draft" do
|
101
|
-
g = AnswerEdition.new(slug: "childcare", panopticon_id: @artefact.id, title: "My new answer")
|
102
|
-
assert g.draft?
|
103
|
-
end
|
104
|
-
|
105
|
-
test "a new guide has draft but isn't published" do
|
106
|
-
g = FactoryGirl.create(:guide_edition, panopticon_id: @artefact.id)
|
107
|
-
assert g.draft?
|
108
|
-
refute g.published?
|
109
|
-
end
|
110
|
-
|
111
|
-
test "a guide should be marked as having reviewables if requested for review" do
|
112
|
-
guide = template_guide
|
113
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
114
|
-
refute guide.in_review?
|
115
|
-
assert_nil guide.review_requested_at
|
116
|
-
|
117
|
-
now = Time.zone.now
|
118
|
-
Timecop.freeze(now) do
|
119
|
-
request_review(user, guide)
|
120
|
-
end
|
121
|
-
assert guide.in_review?
|
122
|
-
assert_equal now.to_i, guide.review_requested_at.to_i
|
123
|
-
end
|
124
|
-
|
125
|
-
test "a guide not in review cannot have a reviewer" do
|
126
|
-
guide = template_guide
|
127
|
-
refute guide.in_review?
|
128
|
-
guide.reviewer = "Bob"
|
129
|
-
refute guide.valid?
|
130
|
-
assert guide.errors.has_key?(:reviewer)
|
131
|
-
end
|
132
|
-
|
133
|
-
test "guide workflow" do
|
134
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
135
|
-
other_user = FactoryGirl.create(:user, name: "James")
|
136
|
-
|
137
|
-
guide = user.create_edition(:guide, title: "My Title", slug: "my-title", panopticon_id: @artefact.id)
|
138
|
-
edition = guide
|
139
|
-
|
140
|
-
assert edition.can_request_review?
|
141
|
-
request_review(user, edition)
|
142
|
-
refute edition.can_request_review?
|
143
|
-
assert edition.can_request_amendments?
|
144
|
-
request_amendments(other_user, edition)
|
145
|
-
refute edition.can_request_amendments?
|
146
|
-
request_review(user, edition)
|
147
|
-
assert edition.can_approve_review?
|
148
|
-
approve_review(other_user, edition)
|
149
|
-
assert edition.can_publish?
|
150
|
-
end
|
151
|
-
|
152
|
-
test "skip review workflow" do
|
153
|
-
user = FactoryGirl.create(:user, name: "Ben", permissions: ["skip_review"])
|
154
|
-
other = FactoryGirl.create(:user, name: "Ben", permissions: ["signin"])
|
155
|
-
|
156
|
-
edition = user.create_edition(:guide, title: "My Title", slug: "my-title", panopticon_id: @artefact.id)
|
157
|
-
|
158
|
-
assert edition.can_request_review?
|
159
|
-
request_review(user, edition)
|
160
|
-
assert edition.can_skip_review?
|
161
|
-
refute skip_review(other, edition)
|
162
|
-
assert skip_review(user, edition)
|
163
|
-
assert edition.ready?
|
164
|
-
assert edition.can_publish?
|
165
|
-
end
|
166
|
-
|
167
|
-
test "when fact check has been initiated it can be skipped" do
|
168
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
169
|
-
other_user = FactoryGirl.create(:user, name: "James")
|
170
|
-
|
171
|
-
edition = user.create_edition(:guide, panopticon_id: @artefact.id, overview: "My Overview", title: "My Title", slug: "my-title")
|
172
|
-
|
173
|
-
request_review(user, edition)
|
174
|
-
approve_review(other_user, edition)
|
175
|
-
send_fact_check(user, edition)
|
176
|
-
|
177
|
-
assert other_user.progress(edition, { request_type: :skip_fact_check, comment: 'Fact check not received in time' })
|
178
|
-
edition.reload
|
179
|
-
assert edition.can_publish?
|
180
|
-
assert edition.actions.detect { |e| e.request_type == 'skip_fact_check' }
|
181
|
-
end
|
182
|
-
|
183
|
-
# until we improve the validation to produce few or no false positives
|
184
|
-
test "when processing fact check, it is not validated" do
|
185
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
186
|
-
other_user = FactoryGirl.create(:user, name: "James")
|
187
|
-
|
188
|
-
guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title")
|
189
|
-
edition = guide
|
190
|
-
|
191
|
-
request_review(user, edition)
|
192
|
-
approve_review(other_user, edition)
|
193
|
-
send_fact_check(user, edition)
|
194
|
-
receive_fact_check(user, edition, "Text.<l>content that the SafeHtml validator would catch</l>")
|
195
|
-
|
196
|
-
assert_equal "Text.<l>content that the SafeHtml validator would catch</l>", edition.actions.last.comment
|
197
|
-
end
|
198
|
-
|
199
|
-
test "fact_check_received can go back to out for fact_check" do
|
200
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
201
|
-
other_user = FactoryGirl.create(:user, name: "James")
|
202
|
-
|
203
|
-
guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title")
|
204
|
-
edition = guide
|
205
|
-
|
206
|
-
request_review(user, edition)
|
207
|
-
approve_review(other_user, edition)
|
208
|
-
send_fact_check(user, edition)
|
209
|
-
receive_fact_check(user, edition, "Text.<l>content that the SafeHtml validator would catch</l>")
|
210
|
-
send_fact_check(user, edition, "Out of office reply triggered receive_fact_check")
|
211
|
-
|
212
|
-
assert(edition.actions.last.comment.include? "Out of office reply triggered receive_fact_check")
|
213
|
-
end
|
214
|
-
|
215
|
-
test "when processing fact check, an edition can request for amendments" do
|
216
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
217
|
-
other_user = FactoryGirl.create(:user, name: "James")
|
218
|
-
|
219
|
-
guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title")
|
220
|
-
edition = guide
|
221
|
-
|
222
|
-
request_review(user, edition)
|
223
|
-
approve_review(other_user, edition)
|
224
|
-
send_fact_check(user, edition)
|
225
|
-
request_amendments(other_user, edition)
|
226
|
-
|
227
|
-
assert_equal 'request_amendments', edition.actions.last.request_type
|
228
|
-
assert_equal "More amendments are required", edition.actions.last.comment
|
229
|
-
end
|
230
|
-
|
231
|
-
test "ready items may require further amendments" do
|
232
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
233
|
-
other_user = FactoryGirl.create(:user, name: "James")
|
234
|
-
FactoryGirl.create(:user, name: "Fiona")
|
235
|
-
|
236
|
-
guide = user.create_edition(:guide, panopticon_id: FactoryGirl.create(:artefact).id, overview: "My Overview", title: "My Title", slug: "my-title")
|
237
|
-
edition = guide
|
238
|
-
|
239
|
-
request_review(user, edition)
|
240
|
-
|
241
|
-
edition.reviewer = other_user
|
242
|
-
edition.save!
|
243
|
-
|
244
|
-
approve_review(other_user, edition)
|
245
|
-
assert_nil edition.reviewer
|
246
|
-
|
247
|
-
request_amendments(other_user, edition)
|
248
|
-
assert_equal "More amendments are required", edition.actions.last.comment
|
249
|
-
end
|
250
|
-
|
251
|
-
test "check counting reviews" do
|
252
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
253
|
-
other_user = FactoryGirl.create(:user, name: "James")
|
254
|
-
|
255
|
-
guide = user.create_edition(:guide, title: "My Title", slug: "my-title", panopticon_id: @artefact.id)
|
256
|
-
edition = guide
|
257
|
-
|
258
|
-
assert_equal 0, guide.rejected_count
|
259
|
-
|
260
|
-
request_review(user, edition)
|
261
|
-
request_amendments(other_user, edition)
|
262
|
-
|
263
|
-
assert_equal 1, guide.rejected_count
|
264
|
-
|
265
|
-
request_review(user, edition)
|
266
|
-
approve_review(other_user, edition)
|
267
|
-
|
268
|
-
assert_equal 1, guide.rejected_count
|
269
|
-
end
|
270
|
-
|
271
|
-
test "user should not be able to review a guide they requested review for" do
|
272
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
273
|
-
|
274
|
-
guide = user.create_edition(:guide, title: "My Title", slug: "my-title", panopticon_id: @artefact.id)
|
275
|
-
edition = guide
|
276
|
-
|
277
|
-
assert edition.can_request_review?
|
278
|
-
request_review(user, edition)
|
279
|
-
refute request_amendments(user, edition)
|
280
|
-
end
|
281
|
-
|
282
|
-
test "user should not be able to okay a guide they requested review for" do
|
283
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
284
|
-
|
285
|
-
guide = user.create_edition(:guide, title: "My Title", slug: "my-title", panopticon_id: @artefact.id)
|
286
|
-
edition = guide
|
287
|
-
|
288
|
-
assert edition.can_request_review?
|
289
|
-
request_review(user, edition)
|
290
|
-
refute approve_review(user, edition)
|
291
|
-
end
|
292
|
-
|
293
|
-
test "a new programme has drafts but isn't published" do
|
294
|
-
p = template_programme
|
295
|
-
assert p.draft?
|
296
|
-
refute p.published?
|
297
|
-
end
|
298
|
-
|
299
|
-
test "a programme should be marked as having reviewables if requested for review" do
|
300
|
-
programme = template_programme
|
301
|
-
user, other_user = template_users
|
302
|
-
|
303
|
-
refute programme.in_review?
|
304
|
-
request_review(user, programme)
|
305
|
-
assert programme.in_review?, "A review was not requested for this programme."
|
306
|
-
end
|
307
|
-
|
308
|
-
test "programme workflow" do
|
309
|
-
user, other_user = template_users
|
310
|
-
|
311
|
-
edition = user.create_edition(:programme, panopticon_id: @artefact.id, title: "My title", slug: "my-slug")
|
312
|
-
|
313
|
-
assert edition.can_request_review?
|
314
|
-
request_review(user, edition)
|
315
|
-
refute edition.can_request_review?
|
316
|
-
assert edition.can_request_amendments?
|
317
|
-
request_amendments(other_user, edition)
|
318
|
-
refute edition.can_request_amendments?
|
319
|
-
request_review(user, edition)
|
320
|
-
assert edition.can_approve_review?
|
321
|
-
approve_review(other_user, edition)
|
322
|
-
assert edition.can_request_amendments?
|
323
|
-
assert edition.can_publish?
|
324
|
-
end
|
325
|
-
|
326
|
-
test "user should not be able to okay a programme they requested review for" do
|
327
|
-
user, other_user = template_users
|
328
|
-
|
329
|
-
edition = user.create_edition(:programme, panopticon_id: @artefact.id, title: "My title", slug: "my-slug")
|
330
|
-
|
331
|
-
assert edition.can_request_review?
|
332
|
-
request_review(user, edition)
|
333
|
-
refute approve_review(user, edition)
|
334
|
-
end
|
335
|
-
|
336
|
-
test "you can only create a new edition from a published edition" do
|
337
|
-
user, other_user = template_users
|
338
|
-
edition = user.create_edition(:programme, panopticon_id: @artefact.id, title: "My title", slug: "my-slug")
|
339
|
-
refute edition.published?
|
340
|
-
refute user.new_version(edition)
|
341
|
-
end
|
342
|
-
|
343
|
-
test "an edition can be moved into archive state" do
|
344
|
-
user, other_user = template_users
|
345
|
-
|
346
|
-
edition = user.create_edition(:programme, panopticon_id: @artefact.id, title: "My title", slug: "my-slug")
|
347
|
-
user.progress(edition, { request_type: :archive })
|
348
|
-
assert_equal "archived", edition.state
|
349
|
-
end
|
350
|
-
|
351
|
-
# Mongoid 2.x marks array fields as dirty whenever they are accessed.
|
352
|
-
# See https://github.com/mongoid/mongoid/issues/2311
|
353
|
-
# This behaviour has been patched in lib/mongoid/monkey_patches.rb
|
354
|
-
# in order to prevent workflow validation failures for editions
|
355
|
-
# with array fields.
|
356
|
-
#
|
357
|
-
test "not_editing_published_item should not consider unchanged array fields as changes" do
|
358
|
-
bs = FactoryGirl.create(:business_support_edition, state: 'published', sectors: [])
|
359
|
-
assert_empty bs.errors
|
360
|
-
bs.sectors # Access the Array field
|
361
|
-
bs.valid?
|
362
|
-
assert_empty bs.errors
|
363
|
-
bs.sectors << 'education'
|
364
|
-
assert_equal ['sectors'], bs.changes.keys
|
365
|
-
bs.valid?
|
366
|
-
assert_equal "Published editions can't be edited", bs.errors[:base].first
|
367
|
-
end
|
368
|
-
|
369
|
-
test "User can request amendments for an edition they just approved" do
|
370
|
-
user_1, user_2 = template_users
|
371
|
-
edition = user_1.create_edition(:answer, panopticon_id: @artefact.id, title: "Answer foo", slug: "answer-foo")
|
372
|
-
edition.body = "body content"
|
373
|
-
|
374
|
-
user_1.assign(edition, user_2)
|
375
|
-
request_review(user_1, edition)
|
376
|
-
assert edition.in_review?
|
377
|
-
|
378
|
-
approve_review(user_2, edition)
|
379
|
-
assert edition.ready?
|
380
|
-
|
381
|
-
request_amendments(user_2, edition)
|
382
|
-
assert edition.amends_needed?
|
383
|
-
end
|
384
|
-
|
385
|
-
test "important_note returns last non-resolved important note" do
|
386
|
-
user = FactoryGirl.create(:user, name: "Ben")
|
387
|
-
edition = template_guide
|
388
|
-
user.record_note(edition, 'this is an important note', Action::IMPORTANT_NOTE)
|
389
|
-
request_review(user, edition)
|
390
|
-
assert_equal edition.important_note.comment, 'this is an important note'
|
391
|
-
|
392
|
-
user.record_note(edition, nil, Action::IMPORTANT_NOTE_RESOLVED)
|
393
|
-
assert_nil edition.important_note
|
394
|
-
end
|
395
|
-
|
396
|
-
context "creating a new version of an edition" do
|
397
|
-
setup do
|
398
|
-
@user = User.new
|
399
|
-
@edition = FactoryGirl.create(:edition, state: :published)
|
400
|
-
end
|
401
|
-
|
402
|
-
should "return false if the edition is not published" do
|
403
|
-
@edition.update_attribute(:state, :in_review)
|
404
|
-
assert_nil @user.new_version(@edition)
|
405
|
-
end
|
406
|
-
|
407
|
-
should "record the action" do
|
408
|
-
new_version = @user.new_version(@edition)
|
409
|
-
assert_equal 'new_version', new_version.actions.last.request_type
|
410
|
-
end
|
411
|
-
|
412
|
-
should "return the new edition" do
|
413
|
-
new_version = @user.new_version(@edition)
|
414
|
-
assert_includes new_version.previous_siblings.to_a, @edition
|
415
|
-
end
|
416
|
-
|
417
|
-
context "creating an edition of a different type" do
|
418
|
-
should "build a clone of a new type" do
|
419
|
-
assert_equal GuideEdition, @user.new_version(@edition, "GuideEdition").class
|
420
|
-
end
|
421
|
-
|
422
|
-
should "record the action" do
|
423
|
-
new_version = @user.new_version(@edition)
|
424
|
-
assert_equal 'new_version', new_version.actions.last.request_type
|
425
|
-
end
|
426
|
-
end
|
427
|
-
|
428
|
-
context "when building the edition fails" do
|
429
|
-
setup do
|
430
|
-
@edition.stubs(:build_clone).returns(nil)
|
431
|
-
end
|
432
|
-
|
433
|
-
should "not record the action" do
|
434
|
-
assert_no_difference '@edition.actions.count' do
|
435
|
-
@user.new_version(@edition)
|
436
|
-
end
|
437
|
-
end
|
438
|
-
|
439
|
-
should "return nil" do
|
440
|
-
assert_nil @user.new_version(@edition)
|
441
|
-
end
|
442
|
-
end
|
443
|
-
end
|
444
|
-
|
445
|
-
context "#receive_fact_check" do
|
446
|
-
setup do
|
447
|
-
@edition = FactoryGirl.create(:guide_edition_with_two_parts, state: :fact_check)
|
448
|
-
# Internal links must start with a forward slash eg [link text](/link-destination)
|
449
|
-
@edition.parts.first.update_attribute(:body,
|
450
|
-
"[register and tax your vehicle](registering-an-imported-vehicle)")
|
451
|
-
end
|
452
|
-
|
453
|
-
should "transition an edition with link validation errors to fact_check_received state" do
|
454
|
-
assert @edition.invalid?
|
455
|
-
receive_fact_check(User.new, @edition)
|
456
|
-
assert_equal "fact_check_received", @edition.reload.state
|
457
|
-
end
|
458
|
-
|
459
|
-
should "record the action" do
|
460
|
-
assert_difference '@edition.actions.count', 1 do
|
461
|
-
receive_fact_check(User.new, @edition)
|
462
|
-
end
|
463
|
-
assert_equal "receive_fact_check", @edition.actions.last.request_type
|
464
|
-
end
|
465
|
-
end
|
466
|
-
|
467
|
-
context "#schedule_for_publishing" do
|
468
|
-
setup do
|
469
|
-
@user = FactoryGirl.build(:user)
|
470
|
-
@publish_at = 1.day.from_now.utc
|
471
|
-
@activity_details = { publish_at: @publish_at, comment: "Go schedule !" }
|
472
|
-
end
|
473
|
-
|
474
|
-
should "return false when scheduling an already published edition" do
|
475
|
-
edition = FactoryGirl.create(:edition, state: 'published')
|
476
|
-
refute schedule_for_publishing(@user, edition, @activity_details)
|
477
|
-
end
|
478
|
-
|
479
|
-
should "schedule an edition for publishing if it is ready" do
|
480
|
-
edition = FactoryGirl.create(:edition, state: 'ready')
|
481
|
-
|
482
|
-
schedule_for_publishing(@user, edition, @activity_details)
|
483
|
-
|
484
|
-
assert edition.scheduled_for_publishing?
|
485
|
-
assert_equal @publish_at.to_i, edition.publish_at.to_i
|
486
|
-
end
|
487
|
-
|
488
|
-
should "record the action" do
|
489
|
-
edition = FactoryGirl.create(:edition, state: 'ready')
|
490
|
-
options = { comment: "Go schedule !", request_details: { scheduled_time: @publish_at } }
|
491
|
-
|
492
|
-
assert_difference 'edition.actions.count', 1 do
|
493
|
-
schedule_for_publishing(@user, edition, @activity_details)
|
494
|
-
end
|
495
|
-
assert_equal 'schedule_for_publishing', edition.actions.last.request_type
|
496
|
-
end
|
497
|
-
end
|
498
|
-
end
|