forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgradebooks_controller_spec.rb
More file actions
1141 lines (978 loc) · 43.6 KB
/
Copy pathgradebooks_controller_spec.rb
File metadata and controls
1141 lines (978 loc) · 43.6 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
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# encoding: utf-8
#
# Copyright (C) 2011 - present 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 GradebooksController do
before :once do
course_with_teacher active_all: true
@teacher_enrollment = @enrollment
student_in_course active_all: true
@student_enrollment = @enrollment
user_factory(active_all: true)
@observer = @user
@oe = @course.enroll_user(@user, 'ObserverEnrollment')
@oe.accept
@oe.update_attribute(:associated_user_id, @student.id)
end
it "uses GradebooksController" do
expect(controller).to be_an_instance_of(GradebooksController)
end
describe "GET 'grade_summary'" do
it "redirects to the login page if the user is logged out" do
get 'grade_summary', :course_id => @course.id, :id => @student.id
expect(response).to redirect_to(login_url)
expect(flash[:warning]).to be_present
end
it "redirects teacher to gradebook" do
user_session(@teacher)
get 'grade_summary', :course_id => @course.id, :id => nil
expect(response).to redirect_to(:action => 'show')
end
it "renders for current user" do
user_session(@student)
get 'grade_summary', :course_id => @course.id, :id => nil
expect(response).to render_template('grade_summary')
end
it "does not allow access for inactive enrollment" do
user_session(@student)
@student_enrollment.deactivate
get 'grade_summary', :course_id => @course.id, :id => nil
assert_unauthorized
end
it "renders with specified user_id" do
user_session(@student)
get 'grade_summary', :course_id => @course.id, :id => @student.id
expect(response).to render_template('grade_summary')
expect(assigns[:presenter].courses_with_grades).not_to be_nil
end
it "does not allow access for wrong user" do
user_factory(active_all: true)
user_session(@user)
get 'grade_summary', :course_id => @course.id, :id => nil
assert_unauthorized
get 'grade_summary', :course_id => @course.id, :id => @student.id
assert_unauthorized
end
it "allows access for a linked observer" do
user_session(@observer)
get 'grade_summary', :course_id => @course.id, :id => @student.id
expect(response).to render_template('grade_summary')
expect(assigns[:courses_with_grades]).to be_nil
end
it "does not allow access for a linked student" do
user_factory(active_all: true)
user_session(@user)
@se = @course.enroll_student(@user)
@se.accept
@se.update_attribute(:associated_user_id, @student.id)
@user.reload
get 'grade_summary', :course_id => @course.id, :id => @student.id
assert_unauthorized
end
it "does not allow access for an observer linked in a different course" do
@course1 = @course
course_factory(active_all: true)
@course2 = @course
user_session(@observer)
get 'grade_summary', :course_id => @course2.id, :id => @student.id
assert_unauthorized
end
it "allows concluded teachers to see a student grades pages" do
user_session(@teacher)
@teacher_enrollment.conclude
get 'grade_summary', :course_id => @course.id, :id => @student.id
expect(response).to be_success
expect(response).to render_template('grade_summary')
expect(assigns[:courses_with_grades]).to be_nil
end
it "allows concluded students to see their grades pages" do
user_session(@student)
@student_enrollment.conclude
get 'grade_summary', :course_id => @course.id, :id => @student.id
expect(response).to render_template('grade_summary')
end
it "gives a student the option to switch between courses" do
pseudonym(@teacher, :username => 'teacher@example.com')
pseudonym(@student, :username => 'student@example.com')
course_with_teacher(:user => @teacher, :active_all => 1)
student_in_course :user => @student, :active_all => 1
user_session(@student)
get 'grade_summary', :course_id => @course.id, :id => @student.id
expect(response).to be_success
expect(assigns[:presenter].courses_with_grades).not_to be_nil
expect(assigns[:presenter].courses_with_grades.length).to eq 2
end
it "does not give a teacher the option to switch between courses when viewing a student's grades" do
pseudonym(@teacher, :username => 'teacher@example.com')
pseudonym(@student, :username => 'student@example.com')
course_with_teacher(:user => @teacher, :active_all => 1)
student_in_course :user => @student, :active_all => 1
user_session(@teacher)
get 'grade_summary', :course_id => @course.id, :id => @student.id
expect(response).to be_success
expect(assigns[:courses_with_grades]).to be_nil
end
it "does not give a linked observer the option to switch between courses when viewing a student's grades" do
pseudonym(@teacher, :username => 'teacher@example.com')
pseudonym(@student, :username => 'student@example.com')
user_with_pseudonym(:username => 'parent@example.com', :active_all => 1)
course1 = @course
course2 = course_with_teacher(:user => @teacher, :active_all => 1).course
student_in_course :user => @student, :active_all => 1
oe = course2.enroll_user(@observer, 'ObserverEnrollment')
oe.associated_user = @student
oe.save!
oe.accept
user_session(@observer)
get 'grade_summary', :course_id => course1.id, :id => @student.id
expect(response).to be_success
expect(assigns[:courses_with_grades]).to be_nil
end
it "assigns assignment group values for grade calculator to ENV" do
user_session(@teacher)
get 'grade_summary', :course_id => @course.id, :id => @student.id
expect(assigns[:js_env][:submissions]).not_to be_nil
expect(assigns[:js_env][:assignment_groups]).not_to be_nil
end
it "does not include assignment discussion information in grade calculator ENV data" do
user_session(@teacher)
assignment1 = @course.assignments.create(:title => "Assignment 1")
assignment1.submission_types = "discussion_topic"
assignment1.save!
get 'grade_summary', :course_id => @course.id, :id => @student.id
expect(assigns[:js_env][:assignment_groups].first[:assignments].first["discussion_topic"]).to be_nil
end
it "includes muted assignments" do
user_session(@student)
assignment = @course.assignments.create!(title: "Example Assignment")
assignment.mute!
get 'grade_summary', course_id: @course.id, id: @student.id
expect(assigns[:js_env][:assignment_groups].first[:assignments].size).to eq 1
expect(assigns[:js_env][:assignment_groups].first[:assignments].first[:muted]).to eq true
end
it "does not leak muted scores" do
user_session(@student)
a1, a2 = 2.times.map { |i|
@course.assignments.create! name: "blah#{i}", points_possible: 10
}
a1.mute!
a1.grade_student(@student, grade: 10, grader: @teacher)
a2.grade_student(@student, grade: 5, grader: @teacher)
get 'grade_summary', course_id: @course.id, id: @student.id
expected =
expect(assigns[:js_env][:submissions].sort_by { |s|
s['assignment_id']
}).to eq [
{score: 5, assignment_id: a2.id, excused: false, workflow_state: 'graded'}
]
end
it "includes necessary attributes on the submissions" do
user_session(@student)
assignment = @course.assignments.create!(points_possible: 10)
assignment.grade_student(@student, grade: 10, grader: @teacher)
get('grade_summary', course_id: @course.id, id: @student.id)
submission = assigns[:js_env][:submissions].first
expect(submission).to include :excused
expect(submission).to include :workflow_state
end
context "assignment sorting" do
let!(:teacher_session) { user_session(@teacher) }
let!(:assignment1) { @course.assignments.create(title: "Banana", position: 2) }
let!(:assignment2) { @course.assignments.create(title: "Apple", due_at: 3.days.from_now, position: 3) }
let!(:assignment3) do
assignment_group = @course.assignment_groups.create!(position: 2)
@course.assignments.create!(
assignment_group: assignment_group, title: "Carrot", due_at: 2.days.from_now, position: 1
)
end
let(:assignment_ids) { assigns[:presenter].assignments.select{ |a| a.class == Assignment }.map(&:id) }
it "sorts assignments by due date (null last), then title if there is no saved order preference" do
get 'grade_summary', course_id: @course.id, id: @student.id
expect(assignment_ids).to eq [assignment3, assignment2, assignment1].map(&:id)
end
it "sort order of 'due_at' sorts by due date (null last), then title" do
@teacher.preferences[:course_grades_assignment_order] = { @course.id => :due_at }
@teacher.save!
get 'grade_summary', course_id: @course.id, id: @student.id
expect(assignment_ids).to eq [assignment3, assignment2, assignment1].map(&:id)
end
context "sort by: title" do
let!(:teacher_setup) do
@teacher.preferences[:course_grades_assignment_order] = { @course.id => :title }
@teacher.save!
end
it "sorts assignments by title" do
get 'grade_summary', course_id: @course.id, id: @student.id
expect(assignment_ids).to eq [assignment2, assignment1, assignment3].map(&:id)
end
it "ingores case" do
assignment1.title = 'banana'
assignment1.save!
get 'grade_summary', course_id: @course.id, id: @student.id
expect(assignment_ids).to eq [assignment2, assignment1, assignment3].map(&:id)
end
end
it "sort order of 'assignment_group' sorts by assignment group position, then assignment position" do
@teacher.preferences[:course_grades_assignment_order] = { @course.id => :assignment_group }
@teacher.save!
get 'grade_summary', course_id: @course.id, id: @student.id
expect(assignment_ids).to eq [assignment1, assignment2, assignment3].map(&:id)
end
context "sort by: module" do
let!(:first_context_module) { @course.context_modules.create! }
let!(:second_context_module) { @course.context_modules.create! }
let!(:assignment1_tag) do
a1_tag = assignment1.context_module_tags.new(context: @course, position: 1, tag_type: 'context_module')
a1_tag.context_module = second_context_module
a1_tag.save!
end
let!(:assignment2_tag) do
a2_tag = assignment2.context_module_tags.new(context: @course, position: 3, tag_type: 'context_module')
a2_tag.context_module = first_context_module
a2_tag.save!
end
let!(:assignment3_tag) do
a3_tag = assignment3.context_module_tags.new(context: @course, position: 2, tag_type: 'context_module')
a3_tag.context_module = first_context_module
a3_tag.save!
end
let!(:teacher_setup) do
@teacher.preferences[:course_grades_assignment_order] = { @course.id => :module }
@teacher.save!
end
it "sorts by module position, then context module tag position" do
get 'grade_summary', course_id: @course.id, id: @student.id
expect(assignment_ids).to eq [assignment3, assignment2, assignment1].map(&:id)
end
it "sorts by module position, then context module tag position, " \
"with those not belonging to a module sorted last" do
assignment3.context_module_tags.first.destroy!
get 'grade_summary', course_id: @course.id, id: @student.id
expect(assignment_ids).to eq [assignment2, assignment1, assignment3].map(&:id)
end
end
end
context "with grading periods" do
let(:group_helper) { Factories::GradingPeriodGroupHelper.new }
let(:period_helper) { Factories::GradingPeriodHelper.new }
before :once do
@grading_period_group = group_helper.create_for_account(@course.root_account, weighted: true)
term = @course.enrollment_term
term.grading_period_group = @grading_period_group
term.save!
@grading_periods = period_helper.create_presets_for_group(@grading_period_group, :past, :current, :future)
end
it "does not display totals if 'All Grading Periods' is selected" do
user_session(@student)
all_grading_periods_id = 0
get 'grade_summary', :course_id => @course.id, :id => @student.id, grading_period_id: all_grading_periods_id
expect(assigns[:exclude_total]).to eq true
end
it "assigns grading period values for grade calculator to ENV" do
user_session(@teacher)
all_grading_periods_id = 0
get 'grade_summary', :course_id => @course.id, :id => @student.id, grading_period_id: all_grading_periods_id
expect(assigns[:js_env][:submissions]).not_to be_nil
expect(assigns[:js_env][:grading_periods]).not_to be_nil
end
it "displays totals if any grading period other than 'All Grading Periods' is selected" do
user_session(@student)
get 'grade_summary', :course_id => @course.id, :id => @student.id, grading_period_id: 1
expect(assigns[:exclude_total]).to eq false
end
it "includes the grading period group (as 'set') in the ENV" do
user_session(@teacher)
get :grade_summary, { course_id: @course.id, id: @student.id }
grading_period_set = assigns[:js_env][:grading_period_set]
expect(grading_period_set[:id]).to eq @grading_period_group.id
end
it "includes grading periods within the group" do
user_session(@teacher)
get :grade_summary, { course_id: @course.id, id: @student.id }
grading_period_set = assigns[:js_env][:grading_period_set]
expect(grading_period_set[:grading_periods].count).to eq 3
period = grading_period_set[:grading_periods][0]
expect(period).to have_key(:is_closed)
expect(period).to have_key(:is_last)
end
it "includes necessary keys with each grading period" do
user_session(@teacher)
get :grade_summary, { course_id: @course.id, id: @student.id }
periods = assigns[:js_env][:grading_period_set][:grading_periods]
periods.each do |period|
expect(period).to have_key(:id)
expect(period).to have_key(:start_date)
expect(period).to have_key(:end_date)
expect(period).to have_key(:close_date)
expect(period).to have_key(:is_closed)
expect(period).to have_key(:is_last)
end
end
end
context "with assignment due date overrides" do
before :once do
@assignment = @course.assignments.create(:title => "Assignment 1")
@due_at = 4.days.from_now
end
def check_grades_page(due_at)
[@student, @teacher, @observer].each do |u|
controller.js_env.clear
user_session(u)
get 'grade_summary', :course_id => @course.id, :id => @student.id
assignment_due_at = assigns[:presenter].assignments.find{|a| a.class == Assignment}.due_at
expect(assignment_due_at.to_i).to eq due_at.to_i
end
end
it "reflects section overrides" do
section = @course.default_section
override = assignment_override_model(:assignment => @assignment)
override.set = section
override.override_due_at(@due_at)
override.save!
check_grades_page(@due_at)
end
it "shows the latest section override in student view" do
section = @course.default_section
override = assignment_override_model(:assignment => @assignment)
override.set = section
override.override_due_at(@due_at)
override.save!
section2 = @course.course_sections.create!
override2 = assignment_override_model(:assignment => @assignment)
override2.set = section2
override2.override_due_at(@due_at - 1.day)
override2.save!
user_session(@teacher)
@fake_student = @course.student_view_student
session[:become_user_id] = @fake_student.id
get 'grade_summary', :course_id => @course.id, :id => @fake_student.id
assignment_due_at = assigns[:presenter].assignments.find{|a| a.class == Assignment}.due_at
expect(assignment_due_at.to_i).to eq @due_at.to_i
end
it "reflects group overrides when student is a member" do
@assignment.group_category = group_category
@assignment.save!
group = @assignment.group_category.groups.create!(:context => @course)
group.add_user(@student)
override = assignment_override_model(:assignment => @assignment)
override.set = group
override.override_due_at(@due_at)
override.save!
check_grades_page(@due_at)
end
it "does not reflect group overrides when student is not a member" do
@assignment.group_category = group_category
@assignment.save!
group = @assignment.group_category.groups.create!(:context => @course)
override = assignment_override_model(:assignment => @assignment)
override.set = group
override.override_due_at(@due_at)
override.save!
check_grades_page(nil)
end
it "reflects ad-hoc overrides" do
override = assignment_override_model(:assignment => @assignment)
override.override_due_at(@due_at)
override.save!
override_student = override.assignment_override_students.build
override_student.user = @student
override_student.save!
check_grades_page(@due_at)
end
it "uses the latest override" do
section = @course.default_section
override = assignment_override_model(:assignment => @assignment)
override.set = section
override.override_due_at(@due_at)
override.save!
override = assignment_override_model(:assignment => @assignment)
override.override_due_at(@due_at + 1.day)
override.save!
override_student = override.assignment_override_students.build
override_student.user = @student
override_student.save!
check_grades_page(@due_at + 1.day)
end
end
it "raises an exception on a non-integer :id" do
user_session(@teacher)
assert_page_not_found do
get 'grade_summary', :course_id => @course.id, :id => "lqw"
end
end
end
describe "GET 'show'" do
context "as an admin" do
it "renders successfully" do
account_admin_user(account: @course.root_account)
user_session(@admin)
get "show", :course_id => @course.id
expect(response).to render_template("gradebook")
end
end
describe 'js_env' do
before :each do
user_session(@teacher)
end
it "includes colors" do
get :show, course_id: @course.id
gradebook_options = controller.js_env.fetch(:GRADEBOOK_OPTIONS)
expect(gradebook_options).to have_key :colors
end
end
describe "csv" do
before :once do
@course.assignments.create(:title => "Assignment 1")
@course.assignments.create(:title => "Assignment 2")
end
before :each do
user_session(@teacher)
end
shared_examples_for "working download" do
it "does not recompute enrollment grades" do
Enrollment.expects(:recompute_final_score).never
get 'show', :course_id => @course.id, :init => 1, :assignments => 1, :format => 'csv'
end
it "should get all the expected datas even with multibytes characters", :focus => true do
@course.assignments.create(:title => "Déjà vu")
exporter = GradebookExporter.new(
@course,
@teacher,
{ include_sis_id: true }
)
raw_csv = exporter.to_csv
expect(raw_csv).to include("Déjà vu")
end
end
context "with teacher that prefers Grid View" do
before do
@user.preferences[:gradebook_version] = "2"
end
include_examples "working download"
end
context "with teacher that prefers Individual View" do
before do
@user.preferences[:gradebook_version] = "srgb"
end
include_examples "working download"
end
end
context "Individual View" do
before do
user_session(@teacher)
end
it "redirects to Grid View with a friendly URL" do
@teacher.preferences[:gradebook_version] = "2"
get "show", :course_id => @course.id
expect(response).to render_template("gradebook")
end
it "redirects to Individual View with a friendly URL" do
@teacher.preferences[:gradebook_version] = "srgb"
get "show", :course_id => @course.id
expect(response).to render_template("screenreader")
end
it "requests groups without wiki_page assignments" do
get "show", :course_id => @course.id
url = controller.js_env[:GRADEBOOK_OPTIONS][:assignment_groups_url]
expect(URI.unescape(url)).to include 'exclude_assignment_submission_types[]=wiki_page'
end
end
it "renders the unauthorized page without gradebook authorization" do
get "show", :course_id => @course.id
assert_unauthorized
end
context 'includes data needed by the Gradebook Action menu in ENV' do
before do
user_session(@teacher)
get 'show', course_id: @course.id
@gradebook_env = assigns[:js_env][:GRADEBOOK_OPTIONS]
end
it 'includes the context_allows_gradebook_uploads key in ENV' do
actual_value = @gradebook_env[:context_allows_gradebook_uploads]
expected_value = @course.allows_gradebook_uploads?
expect(actual_value).to eq(expected_value)
end
it 'includes the gradebook_import_url key in ENV' do
actual_value = @gradebook_env[:gradebook_import_url]
expected_value = new_course_gradebook_upload_path(@course)
expect(actual_value).to eq(expected_value)
end
it "includes the context_modules_url in the ENV" do
expect(@gradebook_env[:context_modules_url]).to eq(api_v1_course_context_modules_url(@course))
end
end
context "includes student context card info in ENV" do
before { user_session(@teacher) }
it "includes context_id" do
get :show, course_id: @course.id
context_id = assigns[:js_env][:GRADEBOOK_OPTIONS][:context_id]
expect(context_id).to eq @course.id.to_param
end
it "doesn't enable context cards when feature is off" do
get :show, course_id: @course.id
expect(assigns[:js_env][:STUDENT_CONTEXT_CARDS_ENABLED]).to eq false
end
it "enables context cards when feature is on" do
@course.root_account.enable_feature! :student_context_cards
get :show, course_id: @course.id
expect(assigns[:js_env][:STUDENT_CONTEXT_CARDS_ENABLED]).to eq true
end
end
context "includes relevant account settings in ENV" do
before { user_session(@teacher) }
let(:custom_login_id) { 'FOOBAR' }
it 'includes login_handle_name' do
@course.account.update!(login_handle_name: custom_login_id)
get :show, course_id: @course.id
login_handle_name = assigns[:js_env][:GRADEBOOK_OPTIONS][:login_handle_name]
expect(login_handle_name).to eq(custom_login_id)
end
end
context "with grading periods" do
let(:group_helper) { Factories::GradingPeriodGroupHelper.new }
let(:period_helper) { Factories::GradingPeriodHelper.new }
before :once do
@grading_period_group = group_helper.create_for_account(@course.root_account)
term = @course.enrollment_term
term.grading_period_group = @grading_period_group
term.save!
@grading_periods = period_helper.create_presets_for_group(@grading_period_group, :past, :current, :future)
end
before { user_session(@teacher) }
it "includes the grading period group (as 'set') in the ENV" do
get :show, { course_id: @course.id }
grading_period_set = assigns[:js_env][:GRADEBOOK_OPTIONS][:grading_period_set]
expect(grading_period_set[:id]).to eq @grading_period_group.id
end
it "includes grading periods within the group" do
get :show, { course_id: @course.id }
grading_period_set = assigns[:js_env][:GRADEBOOK_OPTIONS][:grading_period_set]
expect(grading_period_set[:grading_periods].count).to eq 3
period = grading_period_set[:grading_periods][0]
expect(period).to have_key(:is_closed)
expect(period).to have_key(:is_last)
end
it "includes necessary keys with each grading period" do
get :show, { course_id: @course.id }
periods = assigns[:js_env][:GRADEBOOK_OPTIONS][:grading_period_set][:grading_periods]
periods.each do |period|
expect(period).to have_key(:id)
expect(period).to have_key(:start_date)
expect(period).to have_key(:end_date)
expect(period).to have_key(:close_date)
expect(period).to have_key(:is_closed)
expect(period).to have_key(:is_last)
end
end
end
end
describe "GET 'change_gradebook_version'" do
it 'switches to gradebook if clicked' do
user_session(@teacher)
get 'grade_summary', :course_id => @course.id, :id => nil
expect(response).to redirect_to(:action => 'show')
# tell it to use gradebook 2
get 'change_gradebook_version', :course_id => @course.id, :version => 2
expect(response).to redirect_to(:action => 'show')
end
end
describe "POST 'submissions_zip_upload'" do
it "requires authentication" do
course_factory
assignment_model
post 'submissions_zip_upload', :course_id => @course.id, :assignment_id => @assignment.id, :submissions_zip => 'dummy'
assert_unauthorized
end
end
describe "POST 'update_submission'" do
it "allows adding comments for submission" do
user_session(@teacher)
@assignment = @course.assignments.create!(:title => "some assignment")
@student = @course.enroll_user(User.create!(:name => "some user"))
post 'update_submission', :course_id => @course.id, :submission =>
{:comment => "some comment",:assignment_id => @assignment.id, :user_id => @student.user_id}
expect(response).to be_redirect
expect(assigns[:assignment]).to eql(@assignment)
expect(assigns[:submissions]).not_to be_nil
expect(assigns[:submissions].length).to eql(1)
expect(assigns[:submissions][0].submission_comments).not_to be_nil
expect(assigns[:submissions][0].submission_comments[0].comment).to eql("some comment")
end
it "allows attaching files to comments for submission" do
user_session(@teacher)
@assignment = @course.assignments.create!(:title => "some assignment")
@student = @course.enroll_user(User.create!(:name => "some user"))
data = fixture_file_upload("scribd_docs/doc.doc", "application/msword", true)
post 'update_submission',
:course_id => @course.id,
:attachments => { "0" => { :uploaded_data => data } },
:submission => { :comment => "some comment",
:assignment_id => @assignment.id,
:user_id => @student.user_id }
expect(response).to be_redirect
expect(assigns[:assignment]).to eql(@assignment)
expect(assigns[:submissions]).not_to be_nil
expect(assigns[:submissions].length).to eql(1)
expect(assigns[:submissions][0].submission_comments).not_to be_nil
expect(assigns[:submissions][0].submission_comments[0].comment).to eql("some comment")
expect(assigns[:submissions][0].submission_comments[0].attachments.length).to eql(1)
expect(assigns[:submissions][0].submission_comments[0].attachments[0].display_name).to eql("doc.doc")
end
it "does not allow updating submissions for concluded courses" do
user_session(@teacher)
@teacher_enrollment.complete
@assignment = @course.assignments.create!(:title => "some assignment")
@student = @course.enroll_user(User.create!(:name => "some user"))
post 'update_submission',
:course_id => @course.id,
:submission => { :comment => "some comment",
:assignment_id => @assignment.id,
:user_id => @student.user_id }
assert_unauthorized
end
it "does not allow updating submissions in other sections when limited" do
user_session(@teacher)
@teacher_enrollment.update_attribute(:limit_privileges_to_course_section, true)
s1 = submission_model(:course => @course)
s2 = submission_model(:course => @course,
:username => 'otherstudent@example.com',
:section => @course.course_sections.create(:name => "another section"),
:assignment => @assignment)
post 'update_submission',
:course_id => @course.id,
:submission => { :comment => "some comment",
:assignment_id => @assignment.id,
:user_id => s1.user_id }
expect(response).to be_redirect
# attempt to grade another section throws not found
post 'update_submission',
:course_id => @course.id,
:submission => { :comment => "some comment",
:assignment_id => @assignment.id,
:user_id => s2.user_id }
expect(flash[:error]).to eql 'Submission was unsuccessful: Submission Failed'
end
context "moderated grading" do
before :once do
@assignment = @course.assignments.create!(:title => "some assignment", :moderated_grading => true)
@student = @course.enroll_student(User.create!(:name => "some user"), :enrollment_state => :active).user
end
before :each do
user_session(@teacher)
end
it "creates a provisional grade" do
submission = @assignment.submit_homework(@student, :body => "hello")
post 'update_submission',
:format => :json,
:course_id => @course.id,
:submission => { :score => 100,
:comment => "provisional!",
:assignment_id => @assignment.id,
:user_id => @student.id,
:provisional => true }
# confirm "real" grades/comments were not written
submission.reload
expect(submission.workflow_state).to eq 'submitted'
expect(submission.score).to be_nil
expect(submission.grade).to be_nil
expect(submission.submission_comments.first).to be_nil
# confirm "provisional" grades/comments were written
pg = submission.provisional_grade(@teacher)
expect(pg.score).to eq 100
expect(pg.submission_comments.first.comment).to eq 'provisional!'
# confirm the response JSON shows provisional information
json = JSON.parse response.body
expect(json[0]['submission']['score']).to eq 100
expect(json[0]['submission']['grade_matches_current_submission']).to eq true
expect(json[0]['submission']['submission_comments'].first['submission_comment']['comment']).to eq 'provisional!'
end
it "includes the graded anonymously flag in the provisional grade object" do
submission = @assignment.submit_homework(@student, body: "hello")
post 'update_submission',
format: :json,
course_id: @course.id,
submission: { score: 100,
comment: "provisional!",
assignment_id: @assignment.id,
user_id: @student.id,
provisional: true,
graded_anonymously: true }
submission.reload
pg = submission.provisional_grade(@teacher)
expect(pg.graded_anonymously).to eq true
submission = @assignment.submit_homework(@student, body: "hello")
post 'update_submission',
format: :json,
course_id: @course.id,
submission: { score: 100,
comment: "provisional!",
assignment_id: @assignment.id,
user_id: @student.id,
provisional: true,
graded_anonymously: false }
submission.reload
pg = submission.provisional_grade(@teacher)
expect(pg.graded_anonymously).to eq false
end
it "doesn't create a provisional grade when the student has one already (and isn't in the moderation set)" do
submission = @assignment.submit_homework(@student, :body => "hello")
other_teacher = teacher_in_course(:course => @course, :active_all => true).user
submission.find_or_create_provisional_grade!(other_teacher)
post 'update_submission', :format => :json, :course_id => @course.id,
:submission => { :score => 100, :comment => "provisional!", :assignment_id => @assignment.id,
:user_id => @student.id, :provisional => true }
expect(response).to_not be_success
expect(response.body).to include("Student already has the maximum number of provisional grades")
end
it "should create a provisional grade even if the student has one but is in the moderation set" do
submission = @assignment.submit_homework(@student, :body => "hello")
other_teacher = teacher_in_course(:course => @course, :active_all => true).user
submission.find_or_create_provisional_grade!(other_teacher)
@assignment.moderated_grading_selections.create!(:student => @student)
post 'update_submission', :format => :json, :course_id => @course.id,
:submission => { :score => 100, :comment => "provisional!", :assignment_id => @assignment.id,
:user_id => @student.id, :provisional => true }
expect(response).to be_success
end
it "creates a final provisional grade" do
submission = @assignment.submit_homework(@student, :body => "hello")
other_teacher = teacher_in_course(:course => @course, :active_all => true).user
submission.find_or_create_provisional_grade!(other_teacher) # create one so we can make a final
post 'update_submission',
:format => :json,
:course_id => @course.id,
:submission => { :score => 100,
:comment => "provisional!",
:assignment_id => @assignment.id,
:user_id => @student.id,
:provisional => true,
:final => true
}
expect(response).to be_success
# confirm "real" grades/comments were not written
submission.reload
expect(submission.workflow_state).to eq 'submitted'
expect(submission.score).to be_nil
expect(submission.grade).to be_nil
expect(submission.submission_comments.first).to be_nil
# confirm "provisional" grades/comments were written
pg = submission.provisional_grade(@teacher, final: true)
expect(pg.score).to eq 100
expect(pg.final).to eq true
expect(pg.submission_comments.first.comment).to eq 'provisional!'
# confirm the response JSON shows provisional information
json = JSON.parse response.body
expect(json[0]['submission']['score']).to eq 100
expect(json[0]['submission']['provisional_grade_id']).to eq pg.id
expect(json[0]['submission']['grade_matches_current_submission']).to eq true
expect(json[0]['submission']['submission_comments'].first['submission_comment']['comment']).to eq 'provisional!'
end
end
end
describe "GET 'speed_grader'" do
it "redirects the user if course's large_roster? setting is true" do
user_session(@teacher)
assignment = @course.assignments.create!(:title => 'some assignment')
Course.any_instance.stubs(:large_roster?).returns(true)
get 'speed_grader', :course_id => @course.id, :assignment_id => assignment.id
expect(response).to be_redirect
expect(flash[:notice]).to eq 'SpeedGrader is disabled for this course'
end
context "assignment published status" do
before :once do
@assign = @course.assignments.create!(title: 'Totally')
@assign.unpublish
end
before :each do
user_session(@teacher)
end
it "redirects if the assignment is unpublished" do
get 'speed_grader', course_id: @course, assignment_id: @assign.id
expect(response).to be_redirect
expect(flash[:notice]).to eq I18n.t(
:speedgrader_enabled_only_for_published_content,
'SpeedGrader is enabled only for published content.')
end
it "does not redirect if the assignment is published" do
@assign.publish
get 'speed_grader', course_id: @course, assignment_id: @assign.id
expect(response).not_to be_redirect
end
end
it 'includes the lti_retrieve_url in the js_env' do
user_session(@teacher)
@assignment = @course.assignments.create!(title: "A Title", submission_types: 'online_url,online_file')
get 'speed_grader', course_id: @course, assignment_id: @assignment.id
expect(assigns[:js_env][:lti_retrieve_url]).not_to be_nil
end
it 'includes the grading_type in the js_env' do
user_session(@teacher)
@assignment = @course.assignments.create!(
title: "A Title",
submission_types: 'online_url,online_file',
grading_type: 'percent'
)
get 'speed_grader', course_id: @course, assignment_id: @assignment.id
expect(assigns[:js_env][:grading_type]).to eq('percent')
end
end
describe "POST 'speed_grader_settings'" do
it "lets you set your :enable_speedgrader_grade_by_question preference" do
user_session(@teacher)
expect(@teacher.preferences[:enable_speedgrader_grade_by_question]).not_to be_truthy
post 'speed_grader_settings', course_id: @course.id,
enable_speedgrader_grade_by_question: "1"
expect(@teacher.reload.preferences[:enable_speedgrader_grade_by_question]).to be_truthy
post 'speed_grader_settings', course_id: @course.id,
enable_speedgrader_grade_by_question: "0"
expect(@teacher.reload.preferences[:enable_speedgrader_grade_by_question]).not_to be_truthy
end
end
describe "POST 'save_assignment_order'" do
it "saves the sort order in the user's preferences" do
user_session(@teacher)
post 'save_assignment_order', course_id: @course.id, assignment_order: 'due_at'
saved_order = @teacher.preferences[:course_grades_assignment_order][@course.id]
expect(saved_order).to eq(:due_at)
end
end