-
Notifications
You must be signed in to change notification settings - Fork 197
Expand file tree
/
Copy patheditions.rb
More file actions
189 lines (161 loc) · 6.05 KB
/
editions.rb
File metadata and controls
189 lines (161 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
require_relative "../support/generic_edition"
FactoryBot.define do
factory :edition, class: GenericEdition, traits: [:translated] do
creator
sequence(:title) { |index| "edition-title-#{index}" }
body { "edition-body" }
change_note { "change-note" }
summary { "edition-summary" }
previously_published { false }
auth_bypass_id { SecureRandom.uuid }
trait(:with_organisations) do
transient do
organisations { [] }
create_default_organisation { true }
supporting_organisations { [] }
lead_organisations { organisations }
end
after :build do |edition, evaluator|
if evaluator.lead_organisations.empty? && evaluator.create_default_organisation
edition.edition_organisations.build(
edition:,
organisation: FactoryBot.build(:organisation),
lead_ordering: 1,
lead: true,
)
end
Array.wrap(evaluator.lead_organisations).each.with_index do |org, idx|
edition.edition_organisations.build(
edition:,
organisation: org,
lead_ordering: idx + 1,
lead: true,
)
end
Array.wrap(evaluator.supporting_organisations).each do |org|
edition.edition_organisations.build(
edition:,
organisation: org,
lead: false,
)
end
end
end
trait(:with_topical_events) do
after :build do |edition, evaluator|
if evaluator.topical_events.empty?
edition.topical_event_memberships.build(
edition:,
topical_event: build(:topical_event),
)
end
end
end
trait(:draft) { state { "draft" } }
trait(:submitted) do
transient do
submitter { nil }
end
state { "submitted" }
after :create do |edition, evaluator|
edition.versions.first.update!(event: "create", state: "draft")
submitter = evaluator.submitter.presence || edition.creator
edition.versions.create! event: "update", whodunnit: submitter.id, state: "submitted"
end
end
trait(:rejected) { state { "rejected" } }
trait(:published) do
state { "published" }
first_published_at { 2.days.ago }
major_change_published_at { 1.day.ago }
force_published { false }
published_major_version { 1 }
published_minor_version { 0 }
end
trait(:non_english) { primary_locale { "cy" } }
trait(:force_published) do
state { "published" }
first_published_at { 2.days.ago }
major_change_published_at { 1.day.ago }
force_published { true }
published_major_version { 1 }
published_minor_version { 0 }
end
trait(:deleted) { state { "deleted" } }
trait(:superseded) do
state { "superseded" }
first_published_at { 2.days.ago }
end
trait(:superseded_with_published) do
state { "superseded" }
first_published_at { 2.days.ago }
after(:create) do |edition|
create(:published_edition, document: edition.document)
end
end
trait(:featured) { featured { true } }
trait(:scheduled) do
state { "scheduled" }
scheduled_publication { 7.days.from_now }
end
trait(:force_scheduled) do
state { "scheduled" }
force_published { true }
scheduled_publication { 7.days.from_now }
end
trait(:access_limited) { access_limited { :organisations } }
trait(:with_alternative_format_provider) do
association :alternative_format_provider, factory: :organisation_with_alternative_format_contact_email
end
trait(:with_file_attachment) do
association :alternative_format_provider, factory: :organisation_with_alternative_format_contact_email
attachments { FactoryBot.build_list :file_attachment, 1 }
end
trait(:with_html_attachment) do
association :alternative_format_provider, factory: :organisation_with_alternative_format_contact_email
attachments { FactoryBot.build_list :html_attachment, 1 }
end
trait(:with_file_attachment_not_scanned) do
association :alternative_format_provider, factory: :organisation_with_alternative_format_contact_email
attachments { FactoryBot.build_list :file_attachment, 1 }
end
trait(:with_document) do
document
end
trait(:unpublished) do
state { :unpublished }
unpublishing { build(:unpublishing) }
end
trait(:published_in_error_redirect) do
state { :unpublished }
unpublishing { build(:published_in_error_redirect_unpublishing) }
end
trait(:published_in_error_no_redirect) do
state { :unpublished }
unpublishing { build(:published_in_error_no_redirect_unpublishing) }
end
trait(:consolidated_redirect) do
state { :unpublished }
unpublishing { build(:consolidated_unpublishing) }
end
trait(:withdrawn) do
state { "withdrawn" }
unpublishing { build(:withdrawn_unpublishing) }
end
end
factory :edition_with_document, parent: :edition, traits: [:with_document]
factory :draft_edition, parent: :edition, traits: [:draft]
factory :submitted_edition, parent: :edition, traits: [:submitted]
factory :rejected_edition, parent: :edition, traits: [:rejected]
factory :published_edition, parent: :edition, traits: [:published]
factory :non_english_published_edition, parent: :edition, traits: %i[non_english published]
factory :deleted_edition, parent: :edition, traits: [:deleted]
factory :superseded_edition, parent: :edition, traits: [:superseded]
factory :scheduled_edition, parent: :edition, traits: [:scheduled]
factory :force_scheduled_edition, parent: :edition, traits: [:force_scheduled]
factory :force_published_edition, parent: :edition, traits: [:force_published]
factory :unpublished_edition, parent: :edition, traits: [:unpublished]
factory :withdrawn_edition, parent: :edition, traits: [:withdrawn]
factory :protected_edition, parent: :edition, traits: [:access_limited]
factory :edition_with_organisations, parent: :edition, traits: [:with_organisations]
end