forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmissions_controller_spec.rb
More file actions
763 lines (666 loc) · 35 KB
/
Copy pathsubmissions_controller_spec.rb
File metadata and controls
763 lines (666 loc) · 35 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
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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe SubmissionsController do
describe "POST create" do
it "should require authorization" do
course_with_student(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload")
post 'create', :course_id => @course.id, :assignment_id => @assignment.id, :submission => {:submission_type => "online_url", :url => "url"}
assert_unauthorized
end
it "should allow submitting homework" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload")
post 'create', :course_id => @course.id, :assignment_id => @assignment.id, :submission => {:submission_type => "online_url", :url => "url"}
expect(response).to be_redirect
expect(assigns[:submission]).not_to be_nil
expect(assigns[:submission].user_id).to eql(@user.id)
expect(assigns[:submission].assignment_id).to eql(@assignment.id)
expect(assigns[:submission].submission_type).to eql("online_url")
expect(assigns[:submission].url).to eql("http://url")
end
it "should allow submitting homework as attachments" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_upload")
att = attachment_model(:context => @user, :uploaded_data => stub_file_data('test.txt', 'asdf', 'text/plain'))
post 'create', :course_id => @course.id, :assignment_id => @assignment.id, :submission => {:submission_type => "online_upload", :attachment_ids => att.id}, :attachments => { "0" => { :uploaded_data => "" }, "-1" => { :uploaded_data => "" } }
expect(response).to be_redirect
expect(assigns[:submission]).not_to be_nil
expect(assigns[:submission].user_id).to eql(@user.id)
expect(assigns[:submission][:assignment_id].to_i).to eql(@assignment.id)
expect(assigns[:submission][:submission_type]).to eql("online_upload")
end
it "should copy attachments to the submissions folder if that feature is enabled" do
course_with_student_logged_in(:active_all => true)
@course.root_account.enable_feature! :submissions_folder
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_upload")
att = attachment_model(:context => @user, :uploaded_data => stub_file_data('test.txt', 'asdf', 'text/plain'))
post 'create', :course_id => @course.id, :assignment_id => @assignment.id, :submission => {:submission_type => "online_upload", :attachment_ids => att.id}, :attachments => { "0" => { :uploaded_data => "" }, "-1" => { :uploaded_data => "" } }
expect(response).to be_redirect
expect(assigns[:submission]).not_to be_nil
att_copy = Attachment.find(assigns[:submission].attachment_ids.to_i)
expect(att_copy).not_to eq att
expect(att_copy.root_attachment).to eq att
expect(att).not_to be_associated_with_submission
expect(att_copy).to be_associated_with_submission
end
it "should reject illegal file extensions from submission" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "an additional assignment", :submission_types => "online_upload", :allowed_extensions => ['txt'])
att = attachment_model(:context => @student, :uploaded_data => stub_file_data('test.m4v', 'asdf', 'video/mp4'))
post 'create', :course_id => @course.id, :assignment_id => @assignment.id, :submission => {:submission_type => "online_upload", :attachment_ids => att.id}, :attachments => { "0" => { :uploaded_data => "" }, "-1" => { :uploaded_data => "" } }
expect(response).to be_redirect
expect(assigns[:submission]).to be_nil
expect(flash[:error]).not_to be_nil
expect(flash[:error]).to match(/Invalid file type/)
end
it "should use the appropriate group based on the assignment's category and the current user" do
course_with_student_logged_in(:active_all => true)
group_category = @course.group_categories.create(:name => "Category")
@group = @course.groups.create(:name => "Group", :group_category => group_category)
@group.add_user(@user)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload", :group_category => @group.group_category)
post 'create', :course_id => @course.id, :assignment_id => @assignment.id, :submission => {:submission_type => "online_url", :url => "url"}
expect(response).to be_redirect
expect(assigns[:group]).not_to be_nil
expect(assigns[:group].id).to eql(@group.id)
end
it "should not use a group if the assignment has no category" do
course_with_student_logged_in(:active_all => true)
group_category = @course.group_categories.create(:name => "Category")
@group = @course.groups.create(:name => "Group", :group_category => group_category)
@group.add_user(@user)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload")
post 'create', :course_id => @course.id, :assignment_id => @assignment.id, :submission => {:submission_type => "online_url", :url => "url"}
expect(response).to be_redirect
expect(assigns[:group]).to be_nil
end
it "should allow attaching multiple files to the submission" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload")
att1 = attachment_model(:context => @user, :uploaded_data => fixture_file_upload("scribd_docs/doc.doc", "application/msword", true))
att2 = attachment_model(:context => @user, :uploaded_data => fixture_file_upload("scribd_docs/txt.txt", "application/vnd.ms-excel", true))
post 'create', :course_id => @course.id, :assignment_id => @assignment.id,
:submission => {:submission_type => "online_upload", :attachment_ids => [att1.id, att2.id].join(',')},
:attachments => {"0" => {:uploaded_data => "doc.doc"}, "1" => {:uploaded_data => "txt.txt"}}
expect(response).to be_redirect
expect(assigns[:submission]).not_to be_nil
expect(assigns[:submission].user_id).to eql(@user.id)
expect(assigns[:submission].assignment_id).to eql(@assignment.id)
expect(assigns[:submission].submission_type).to eql("online_upload")
expect(assigns[:submission].attachments).not_to be_empty
expect(assigns[:submission].attachments.length).to eql(2)
expect(assigns[:submission].attachments.map{|a| a.display_name}).to be_include("doc.doc")
expect(assigns[:submission].attachments.map{|a| a.display_name}).to be_include("txt.txt")
end
it "should fail but not raise when the submission is invalid" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url")
post 'create', :course_id => @course.id, :assignment_id => @assignment.id, :submission => {:submission_type => "online_url", :url => ""} # blank url not allowed
expect(response).to be_redirect
expect(flash[:error]).not_to be_nil
expect(assigns[:submission]).to be_nil
end
it "should strip leading/trailing whitespace off url submissions" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url")
post 'create', :course_id => @course.id, :assignment_id => @assignment.id, :submission => {:submission_type => "online_url", :url => " http://www.google.com "}
expect(response).to be_redirect
expect(assigns[:submission]).not_to be_nil
expect(assigns[:submission].url).to eql("http://www.google.com")
end
it 'must accept a basic_lti_launch url when any online submission type is allowed' do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => 'some assignment', :submission_types => 'online_url')
request.path = "/api/v1/courses/#{@course.id}/assignments/#{@assignment.id}/submissions"
post 'create', :course_id => @course.id, :assignment_id => @assignment.id, :submission => {:submission_type => 'basic_lti_launch', :url => 'http://www.google.com'}
expect(response).to be_redirect
expect(assigns[:submission]).not_to be_nil
expect(assigns[:submission].submission_type).to eq 'basic_lti_launch'
expect(assigns[:submission].url).to eq 'http://www.google.com'
end
it "should redirect to the assignment when locked in submit-at-deadline situation" do
enable_cache do
now = Time.now.utc
Timecop.freeze(now) do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(
:title => "some assignment",
:submission_types => "online_url",
:lock_at => now + 5.seconds
)
# cache permission as true (for 5 minutes)
expect(@assignment.grants_right?(@student, {}, :submit)).to be_truthy
end
# travel past due date (which resets the Assignment#locked_for? cache)
Timecop.freeze(now + 10.seconds) do
# now it's locked, but permission is cached, locked_for? is not
post 'create',
:course_id => @course.id,
:assignment_id => @assignment.id,
:submission => {
:submission_type => "online_url",
:url => " http://www.google.com "
}
expect(response).to be_redirect
end
end
end
describe 'when submitting a text response for the answer' do
let(:assignment) { @course.assignments.create!(:title => "some assignment", :submission_types => "online_text_entry") }
let(:submission_params) { {:submission_type => "online_text_entry", :body => "My Answer"} }
before do
Setting.set('enable_page_views', 'db')
course_with_student_logged_in :active_all => true
post 'create', :course_id => @course.id, :assignment_id => assignment.id, :submission => submission_params
end
after do
Setting.set('enable_page_views', 'false')
end
it 'should redirect me to the course assignment' do
expect(response).to be_redirect
end
it 'saves a submission object' do
submission = assigns[:submission]
expect(submission.id).not_to be_nil
expect(submission.user_id).to eq @user.id
expect(submission.body).to eq submission_params[:body]
end
it 'logs an asset access for the assignment' do
accessed_asset = assigns[:accessed_asset]
expect(accessed_asset[:level]).to eq 'submit'
end
it 'registers a page view' do
page_view = assigns[:page_view]
expect(page_view).not_to be_nil
expect(page_view.http_method).to eq 'post'
expect(page_view.url).to match %r{^http://test\.host/courses/\d+/assignments/\d+/submissions}
expect(page_view.participated).to be_truthy
end
end
it 'rejects an empty text response' do
course_with_student_logged_in(:active_all => true)
assignment = @course.assignments.create!(
:title => 'some assignment',
:submission_types => 'online_text_entry'
)
sub_params = { submission_type: 'online_text_entry', body: '' }
post 'create', {
:course_id => @course.id,
:assignment_id => assignment.id,
:submission => sub_params
}
expect(response).to be_redirect
expect(flash[:error]).not_to be_nil
expect(assigns[:submission]).to be_nil
end
it 'should build a pageview thats marked as participating' do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url")
end
context "group comments" do
before do
course_with_student_logged_in(:active_all => true)
@u1 = @user
student_in_course(:course => @course)
@u2 = @user
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_text_entry", :group_category => GroupCategory.create!(:name => "groups", :context => @course), :grade_group_students_individually => true)
@group = @assignment.group_category.groups.create!(:name => 'g1', :context => @course)
@group.users << @u1
@group.users << @user
end
it "should not send a comment to the entire group by default" do
post(
'create',
:course_id => @course.id,
:assignment_id => @assignment.id,
:submission => {
:submission_type => 'online_text_entry',
:body => 'blah',
:comment => "some comment"
}
)
subs = @assignment.submissions
expect(subs.size).to eq 2
expect(subs.to_a.sum{ |s| s.submission_comments.size }).to eql 1
end
it "should send a comment to the entire group if requested" do
post(
'create',
:course_id => @course.id,
:assignment_id => @assignment.id,
:submission => {
:submission_type => 'online_text_entry',
:body => 'blah',
:comment => "some comment",
:group_comment => '1'
}
)
subs = @assignment.submissions
expect(subs.size).to eq 2
expect(subs.to_a.sum{ |s| s.submission_comments.size }).to eql 2
end
end
context "google doc" do
before(:each) do
course_with_student_logged_in(active_all: true)
@student.stubs(:gmail).returns('student@does-not-match.com')
@assignment = @course.assignments.create!(title: 'some assignment', submission_types: 'online_upload')
account = Account.default
flag = FeatureFlag.new
account.settings[:google_docs_domain] = 'example.com'
account.save!
flag.context = account
flag.feature = 'google_docs_domain_restriction'
flag.state = 'on'
flag.save!
mock_user_service = mock()
@user.stubs(:user_services).returns(mock_user_service)
mock_user_service.expects(:where).with(service: "google_drive").
returns(stub(first: mock(token: "token", secret: "secret")))
end
it "should not save if domain restriction prevents it" do
google_docs = mock
GoogleDrive::Connection.expects(:new).returns(google_docs)
google_docs.expects(:download).returns([Net::HTTPOK.new(200, {}, ''), 'title', 'pdf'])
post(:create, course_id: @course.id, assignment_id: @assignment.id,
submission: { submission_type: 'google_doc' },
google_doc: { document_id: '12345' })
expect(response).to be_redirect
end
end
end
describe "PUT update" do
it "should require authorization" do
course_with_student(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload")
@submission = @assignment.submit_homework(@user)
put 'update', :course_id => @course.id, :assignment_id => @assignment.id, :id => @user.id, :submission => {:comment => "some comment"}
assert_unauthorized
end
it "should require the right student" do
course_with_student_logged_in(:active_all => true)
@user2 = User.create!(:name => "some user")
@course.enroll_user(@user2)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload")
@submission = @assignment.submit_homework(@user2)
put 'update', :course_id => @course.id, :assignment_id => @assignment.id, :id => @user2.id, :submission => {:comment => "some comment"}
assert_unauthorized
end
it "should allow updating homework to add comments" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload")
@submission = @assignment.submit_homework(@user)
put 'update', :course_id => @course.id, :assignment_id => @assignment.id, :id => @user.id, :submission => {:comment => "some comment"}
expect(response).to be_redirect
expect(assigns[:submission]).to eql(@submission)
expect(assigns[:submission].submission_comments.length).to eql(1)
expect(assigns[:submission].submission_comments[0].comment).to eql("some comment")
end
it "should allow a non-enrolled admin to add comments" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload")
@submission = @assignment.submit_homework(@user)
site_admin_user
user_session(@user)
put 'update', :course_id => @course.id, :assignment_id => @assignment.id, :id => @student.id, :submission => {:comment => "some comment"}
expect(response).to be_redirect
expect(assigns[:submission]).to eql(@submission)
expect(assigns[:submission].submission_comments.length).to eql(1)
expect(assigns[:submission].submission_comments[0].comment).to eql("some comment")
expect(assigns[:submission].submission_comments[0]).not_to be_hidden
end
it "should allow a non-enrolled admin to add comments on a submission to muted assignment" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload")
@submission = @assignment.submit_homework(@user)
@assignment.muted = true
@assignment.save!
site_admin_user
user_session(@user)
put 'update', :course_id => @course.id, :assignment_id => @assignment.id, :id => @student.id, :submission => {:comment => "some comment"}
expect(response).to be_redirect
expect(assigns[:submission]).to eql(@submission)
expect(assigns[:submission].submission_comments.length).to eql(1)
expect(assigns[:submission].submission_comments[0].comment).to eql("some comment")
expect(assigns[:submission].submission_comments[0]).to be_hidden
end
it "should comment as the current user for all submissions in the group" do
course_with_student_logged_in(:active_all => true)
@u1 = @user
student_in_course(:course => @course)
@u2 = @user
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload", :group_category => GroupCategory.create!(:name => "groups", :context => @course), :grade_group_students_individually => true)
@group = @assignment.group_category.groups.create!(:name => 'g1', :context => @course)
@group.users << @u1
@group.users << @user
put 'update', :course_id => @course.id, :assignment_id => @assignment.id, :id => @u1.id, :submission => {:comment => "some comment", :group_comment => '1'}
subs = @assignment.submissions
expect(subs.size).to eq 2
subs.each do |s|
expect(s.submission_comments.size).to eq 1
expect(s.submission_comments.first.author).to eq @u1
end
end
it "should allow attaching files to the comment" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment", :submission_types => "online_url,online_upload")
@submission = @assignment.submit_homework(@user)
data1 = fixture_file_upload("scribd_docs/doc.doc", "application/msword", true)
data2 = fixture_file_upload("scribd_docs/txt.txt", "text/plain", true)
put 'update', :course_id => @course.id, :assignment_id => @assignment.id, :id => @user.id, :submission => {:comment => "some comment"}, :attachments => {"0" => {:uploaded_data => data1}, "1" => {:uploaded_data => data2}}
expect(response).to be_redirect
expect(assigns[:submission]).to eql(@submission)
expect(assigns[:submission].submission_comments.length).to eql(1)
expect(assigns[:submission].submission_comments[0].comment).to eql("some comment")
expect(assigns[:submission].submission_comments[0].attachments.length).to eql(2)
expect(assigns[:submission].submission_comments[0].attachments.map{|a| a.display_name}).to be_include("doc.doc")
expect(assigns[:submission].submission_comments[0].attachments.map{|a| a.display_name}).to be_include("txt.txt")
end
describe 'allows a teacher to add draft comments to a submission' do
before(:each) do
course_with_teacher(active_all: true)
student_in_course
assignment = @course.assignments.create!(title: 'Assignment #1', submission_types: 'online_url,online_upload')
user_session(@teacher)
@test_params = {
course_id: @course.id,
assignment_id: assignment.id,
id: @student.id,
submission: {
comment: 'Comment #1',
}
}
end
it 'when draft_comment is true' do
test_params = @test_params
test_params[:submission][:draft_comment] = true
expect { put 'update', test_params }.to change { SubmissionComment.draft.count }.by(1)
end
it 'except when draft_comment is nil' do
test_params = @test_params
test_params[:submission].delete(:draft_comment)
expect { put 'update', test_params }.to change { SubmissionComment.count }.by(1)
expect { put 'update', test_params }.not_to change { SubmissionComment.draft.count }
end
it 'except when draft_comment is false' do
test_params = @test_params
test_params[:submission][:draft_comment] = false
expect { put 'update', test_params }.to change { SubmissionComment.count }.by(1)
expect { put 'update', test_params }.not_to change { SubmissionComment.draft.count }
end
end
it "should allow setting 'student_entered_grade'" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment",
:submission_types => "online_url,online_upload")
@submission = @assignment.submit_homework(@user)
put 'update', {
:course_id => @course.id,
:assignment_id => @assignment.id,
:id => @user.id,
:submission => {
:student_entered_score => '2'
}
}
expect(@submission.reload.student_entered_score).to eq 2.0
end
it "should round 'student_entered_grade'" do
course_with_student_logged_in(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment",
:submission_types => "online_url,online_upload")
@submission = @assignment.submit_homework(@user)
put 'update', {
:course_id => @course.id,
:assignment_id => @assignment.id,
:id => @user.id,
:submission => {
:student_entered_score => '2.0000000020'
}
}
expect(@submission.reload.student_entered_score).to eq 2.0
end
it 'changing student_entered_grade for a quiz does not change the workflow_state of a submission' do
course_with_student_logged_in(active_all: true)
assignment = @course.assignments.create!
assignment.workflow_state = :published
assignment.submission_types = :online_quiz
assignment.save!
quiz = Quizzes::Quiz.find_by(assignment_id: assignment)
quiz_submission = quiz.generate_submission(@user).complete!
quiz_submission.update_column(:workflow_state, :pending_review)
put(
:update,
course_id: @course.id,
assignment_id: assignment.id,
id: @user.id,
submission: { student_entered_score: 2 }
)
expect(quiz_submission.submission.reload).not_to be_pending_review
end
context "moderated grading" do
before :once do
course_with_student(:active_all => true)
@assignment = @course.assignments.create!(:title => "some assignment",
:submission_types => "online_url,online_upload", :moderated_grading => true)
@submission = @assignment.submit_homework(@user)
end
before :each do
user_session @teacher
end
it "should create a provisional comment" do
put 'update', :format => :json, :course_id => @course.id, :assignment_id => @assignment.id, :id => @user.id,
:submission => {:comment => "provisional!", :provisional => true}
@submission.reload
expect(@submission.submission_comments.first).to be_nil
expect(@submission.provisional_grade(@teacher).submission_comments.first.comment).to eq 'provisional!'
json = JSON.parse response.body
expect(json[0]['submission']['submission_comments'].first['submission_comment']['comment']).to eq 'provisional!'
end
it "should create a final provisional comment" do
@submission.find_or_create_provisional_grade!(@teacher)
put 'update', :format => :json, :course_id => @course.id, :assignment_id => @assignment.id, :id => @user.id,
:submission => {:comment => "provisional!", :provisional => true, :final => true}
expect(response).to be_success
@submission.reload
expect(@submission.submission_comments.first).to be_nil
pg = @submission.provisional_grade(@teacher, final: true)
expect(pg.submission_comments.first.comment).to eq 'provisional!'
expect(pg.final).to be_truthy
json = JSON.parse response.body
expect(json[0]['submission']['submission_comments'].first['submission_comment']['comment']).to eq 'provisional!'
end
end
end
describe "GET zip" do
it "should zip and download" do
course_with_student_and_submitted_homework
get 'index', :course_id => @course.id, :assignment_id => @assignment.id, :zip => '1', :format => 'json'
expect(response).to be_success
a = Attachment.last
expect(a.user).to eq @teacher
expect(a.workflow_state).to eq 'to_be_zipped'
a.update_attribute('workflow_state', 'zipped')
a.stubs('full_filename').returns(File.expand_path(__FILE__)) # just need a valid file
a.stubs('content_type').returns('test/file')
Attachment.stubs(:instantiate).returns(a)
get 'index', { :course_id => @course.id, :assignment_id => @assignment.id, :zip => '1' }, 'HTTP_ACCEPT' => '*/*'
expect(response).to be_success
expect(response.content_type).to eq 'test/file'
end
end
describe "GET show" do
before do
course_with_student_and_submitted_homework
@context = @course
user_session(@teacher)
end
it "renders show template" do
get :show, course_id: @context.id, assignment_id: @assignment.id, id: @student.id
expect(response).to render_template(:show)
end
it "renders json" do
request.accept = Mime[:json].to_s
get :show, course_id: @context.id, assignment_id: @assignment.id, id: @student.id, format: :json
expect(JSON.parse(response.body)['submission']['id']).to eq @submission.id
end
context "with user id not present in course" do
before(:once) do
course_with_student(active_all: true)
end
it "sets flash error" do
get :show, course_id: @context.id, assignment_id: @assignment.id, id: @student.id
expect(flash[:error]).not_to be_nil
end
it "should redirect to context assignment url" do
get :show, course_id: @context.id, assignment_id: @assignment.id, id: @student.id
expect(response).to redirect_to(course_assignment_url(@context, @assignment))
end
end
it "should not expose muted assignment's scores" do
get "show", :id => @submission.to_param, :assignment_id => @assignment.to_param, :course_id => @course.to_param
expect(response).to be_success
%w(score published_grade published_score grade).each do |secret_attr|
expect(assigns[:submission].send(secret_attr)).to be_nil
end
end
it "should show rubric assessments to peer reviewers" do
course_with_student(active_all: true)
@assessor = @student
outcome_with_rubric
@association = @rubric.associate_with @assignment, @context, :purpose => 'grading'
@assignment.assign_peer_review(@assessor, @submission.user)
@assessment = @association.assess(:assessor => @assessor, :user => @submission.user, :artifact => @submission, :assessment => { :assessment_type => 'grading'})
user_session(@assessor)
get "show", :id => @submission.user.id, :assignment_id => @assignment.id, :course_id => @context.id
expect(response).to be_success
expect(assigns[:visible_rubric_assessments]).to eq [@assessment]
end
end
context 'originality report' do
let(:test_course) do
test_course = course_factory(active_course: true)
test_course.enroll_teacher(test_teacher, enrollment_state: 'active')
test_course.enroll_student(test_student, enrollment_state: 'active')
test_course
end
let(:test_teacher) { User.create }
let(:test_student) { User.create }
let(:assignment) { Assignment.create!(title: 'test assignment', context: test_course) }
let(:attachment) { attachment_model(filename: "submission.doc", context: test_student) }
let(:submission) { assignment.submit_homework(test_student, attachments: [attachment]) }
let!(:originality_report) do
OriginalityReport.create!(attachment: attachment,
submission: submission,
originality_score: 0.5,
originality_report_url: 'http://www.instructure.com')
end
before :each do
user_session(test_teacher)
end
describe 'GET originality_report' do
it 'redirects to the originality report URL if it exists' do
get 'originality_report', course_id: assignment.context_id, assignment_id: assignment.id, submission_id: test_student.id, asset_string: attachment.asset_string
expect(response).to redirect_to originality_report.originality_report_url
end
it 'returns 400 if submission_id is not integer' do
get 'originality_report', :course_id => assignment.context_id, :assignment_id => assignment.id, :submission_id => '{{ user_id }}', :asset_string => attachment.asset_string
expect(response.response_code).to eq 400
end
it "returns unauthorized for users who can't read submission" do
unauthorized_user = User.create
user_session(unauthorized_user)
get 'originality_report', course_id: assignment.context_id, assignment_id: assignment.id, submission_id: test_student.id, asset_string: attachment.asset_string
expect(response.status).to eq 401
end
it 'gives error if no url is present for the OriginalityReport' do
originality_report.update_attribute(:originality_report_url, nil)
get 'originality_report', course_id: assignment.context_id, assignment_id: assignment.id, submission_id: test_student.id, asset_string: attachment.asset_string
expect(flash[:notice]).to be_present
end
end
describe 'POST resubmit_to_turnitin' do
it 'returns 400 if submission_id is not integer' do
assignment = assignment_model
post 'resubmit_to_turnitin', :course_id => assignment.context_id, :assignment_id => assignment.id, :submission_id => '{{ user_id }}'
expect(response.response_code).to eq 400
end
it "emits a 'plagiarism_resubmit' live event if originality report exists" do
submission.attachments << attachment
submission.save!
expect(Canvas::LiveEvents).to receive(:plagiarism_resubmit)
post 'resubmit_to_turnitin', course_id: assignment.context_id, assignment_id: assignment.id, submission_id: test_student.id
end
it "emits a 'plagiarism_resubmit' live event if originality report does not exists" do
originality_report.destroy
submission.attachments << attachment
submission.save!
expect(Canvas::LiveEvents).to receive(:plagiarism_resubmit)
post 'resubmit_to_turnitin', course_id: assignment.context_id, assignment_id: assignment.id, submission_id: test_student.id
end
end
describe 'POST resubmit_to_vericite' do
it "emits a 'plagiarism_resubmit' live event" do
submission.attachments << attachment
submission.save!
expect(Canvas::LiveEvents).to receive(:plagiarism_resubmit)
post 'resubmit_to_vericite', course_id: assignment.context_id, assignment_id: assignment.id, submission_id: test_student.id
end
end
end
describe 'GET turnitin_report' do
it 'returns 400 if submission_id is not integer' do
assignment = assignment_model
get 'turnitin_report', :course_id => assignment.context_id, :assignment_id => assignment.id, :submission_id => '{{ user_id }}', :asset_string => '123'
expect(response.response_code).to eq 400
end
end
describe "copy_attachments_to_submissions_folder" do
before(:once) do
course_with_student
attachment_model(context: @student)
end
it "copies a user attachment into the user's submissions folder" do
atts = SubmissionsController.copy_attachments_to_submissions_folder(@course, [@attachment])
expect(atts.length).to eq 1
expect(atts[0]).not_to eq @attachment
expect(atts[0].folder).to eq @student.submissions_folder(@course)
end
it "leaves files already in submissions folders alone" do
@attachment.folder = @student.submissions_folder(@course)
@attachment.save!
atts = SubmissionsController.copy_attachments_to_submissions_folder(@course, [@attachment])
expect(atts).to eq [@attachment]
end
it "copies a group attachment into the group submission folder" do
group_model(context: @course)
attachment_model(context: @group)
atts = SubmissionsController.copy_attachments_to_submissions_folder(@course, [@attachment])
expect(atts.length).to eq 1
expect(atts[0]).not_to eq @attachment
expect(atts[0].folder).to eq @group.submissions_folder
end
it "leaves files in non user/group context alone" do
assignment_model(context: @course)
weird_file = @assignment.attachments.create! display_name: 'blah', uploaded_data: default_uploaded_data
atts = SubmissionsController.copy_attachments_to_submissions_folder(@course, [weird_file])
expect(atts).to eq [weird_file]
end
end
end