Skip to content

Commit e4a563d

Browse files
committed
Make shared examples explicit to report?
1 parent 818d7ad commit e4a563d

File tree

1 file changed

+45
-98
lines changed

1 file changed

+45
-98
lines changed

spec/policies/request_for_comment_policy_spec.rb

Lines changed: 45 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,21 @@
9393
end
9494
end
9595

96-
shared_examples 'grants access to everyone but the author' do
97-
it 'grants access to everyone but the author' do
98-
%i[external_user teacher admin].each do |factory_name|
99-
expect(policy).to permit(create(factory_name, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc)
96+
shared_examples 'grants report permissions to everyone but the author' do
97+
permissions(:report?) do
98+
let(:reports_enabled) { true }
99+
100+
it 'grants access to everyone but the author' do
101+
%i[external_user teacher admin].each do |factory_name|
102+
expect(policy).to permit(create(factory_name, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc)
103+
end
104+
expect(policy).not_to permit(rfc.author, rfc)
100105
end
101-
expect(policy).not_to permit(rfc.author, rfc)
102-
end
103106

104-
it 'grant access to other authors of the programming group' do
105-
rfc.submission.update(contributor: programming_group)
106-
expect(policy).to permit(viewer_other_group_member, rfc)
107+
it 'grant access to other authors of the programming group' do
108+
rfc.submission.update(contributor: programming_group)
109+
expect(policy).to permit(viewer_other_group_member, rfc)
110+
end
107111
end
108112
end
109113

@@ -128,23 +132,26 @@
128132
end
129133
end
130134

131-
shared_examples 'grants access to admins and other authors only' do
132-
it 'grants access to admins' do
133-
expect(policy).to permit(create(:admin, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc)
134-
end
135+
shared_examples 'grants report permissions to admins and other authors only' do
136+
permissions(:report?) do
137+
let(:reports_enabled) { true }
138+
it 'grants access to admins' do
139+
expect(policy).to permit(create(:admin, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc)
140+
end
135141

136-
it 'does not grant access to authors' do
137-
expect(policy).not_to permit(rfc.author, rfc)
138-
end
142+
it 'does not grant access to authors' do
143+
expect(policy).not_to permit(rfc.author, rfc)
144+
end
139145

140-
it 'grant access to other authors of the programming group' do
141-
rfc.submission.update(contributor: programming_group)
142-
expect(policy).to permit(viewer_other_group_member, rfc)
143-
end
146+
it 'grant access to other authors of the programming group' do
147+
rfc.submission.update(contributor: programming_group)
148+
expect(policy).to permit(viewer_other_group_member, rfc)
149+
end
144150

145-
it 'does not grant access to all other users' do
146-
%i[external_user teacher].each do |factory_name|
147-
expect(policy).not_to permit(create(factory_name, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc)
151+
it 'does not grant access to all other users' do
152+
%i[external_user teacher].each do |factory_name|
153+
expect(policy).not_to permit(create(factory_name, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc)
154+
end
148155
end
149156
end
150157
end
@@ -174,11 +181,7 @@
174181
end
175182
end
176183

177-
permissions(:report?) do
178-
let(:reports_enabled) { true }
179-
180-
it_behaves_like 'grants access to everyone but the author'
181-
end
184+
it_behaves_like 'grants report permissions to everyone but the author'
182185
end
183186

184187
context "when the viewer's rfc_visibility is set to consumer" do
@@ -191,11 +194,7 @@
191194
end
192195
end
193196

194-
permissions(:report?) do
195-
let(:reports_enabled) { true }
196-
197-
it_behaves_like 'grants access to admins and other authors only'
198-
end
197+
it_behaves_like 'grants report permissions to admins and other authors only'
199198
end
200199

201200
context "when the viewer's rfc_visibility is set to study_group" do
@@ -208,11 +207,7 @@
208207
end
209208
end
210209

211-
permissions(:report?) do
212-
let(:reports_enabled) { true }
213-
214-
it_behaves_like 'grants access to admins and other authors only'
215-
end
210+
it_behaves_like 'grants report permissions to admins and other authors only'
216211
end
217212
end
218213

@@ -232,11 +227,7 @@
232227
end
233228
end
234229

235-
permissions(:report?) do
236-
let(:reports_enabled) { true }
237-
238-
it_behaves_like 'grants access to everyone but the author'
239-
end
230+
it_behaves_like 'grants report permissions to everyone but the author'
240231
end
241232

242233
context 'when the viewer is from the same study group' do
@@ -252,11 +243,7 @@
252243
end
253244
end
254245

255-
permissions(:report?) do
256-
let(:reports_enabled) { true }
257-
258-
it_behaves_like 'grants access to everyone but the author'
259-
end
246+
it_behaves_like 'grants report permissions to everyone but the author'
260247
end
261248
end
262249
end
@@ -275,11 +262,7 @@
275262
end
276263
end
277264

278-
permissions(:report?) do
279-
let(:reports_enabled) { true }
280-
281-
it_behaves_like 'grants access to admins and other authors only'
282-
end
265+
it_behaves_like 'grants report permissions to admins and other authors only'
283266
end
284267

285268
context "when the viewer's rfc_visibility is set to consumer" do
@@ -292,11 +275,7 @@
292275
end
293276
end
294277

295-
permissions(:report?) do
296-
let(:reports_enabled) { true }
297-
298-
it_behaves_like 'grants access to admins and other authors only'
299-
end
278+
it_behaves_like 'grants report permissions to admins and other authors only'
300279
end
301280

302281
context "when the viewer's rfc_visibility is set to study_group" do
@@ -309,11 +288,7 @@
309288
end
310289
end
311290

312-
permissions(:report?) do
313-
let(:reports_enabled) { true }
314-
315-
it_behaves_like 'grants access to admins and other authors only'
316-
end
291+
it_behaves_like 'grants report permissions to admins and other authors only'
317292
end
318293
end
319294

@@ -333,11 +308,7 @@
333308
end
334309
end
335310

336-
permissions(:report?) do
337-
let(:reports_enabled) { true }
338-
339-
it_behaves_like 'grants access to everyone but the author'
340-
end
311+
it_behaves_like 'grants report permissions to everyone but the author'
341312
end
342313

343314
context 'when the viewer is from the same study group' do
@@ -353,11 +324,7 @@
353324
end
354325
end
355326

356-
permissions(:report?) do
357-
let(:reports_enabled) { true }
358-
359-
it_behaves_like 'grants access to everyone but the author'
360-
end
327+
it_behaves_like 'grants report permissions to everyone but the author'
361328
end
362329
end
363330
end
@@ -376,11 +343,7 @@
376343
end
377344
end
378345

379-
permissions(:report?) do
380-
let(:reports_enabled) { true }
381-
382-
it_behaves_like 'grants access to admins and other authors only'
383-
end
346+
it_behaves_like 'grants report permissions to admins and other authors only'
384347
end
385348

386349
context "when the viewer's rfc_visibility is set to consumer" do
@@ -393,11 +356,7 @@
393356
end
394357
end
395358

396-
permissions(:report?) do
397-
let(:reports_enabled) { true }
398-
399-
it_behaves_like 'grants access to admins and other authors only'
400-
end
359+
it_behaves_like 'grants report permissions to admins and other authors only'
401360
end
402361

403362
context "when the viewer's rfc_visibility is set to study_group" do
@@ -410,11 +369,7 @@
410369
end
411370
end
412371

413-
permissions(:report?) do
414-
let(:reports_enabled) { true }
415-
416-
it_behaves_like 'grants access to admins and other authors only'
417-
end
372+
it_behaves_like 'grants report permissions to admins and other authors only'
418373
end
419374
end
420375

@@ -430,11 +385,7 @@
430385
end
431386
end
432387

433-
permissions(:report?) do
434-
let(:reports_enabled) { true }
435-
436-
it_behaves_like 'grants access to admins and other authors only'
437-
end
388+
it_behaves_like 'grants report permissions to admins and other authors only'
438389
end
439390

440391
context 'when the viewer is from the same study group' do
@@ -450,11 +401,7 @@
450401
end
451402
end
452403

453-
permissions(:report?) do
454-
let(:reports_enabled) { true }
455-
456-
it_behaves_like 'grants access to everyone but the author'
457-
end
404+
it_behaves_like 'grants report permissions to everyone but the author'
458405
end
459406
end
460407
end

0 commit comments

Comments
 (0)