Skip to content

Commit 541631a

Browse files
committed
intergrate tests for reports
1 parent da6d91b commit 541631a

File tree

1 file changed

+232
-29
lines changed

1 file changed

+232
-29
lines changed

spec/policies/request_for_comment_policy_spec.rb

Lines changed: 232 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,40 @@
4646
end
4747
end
4848
end
49+
50+
permissions(:report?) do
51+
before do
52+
codeocean_config = instance_double(CodeOcean::Config)
53+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
54+
allow(codeocean_config).to receive(:read).and_return({
55+
content_moderation: {report_emails: ['[email protected]']},
56+
})
57+
end
58+
59+
it 'allows anyone to report RfCs' do
60+
%i[admin external_user teacher].each do |factory_name|
61+
expect(policy).to permit(create(factory_name), create(:rfc))
62+
end
63+
end
64+
end
4965
end
5066

5167
context 'when the RfC visibility is considered' do
52-
shared_examples 'grants access to everyone' do
68+
shared_examples 'grants access to everyone' do |params|
5369
it 'grants access to everyone' do
5470
%i[external_user teacher admin].each do |factory_name|
5571
expect(policy).to permit(create(factory_name, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc)
5672
end
5773
end
5874

59-
it 'grants access to authors' do
60-
expect(policy).to permit(rfc.author, rfc)
75+
if params && params[:block_author]
76+
it 'dose not grant access to authors' do
77+
expect(policy).not_to permit(rfc.author, rfc)
78+
end
79+
else
80+
it 'grants access to authors' do
81+
expect(policy).to permit(rfc.author, rfc)
82+
end
6183
end
6284

6385
it 'grant access to other authors of the programming group' do
@@ -87,6 +109,27 @@
87109
end
88110
end
89111

112+
shared_examples 'grants access to admins only' do
113+
it 'grants access to admins' do
114+
expect(policy).to permit(create(:admin, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc)
115+
end
116+
117+
it 'dose not grant access to authors' do
118+
expect(policy).not_to permit(rfc.author, rfc)
119+
end
120+
121+
it 'grant access to other authors of the programming group' do
122+
rfc.submission.update(contributor: programming_group)
123+
expect(policy).to permit(viewer_other_group_member, rfc)
124+
end
125+
126+
it 'does not grant access to all other users' do
127+
%i[external_user teacher].each do |factory_name|
128+
expect(policy).not_to permit(create(factory_name, consumer: viewer_consumer, study_groups: viewer_study_groups), rfc)
129+
end
130+
end
131+
end
132+
90133
let(:rfc_author) { create(:learner, consumer: author_consumer, study_groups: author_study_groups) }
91134
let(:author_study_groups) { create_list(:study_group, 1, consumer: author_consumer) }
92135
let(:rfc) { create(:rfc, user: rfc_author) }
@@ -111,6 +154,18 @@
111154
it_behaves_like 'grants access to admins and authors only'
112155
end
113156
end
157+
158+
permissions(:report?) do
159+
before do
160+
codeocean_config = instance_double(CodeOcean::Config)
161+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
162+
allow(codeocean_config).to receive(:read).and_return({
163+
content_moderation: {report_emails: ['[email protected]']},
164+
})
165+
end
166+
167+
it_behaves_like 'grants access to everyone', {block_author: true}
168+
end
114169
end
115170

116171
context "when the viewer's rfc_visibility is set to consumer" do
@@ -122,6 +177,18 @@
122177
it_behaves_like 'grants access to admins and authors only'
123178
end
124179
end
180+
181+
permissions(:report?) do
182+
before do
183+
codeocean_config = instance_double(CodeOcean::Config)
184+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
185+
allow(codeocean_config).to receive(:read).and_return({
186+
content_moderation: {report_emails: ['[email protected]']},
187+
})
188+
end
189+
190+
it_behaves_like 'grants access to admins only'
191+
end
125192
end
126193

127194
context "when the viewer's rfc_visibility is set to study_group" do
@@ -133,6 +200,18 @@
133200
it_behaves_like 'grants access to admins and authors only'
134201
end
135202
end
203+
204+
permissions(:report?) do
205+
before do
206+
codeocean_config = instance_double(CodeOcean::Config)
207+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
208+
allow(codeocean_config).to receive(:read).and_return({
209+
content_moderation: {report_emails: ['[email protected]']},
210+
})
211+
end
212+
213+
it_behaves_like 'grants access to admins only'
214+
end
136215
end
137216
end
138217

@@ -151,6 +230,18 @@
151230
it_behaves_like 'grants access to admins and authors only'
152231
end
153232
end
233+
234+
permissions(:report?) do
235+
before do
236+
codeocean_config = instance_double(CodeOcean::Config)
237+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
238+
allow(codeocean_config).to receive(:read).and_return({
239+
content_moderation: {report_emails: ['[email protected]']},
240+
})
241+
end
242+
243+
it_behaves_like 'grants access to everyone', {block_author: true}
244+
end
154245
end
155246

156247
context 'when the viewer is from the same study group' do
@@ -165,6 +256,18 @@
165256
it_behaves_like 'grants access to admins and authors only'
166257
end
167258
end
259+
260+
permissions(:report?) do
261+
before do
262+
codeocean_config = instance_double(CodeOcean::Config)
263+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
264+
allow(codeocean_config).to receive(:read).and_return({
265+
content_moderation: {report_emails: ['[email protected]']},
266+
})
267+
end
268+
269+
it_behaves_like 'grants access to everyone', {block_author: true}
270+
end
168271
end
169272
end
170273
end
@@ -182,6 +285,18 @@
182285
it_behaves_like 'grants access to admins and authors only'
183286
end
184287
end
288+
289+
permissions(:report?) do
290+
before do
291+
codeocean_config = instance_double(CodeOcean::Config)
292+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
293+
allow(codeocean_config).to receive(:read).and_return({
294+
content_moderation: {report_emails: ['[email protected]']},
295+
})
296+
end
297+
298+
it_behaves_like 'grants access to admins only'
299+
end
185300
end
186301

187302
context "when the viewer's rfc_visibility is set to consumer" do
@@ -193,6 +308,18 @@
193308
it_behaves_like 'grants access to admins and authors only'
194309
end
195310
end
311+
312+
permissions(:report?) do
313+
before do
314+
codeocean_config = instance_double(CodeOcean::Config)
315+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
316+
allow(codeocean_config).to receive(:read).and_return({
317+
content_moderation: {report_emails: ['[email protected]']},
318+
})
319+
end
320+
321+
it_behaves_like 'grants access to admins only'
322+
end
196323
end
197324

198325
context "when the viewer's rfc_visibility is set to study_group" do
@@ -204,6 +331,18 @@
204331
it_behaves_like 'grants access to admins and authors only'
205332
end
206333
end
334+
335+
permissions(:report?) do
336+
before do
337+
codeocean_config = instance_double(CodeOcean::Config)
338+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
339+
allow(codeocean_config).to receive(:read).and_return({
340+
content_moderation: {report_emails: ['[email protected]']},
341+
})
342+
end
343+
344+
it_behaves_like 'grants access to admins only'
345+
end
207346
end
208347
end
209348

@@ -222,6 +361,18 @@
222361
it_behaves_like 'grants access to admins and authors only'
223362
end
224363
end
364+
365+
permissions(:report?) do
366+
before do
367+
codeocean_config = instance_double(CodeOcean::Config)
368+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
369+
allow(codeocean_config).to receive(:read).and_return({
370+
content_moderation: {report_emails: ['[email protected]']},
371+
})
372+
end
373+
374+
it_behaves_like 'grants access to everyone', {block_author: true}
375+
end
225376
end
226377

227378
context 'when the viewer is from the same study group' do
@@ -236,6 +387,18 @@
236387
it_behaves_like 'grants access to admins and authors only'
237388
end
238389
end
390+
391+
permissions(:report?) do
392+
before do
393+
codeocean_config = instance_double(CodeOcean::Config)
394+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
395+
allow(codeocean_config).to receive(:read).and_return({
396+
content_moderation: {report_emails: ['[email protected]']},
397+
})
398+
end
399+
400+
it_behaves_like 'grants access to everyone', {block_author: true}
401+
end
239402
end
240403
end
241404
end
@@ -253,6 +416,18 @@
253416
it_behaves_like 'grants access to admins and authors only'
254417
end
255418
end
419+
420+
permissions(:report?) do
421+
before do
422+
codeocean_config = instance_double(CodeOcean::Config)
423+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
424+
allow(codeocean_config).to receive(:read).and_return({
425+
content_moderation: {report_emails: ['[email protected]']},
426+
})
427+
end
428+
429+
it_behaves_like 'grants access to admins only'
430+
end
256431
end
257432

258433
context "when the viewer's rfc_visibility is set to consumer" do
@@ -264,6 +439,18 @@
264439
it_behaves_like 'grants access to admins and authors only'
265440
end
266441
end
442+
443+
permissions(:report?) do
444+
before do
445+
codeocean_config = instance_double(CodeOcean::Config)
446+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
447+
allow(codeocean_config).to receive(:read).and_return({
448+
content_moderation: {report_emails: ['[email protected]']},
449+
})
450+
end
451+
452+
it_behaves_like 'grants access to admins only'
453+
end
267454
end
268455

269456
context "when the viewer's rfc_visibility is set to study_group" do
@@ -275,6 +462,18 @@
275462
it_behaves_like 'grants access to admins and authors only'
276463
end
277464
end
465+
466+
permissions(:report?) do
467+
before do
468+
codeocean_config = instance_double(CodeOcean::Config)
469+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
470+
allow(codeocean_config).to receive(:read).and_return({
471+
content_moderation: {report_emails: ['[email protected]']},
472+
})
473+
end
474+
475+
it_behaves_like 'grants access to admins only'
476+
end
278477
end
279478
end
280479

@@ -289,6 +488,18 @@
289488
it_behaves_like 'grants access to admins and authors only'
290489
end
291490
end
491+
492+
permissions(:report?) do
493+
before do
494+
codeocean_config = instance_double(CodeOcean::Config)
495+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
496+
allow(codeocean_config).to receive(:read).and_return({
497+
content_moderation: {report_emails: ['[email protected]']},
498+
})
499+
end
500+
501+
it_behaves_like 'grants access to admins only'
502+
end
292503
end
293504

294505
context 'when the viewer is from the same study group' do
@@ -303,38 +514,30 @@
303514
it_behaves_like 'grants access to admins and authors only'
304515
end
305516
end
306-
end
307-
end
308-
end
309-
end
310517

311-
permissions(:report?) do
312-
let(:user) { build_stubbed(:external_user) }
518+
permissions(:report?) do
519+
before do
520+
codeocean_config = instance_double(CodeOcean::Config)
521+
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
522+
allow(codeocean_config).to receive(:read).and_return({
523+
content_moderation: {report_emails: ['[email protected]']},
524+
})
525+
end
313526

314-
it 'allows anyone to report RfCs' do
315-
%i[admin external_user teacher].each do |factory_name|
316-
expect(policy).to permit(create(factory_name), create(:rfc))
527+
it_behaves_like 'grants access to everyone', {block_author: true}
528+
end
529+
end
317530
end
318531
end
319532

320-
it 'dose not allow reports when the RfC is not accessable' do
321-
allow_any_instance_of(policy).to receive(:show?).and_return(false)
322-
323-
%i[admin external_user teacher].each do |factory_name|
324-
expect(policy).not_to permit(create(factory_name), RequestForComment.new)
533+
context 'when no report email is configured' do
534+
permissions(:report?) do
535+
it 'dose not allow reports from anyone' do
536+
%i[admin external_user teacher].each do |factory_name|
537+
expect(policy).not_to permit(create(factory_name), RequestForComment.new)
538+
end
539+
end
325540
end
326541
end
327-
328-
it 'dose not allow reports when no report email is configured' do
329-
codeocean_config = instance_double(CodeOcean::Config)
330-
allow(CodeOcean::Config).to receive(:new).with(:code_ocean).and_return(codeocean_config)
331-
allow(codeocean_config).to receive(:read).and_return({})
332-
333-
expect(policy).not_to permit(user, RequestForComment.new)
334-
end
335-
336-
it 'dose not allow reports of your own content' do
337-
expect(policy).not_to permit(user, RequestForComment.new(user: user))
338-
end
339542
end
340543
end

0 commit comments

Comments
 (0)