forked from expertiza/expertiza
-
Notifications
You must be signed in to change notification settings - Fork 0
/
review_mapping_controller_spec.rb
581 lines (535 loc) · 26.7 KB
/
review_mapping_controller_spec.rb
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
require 'rails_helper'
describe ReviewMappingController do
let(:assignment) { double('Assignment', id: 1) }
let(:review_response_map) do
double('ReviewResponseMap', id: 1, map_id: 1, assignment: assignment,
reviewer: double('Participant', id: 1, name: 'reviewer'), reviewee: double('Participant', id: 2, name: 'reviewee'))
end
let(:metareview_response_map) do
double('MetareviewResponseMap', id: 1, map_id: 1, assignment: assignment,
reviewer: double('Participant', id: 1, name: 'reviewer'), reviewee: double('Participant', id: 2, name: 'reviewee'))
end
let(:participant) { double('AssignmentParticipant', id: 1, can_review: false, user: double('User', id: 1)) }
let(:participant1) { double('AssignmentParticipant', id: 2, can_review: true, user: double('User', id: 2)) }
let(:user) { double('User', id: 3) }
let(:participant2) { double('AssignmentParticipant', id: 3, can_review: true, user: user) }
let(:participant3) { double('Participant', user_id: 1, parent_id: '1', can_review: true) }
let(:team) { double('AssignmentTeam', name: 'no one') }
let(:team1) { double('AssignmentTeam', name: 'no one1') }
let(:response1) { [double('Response', id: 1, map_id: 1, additional_comment: 'Test Comment')] }
before(:each) do
allow(Assignment).to receive(:find).with('1').and_return(assignment)
instructor = build(:instructor)
stub_current_user(instructor, instructor.role.name, instructor.role)
end
describe '#add_calibration' do
context 'when both participant and review_response_map have already existed' do
it 'does not need to create new objects and redirects to responses#new maps' do
allow(AssignmentParticipant).to receive_message_chain(:where, :first)
.with(parent_id: '1', user_id: 1).with(no_args).and_return(participant)
allow(ReviewResponseMap).to receive_message_chain(:where, :first)
.with(reviewed_object_id: '1', reviewer_id: 1, reviewee_id: '1', calibrate_to: true).with(no_args).and_return(review_response_map)
params = {id: 1, team_id: 1}
session = {user: build(:instructor, id: 1)}
get :add_calibration, params, session
expect(response).to redirect_to '/response/new?assignment_id=1&id=1&return=assignment_edit'
end
end
context 'when both participant and review_response_map have not been created' do
it 'creates new objects and redirects to responses#new maps' do
allow(AssignmentParticipant).to receive_message_chain(:where, :first)
.with(parent_id: '1', user_id: 1).with(no_args).and_return(nil)
allow(AssignmentParticipant).to receive(:create)
.with(parent_id: '1', user_id: 1, can_submit: 1, can_review: 1, can_take_quiz: 1, handle: 'handle').and_return(participant)
allow(ReviewResponseMap).to receive_message_chain(:where, :first)
.with(reviewed_object_id: '1', reviewer_id: 1, reviewee_id: '1', calibrate_to: true).with(no_args).and_return(nil)
allow(ReviewResponseMap).to receive(:create)
.with(reviewed_object_id: '1', reviewer_id: 1, reviewee_id: '1', calibrate_to: true).and_return(review_response_map)
params = {id: 1, team_id: 1}
session = {user: build(:instructor, id: 1)}
get :add_calibration, params, session
expect(response).to redirect_to '/response/new?assignment_id=1&id=1&return=assignment_edit'
end
end
end
describe '#add_reviewer and #get_reviewer' do
before(:each) do
allow(User).to receive_message_chain(:where, :first).with(name: 'expertiza').with(no_args).and_return(double('User', id: 1))
@params = {
id: 1,
topic_id: 1,
user: {name: 'expertiza'},
contributor_id: 1
}
end
context 'when team_user does not exist' do
it 'shows an error message and redirects to review_mapping#list_mappings page' do
allow(TeamsUser).to receive(:exists?).with(team_id: '1', user_id: 1).and_return(true)
post :add_reviewer, @params
expect(response).to redirect_to '/review_mapping/list_mappings?id=1'
end
end
context 'when team_user exists and get_reviewer method returns a reviewer' do
it 'creates a whole bunch of objects and redirects to review_mapping#list_mappings page' do
allow(TeamsUser).to receive(:exists?).with(team_id: '1', user_id: 1).and_return(false)
allow(SignUpSheet).to receive(:signup_team).with(1, 1, '1').and_return(true)
user = double('User', id: 1)
allow(User).to receive(:from_params).with(any_args).and_return(user)
allow(AssignmentParticipant).to receive(:where).with(user_id: 1, parent_id: 1)
.and_return([double('AssignmentParticipant', id: 1, name: 'no one')])
allow(Participant).to receive_message_chain(:where, :first)
.with(parent_id: '1', user_id: 1).with(no_args).and_return(participant3)
allow(ReviewResponseMap).to receive_message_chain(:where, :first)
.with(reviewee_id: '1', reviewer_id: 1).with(no_args).and_return(nil)
allow(ReviewResponseMap).to receive(:create).with(reviewee_id: '1', reviewer_id: 1, reviewed_object_id: 1).and_return(nil)
post :add_reviewer, @params
expect(response).to redirect_to '/review_mapping/list_mappings?id=1'
end
end
end
describe '#assign_reviewer_dynamically' do
before(:each) do
allow(AssignmentParticipant).to receive_message_chain(:where, :first)
.with(user_id: '1', parent_id: 1).with(no_args).and_return(participant)
end
context 'when assignment has topics and no topic is selected by reviewer' do
it 'shows an error message and redirects to student_review#list page' do
allow(assignment).to receive(:topics?).and_return(true)
allow(assignment).to receive(:can_choose_topic_to_review?).and_return(true)
params = {
assignment_id: 1,
reviewer_id: 1
}
post :assign_reviewer_dynamically, params
expect(flash[:error]).to eq('No topic is selected. Please go back and select a topic.')
expect(response).to redirect_to '/student_review/list?id=1'
end
end
context 'when assignment has topics and a topic is selected by reviewer' do
it 'assigns reviewer dynamically and redirects to student_review#list page' do
allow(assignment).to receive(:topics?).and_return(true)
topic = double('SignUpTopic')
allow(SignUpTopic).to receive(:find).with('1').and_return(topic)
allow(assignment).to receive(:assign_reviewer_dynamically).with(participant, topic).and_return(true)
params = {
assignment_id: 1,
reviewer_id: 1,
topic_id: 1
}
post :assign_reviewer_dynamically, params
expect(response).to redirect_to '/student_review/list?id=1'
end
end
context 'when assignment does not have topics' do
it 'runs another algorithms and redirects to student_review#list page' do
allow(assignment).to receive(:topics?).and_return(false)
team1 = double('AssignmentTeam')
team2 = double('AssignmentTeam')
teams = [team1, team2]
allow(assignment).to receive(:candidate_assignment_teams_to_review).with(participant).and_return(teams)
allow(teams).to receive_message_chain(:to_a, :sample).and_return(team2)
allow(assignment).to receive(:assign_reviewer_dynamically_no_topic).with(participant, team2).and_return(true)
params = {
assignment_id: 1,
reviewer_id: 1,
topic_id: 1
}
post :assign_reviewer_dynamically, params
expect(response).to redirect_to '/student_review/list?id=1'
end
end
end
describe '#assign_quiz_dynamically' do
before(:each) do
allow(AssignmentParticipant).to receive_message_chain(:where, :first)
.with(user_id: '1', parent_id: 1).with(no_args).and_return(participant)
@params = {
assignment_id: 1,
reviewer_id: 1,
questionnaire_id: 1,
participant_id: 1
}
end
context 'when corresponding response map exists' do
it 'shows a flash error and redirects to student_quizzes page' do
allow(ResponseMap).to receive_message_chain(:where, :first).with(reviewed_object_id: '1', reviewer_id: '1')
.with(no_args).and_return(double('ResponseMap'))
post :assign_quiz_dynamically, @params
expect(flash[:error]).to eq('You have already taken that quiz.')
expect(response).to redirect_to('/student_quizzes?id=1')
end
end
context 'when corresponding response map does not exist' do
it 'creates a new QuizResponseMap and redirects to student_quizzes page' do
questionnaire = double('Questionnaire', id: 1, instructor_id: 1)
allow(Questionnaire).to receive(:find).with('1').and_return(questionnaire)
allow(Questionnaire).to receive(:find_by).with(instructor_id: 1).and_return(questionnaire)
allow_any_instance_of(QuizResponseMap).to receive(:save).and_return(true)
post :assign_quiz_dynamically, @params
expect(flash[:error]).to be nil
expect(response).to redirect_to('/student_quizzes?id=1')
end
end
end
describe '#add_metareviewer' do
before(:each) do
allow(ResponseMap).to receive(:find).with('1').and_return(review_response_map)
end
it 'redirects to review_mapping#list_mappings page' do
user = double('User', id: 1, name: 'no one')
allow(User).to receive(:from_params).with(any_args).and_return(user)
# allow_any_instance_of(ReviewMappingController).to receive(:url_for).with(action: 'add_user_to_assignment', id: 1, user_id: 1).and_return('')
allow_any_instance_of(ReviewMappingController).to receive(:get_reviewer)
.with(user, assignment, 'http://test.host/review_mapping/add_user_to_assignment?id=1&user_id=1')
.and_return(double('AssignmentParticipant', id: 1, name: 'no one'))
allow(ReviewResponseMap).to receive(:where).with(reviewed_object_id: 1, reviewer_id: 1).and_return([nil])
params = {id: 1}
post :add_metareviewer, params
expect(response).to redirect_to('/review_mapping/list_mappings?id=1&msg=')
end
end
describe '#assign_metareviewer_dynamically' do
it 'redirects to student_review#list page' do
metareviewer = double('AssignmentParticipant', id: 1)
allow(AssignmentParticipant).to receive(:where).with(user_id: '1', parent_id: 1).and_return([metareviewer])
allow(assignment).to receive(:assign_metareviewer_dynamically).with(metareviewer).and_return(true)
params = {
assignment_id: 1,
metareviewer_id: 1
}
post :assign_metareviewer_dynamically, params
expect(response).to redirect_to('/student_review/list?id=1')
end
end
describe '#delete_outstanding_reviewers' do
before(:each) do
allow(AssignmentTeam).to receive(:find).with('1').and_return(team)
allow(team).to receive(:review_mappings).and_return([double('ReviewResponseMap', id: 1)])
end
context 'when review response map has corresponding responses' do
it 'shows a flash error and redirects to review_mapping#list_mappings page' do
allow(Response).to receive(:exists?).with(map_id: 1).and_return(true)
allow(Response).to receive(:where).with(map_id: 1).and_return(response1)
params = {
id: 1,
contributor_id: 1
}
post :delete_outstanding_reviewers, params
expect(flash[:success]).to be nil
expect(flash[:error]).to eq('1 reviewer(s) cannot be deleted because they have already started a review.')
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
context 'when review response map does not have corresponding responses' do
it 'shows a flash success and redirects to review_mapping#list_mappings page' do
allow(Response).to receive(:exists?).with(map_id: 1).and_return(false)
review_response_map = double('ReviewResponseMap')
allow(ReviewResponseMap).to receive(:find).with(1).and_return(review_response_map)
allow(review_response_map).to receive(:destroy).and_return(true)
params = {
id: 1,
contributor_id: 1
}
post :delete_outstanding_reviewers, params
expect(flash[:error]).to be nil
expect(flash[:success]).to eq('All review mappings for "no one" have been deleted.')
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
end
describe '#delete_all_metareviewers' do
before(:each) do
allow(ResponseMap).to receive(:find).with('1').and_return(review_response_map)
@metareview_response_maps = [metareview_response_map]
allow(MetareviewResponseMap).to receive(:where).with(reviewed_object_id: 1).and_return(@metareview_response_maps)
end
context 'when failed times are bigger than 0' do
it 'shows an error flash message and redirects to review_mapping#list_mappings page' do
@metareview_response_maps.each do |metareview_response_map|
allow(metareview_response_map).to receive(:delete).with(true).and_raise('Boom')
end
params = {id: 1, force: true}
post :delete_all_metareviewers, params
expect(flash[:note]).to be nil
expect(flash[:error]).to eq("A delete action failed:<br/>1 metareviews exist for these mappings. "\
"Delete these mappings anyway? <a href='http://test.host/review_mapping/delete_all_metareviewers?force=1&id=1'>Yes</a> | "\
"<a href='http://test.host/review_mapping/delete_all_metareviewers?id=1'>No</a><br/>")
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
context 'when failed time is equal to 0' do
it 'shows a note flash message and redirects to review_mapping#list_mappings page' do
@metareview_response_maps.each do |metareview_response_map|
allow(metareview_response_map).to receive(:delete).with(true)
end
params = {id: 1, force: true}
post :delete_all_metareviewers, params
expect(flash[:error]).to be nil
expect(flash[:note]).to eq('All metareview mappings for contributor "reviewee" and reviewer "reviewer" have been deleted.')
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
end
describe '#unsubmit_review' do
let(:review_response) { double('Response') }
before(:each) do
allow(Response).to receive(:where).with(map_id: '1').and_return([review_response])
allow(ReviewResponseMap).to receive(:find_by).with(id: '1').and_return(review_response_map)
end
context 'when attributes of response are updated successfully' do
it 'shows a success flash.now message and renders a .js.erb file' do
allow(review_response).to receive(:update_attribute).with('is_submitted', false).and_return(true)
params = {id: 1}
# xhr - XmlHttpRequest (AJAX)
xhr :get, :unsubmit_review, params
expect(flash.now[:error]).to be nil
expect(flash.now[:success]).to eq('The review by "reviewer" for "reviewee" has been unsubmitted.')
expect(response).to render_template('unsubmit_review.js.erb')
end
end
context 'when attributes of response are not updated successfully' do
it 'shows an error flash.now message and renders a .js.erb file' do
allow(review_response).to receive(:update_attribute).with('is_submitted', false).and_return(false)
params = {id: 1}
# xhr - XmlHttpRequest (AJAX)
xhr :get, :unsubmit_review, params
expect(flash.now[:success]).to be nil
expect(flash.now[:error]).to eq('The review by "reviewer" for "reviewee" could not be unsubmitted.')
expect(response).to render_template('unsubmit_review.js.erb')
end
end
end
describe '#delete_reviewer' do
before(:each) do
allow(ReviewResponseMap).to receive(:find_by).with(id: '1').and_return(review_response_map)
request.env['HTTP_REFERER'] = 'www.google.com'
end
context 'when corresponding response does not exist to current review response map' do
it 'shows a success flash message and redirects to previous page' do
allow(Response).to receive(:exists?).with(map_id: 1).and_return(false)
allow(review_response_map).to receive(:destroy).and_return(true)
params = {id: 1}
post :delete_reviewer, params
expect(flash[:success]).to eq('The review mapping for "reviewee" and "reviewer" has been deleted.')
expect(flash[:error]).to be nil
expect(response).to redirect_to('www.google.com')
end
end
context 'when corresponding response exists to current review response map' do
it 'shows an error flash message and redirects to previous page' do
allow(Response).to receive(:exists?).with(map_id: 1).and_return(true)
allow(Response).to receive(:where).with(map_id: 1).and_return(response1)
params = {id: 1}
post :delete_reviewer, params
expect(flash[:error]).to eq('This reviewer has already started the review. Hence, it cannot been deleted.')
expect(flash[:success]).to be nil
expect(response).to redirect_to('www.google.com')
end
end
end
describe '#delete_metareviewer' do
before(:each) do
allow(MetareviewResponseMap).to receive(:find).with('1').and_return(metareview_response_map)
end
context 'when metareview_response_map can be deleted successfully' do
it 'show a note flash message and redirects to review_mapping#list_mappings page' do
allow(metareview_response_map).to receive(:delete).and_return(true)
params = {id: 1}
post :delete_metareviewer, params
expect(flash[:note]).to eq('The metareview mapping for reviewee and reviewer has been deleted.')
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
context 'when metareview_response_map cannot be deleted successfully' do
it 'show a note flash message and redirects to review_mapping#list_mappings page' do
allow(metareview_response_map).to receive(:delete).and_raise('Boom')
params = {id: 1}
post :delete_metareviewer, params
expect(flash[:error]).to eq("A delete action failed:<br/>Boom<a href='/review_mapping/delete_metareview/1'>Delete this mapping anyway>?")
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
end
describe '#delete_metareview' do
it 'redirects to review_mapping#list_mappings page after deletion' do
allow(MetareviewResponseMap).to receive(:find).with('1').and_return(metareview_response_map)
allow(metareview_response_map).to receive(:delete).and_return(true)
params = {id: 1}
post :delete_metareview, params
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
describe '#list_mappings' do
it 'renders review_mapping#list_mappings page' do
allow(AssignmentTeam).to receive(:where).with(parent_id: 1).and_return([team, team1])
params = {
id: 1,
msg: 'No error!'
}
get :list_mappings, params
expect(flash[:error]).to eq('No error!')
expect(response).to render_template(:list_mappings)
end
end
describe '#automatic_review_mapping' do
before(:each) do
allow(AssignmentParticipant).to receive(:where).with(parent_id: 1).and_return([participant, participant1, participant2])
end
context 'when teams is not empty' do
before(:each) do
allow(AssignmentTeam).to receive(:where).with(parent_id: 1).and_return([team, team1])
end
context 'when all nums in params are 0' do
it 'shows an error flash message and redirects to review_mapping#list_mappings page' do
params = {
id: 1,
max_team_size: 1,
num_reviews_per_student: 0,
num_reviews_per_submission: 0,
num_calibrated_artifacts: 0,
num_uncalibrated_artifacts: 0
}
post :automatic_review_mapping, params
expect(flash[:error]).to eq('Please choose either the number of reviews per student or the number of reviewers per team (student).')
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
context 'when all nums in params are 0 except student_review_num' do
it 'runs automatic review mapping strategy and redirects to review_mapping#list_mappings page' do
allow_any_instance_of(ReviewMappingController).to receive(:automatic_review_mapping_strategy).with(any_args).and_return(true)
params = {
id: 1,
max_team_size: 1,
num_reviews_per_student: 1,
num_reviews_per_submission: 0,
num_calibrated_artifacts: 0,
num_uncalibrated_artifacts: 0
}
post :automatic_review_mapping, params
expect(flash[:error]).to be nil
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
context 'when calibrated params are not 0' do
it 'runs automatic review mapping strategy and redirects to review_mapping#list_mappings page' do
allow(ReviewResponseMap).to receive(:where).with(reviewed_object_id: 1, calibrate_to: 1)
.and_return([double('ReviewResponseMap', reviewee_id: 2)])
allow(AssignmentTeam).to receive(:find).with(2).and_return(team)
allow_any_instance_of(ReviewMappingController).to receive(:automatic_review_mapping_strategy).with(any_args).and_return(true)
params = {
id: 1,
max_team_size: 1,
num_reviews_per_student: 1,
num_reviews_per_submission: 0,
num_calibrated_artifacts: 1,
num_uncalibrated_artifacts: 1
}
post :automatic_review_mapping, params
expect(flash[:error]).to be nil
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
context 'when student review num is greater than or equal to team size' do
it 'throws error stating that student review number cannot be greather than or equal to team size' do
allow(ReviewResponseMap).to receive(:where)
.with(reviewed_object_id: 1, calibrate_to: 1)
.and_return([double('ReviewResponseMap', reviewee_id: 2)])
allow(AssignmentTeam).to receive(:find).with(2).and_return(team)
params = {
id: 1,
max_team_size: 1,
num_reviews_per_student: 45,
num_reviews_per_submission: 0,
num_calibrated_artifacts: 0,
num_uncalibrated_artifacts: 0
}
post :automatic_review_mapping, params
expect(flash[:error]).to eq('You cannot set the number of reviews done ' \
'by each student to be greater than or equal to total number of teams ' \
'[or "participants" if it is an individual assignment].')
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
end
context 'when teams is empty, max team size is 1 and when review params are not 0' do
it 'shows an error flash message and redirects to review_mapping#list_mappings page' do
allow(TeamsUser).to receive(:team_id).with(1, 2).and_return(true)
allow(TeamsUser).to receive(:team_id).with(1, 3).and_return(false)
allow(AssignmentTeam).to receive(:create_team_and_node).with(1).and_return(double('AssignmentTeam', id: 1))
allow(ApplicationController).to receive_message_chain(:helpers, :create_team_users).with(no_args).with(user, 1).and_return(true)
params = {
id: 1,
max_team_size: 1,
num_reviews_per_student: 1,
num_reviews_per_submission: 4,
num_calibrated_artifacts: 0,
num_uncalibrated_artifacts: 0
}
post :automatic_review_mapping, params
expect(flash[:error]).to eq('Please choose either the number of reviews per student or the number of reviewers per team (student), not both.')
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
end
describe '#automatic_review_mapping_staggered' do
it 'shows a note flash message and redirects to review_mapping#list_mappings page' do
allow(assignment).to receive(:assign_reviewers_staggered).with('4', '2').and_return('Awesome!')
params = {
id: 1,
assignment: {
num_reviews: 4,
num_metareviews: 2
}
}
post :automatic_review_mapping_staggered, params
expect(flash[:note]).to eq('Awesome!')
expect(response).to redirect_to('/review_mapping/list_mappings?id=1')
end
end
describe '#save_grade_and_comment_for_reviewer' do
it 'redirects to reports#response_report page' do
review_grade = build(:review_grade)
allow(ReviewGrade).to receive(:find_by).with(participant_id: '1').and_return(review_grade)
allow(review_grade).to receive(:save).and_return(true)
params = {
participant_id: 1,
grade_for_reviewer: 90,
comment_for_reviewer: 'keke'
}
session = {user: double('User', id: 1)}
post :save_grade_and_comment_for_reviewer, params, session
expect(flash[:note]).to be nil
expect(response).to redirect_to('/reports/response_report')
end
end
describe '#start_self_review' do
before(:each) do
allow(Team).to receive(:find_team_for_assignment_and_user).with(1, '1').and_return([double('Team', id: 1)])
end
context 'when self review response map does not exist' do
it 'creates a new record and redirects to submitted_content#edit page' do
allow(SelfReviewResponseMap).to receive(:where).with(reviewee_id: 1, reviewer_id: '1').and_return([nil])
allow(SelfReviewResponseMap).to receive(:create).with(reviewee_id: 1, reviewer_id: '1', reviewed_object_id: 1).and_return(true)
params = {
assignment_id: 1,
reviewer_userid: 1,
reviewer_id: 1
}
post :start_self_review, params
expect(response).to redirect_to('/submitted_content/1/edit')
end
end
context 'when self review response map exists' do
it 'redirects to submitted_content#edit page' do
allow(SelfReviewResponseMap).to receive(:where).with(reviewee_id: 1, reviewer_id: '1').and_return([double('SelfReviewResponseMap')])
params = {
assignment_id: 1,
reviewer_userid: 1,
reviewer_id: 1
}
post :start_self_review, params
expect(response).to redirect_to('/submitted_content/1/edit?msg=Self+review+already+assigned%21')
end
end
end
end