forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdifferentiable_assignment_spec.rb
More file actions
177 lines (165 loc) · 7.05 KB
/
Copy pathdifferentiable_assignment_spec.rb
File metadata and controls
177 lines (165 loc) · 7.05 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
#
# Copyright (C) 2014 - 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.rb')
shared_examples_for "a differentiable_object" do
before do
teacher_in_course(active_all: true, course: differentiable.context)
end
describe "differentiated_assignments_applies?" do
context "only_visible_to_overrides is true" do
it "returns true" do
differentiable.update_attribute "only_visible_to_overrides",true
expect(differentiable.differentiated_assignments_applies?).to be_truthy
end
end
context "only_visible_to_overrides is false" do
it "returns false" do
differentiable.update_attribute "only_visible_to_overrides",false
expect(differentiable.differentiated_assignments_applies?).to be_falsey
end
end
end
describe "visible_to_user?" do
context "student" do
before {student_in_course(:course => @course)}
it "with a visibility it should be true" do
differentiable_view.stubs(:where).returns([:a_record])
expect(differentiable.visible_to_user?(@user)).to be_truthy
end
it "without a visibility should be false" do
differentiable_view.stubs(:where).returns([])
expect(differentiable.visible_to_user?(@user)).to be_falsey
end
end
context "observer" do
before do
@course_section = @course.course_sections.create
@student1, @student2, @student3 = create_users(3, return_type: :record)
@course.enroll_student(@student2, :enrollment_state => 'active')
@section = @course.course_sections.create!(name: "test section")
@section2 = @course.course_sections.create!(name: "second test section")
student_in_section(@section, user: @student1)
create_section_override_for_assignment(differentiable, {course_section: @section})
@course.reload
@observer = User.create(name: "observer")
end
context "observing only a section (with or without an override)" do
before do
@observer_enrollment = @course.enroll_user(@observer, 'ObserverEnrollment', :section => @section2, :enrollment_state => 'active')
end
it "should be visible" do
expect(differentiable.visible_to_user?(@observer)).to be_truthy
end
end
context "observing a student with visibility" do
before do
@observer_enrollment = @course.enroll_user(@observer, 'ObserverEnrollment', :section => @section2, :enrollment_state => 'active')
@observer_enrollment.update_attribute(:associated_user_id, @student1.id)
end
it "should be visible" do
expect(differentiable.visible_to_user?(@observer)).to be_truthy
end
end
context "observing a student without visibility" do
before do
@observer_enrollment = @course.enroll_user(@observer, 'ObserverEnrollment', :section => @section2, :enrollment_state => 'active')
@observer_enrollment.update_attribute(:associated_user_id, @student2.id)
end
it "should not be visible" do
expect(differentiable.visible_to_user?(@observer)).to be_falsey
end
end
context "observing two students, one with visibility" do
before do
@observer_enrollment = @course.enroll_user(@observer, 'ObserverEnrollment', :section => @section2, :enrollment_state => 'active', :associated_user_id => @student1.id)
@course.enroll_user(@observer, "ObserverEnrollment", {:allow_multiple_enrollments => true, :associated_user_id => @student2.id})
end
it "should be visible" do
expect(differentiable.visible_to_user?(@observer)).to be_truthy
end
end
context "observing two students, neither with visibility" do
before do
@observer_enrollment = @course.enroll_user(@observer, 'ObserverEnrollment', :section => @section2, :enrollment_state => 'active', :associated_user_id => @student3.id)
@course.enroll_user(@observer, "ObserverEnrollment", {:allow_multiple_enrollments => true, :associated_user_id => @student2.id})
end
it "should not be visible" do
expect(differentiable.visible_to_user?(@observer)).to be_falsey
end
end
end
context "teacher" do
it "should be visible" do
teacher_in_course(active_all: true, course: @course)
expect(differentiable.visible_to_user?(@user)).to be_truthy
end
end
end
describe "filter" do
def call_filter
block = lambda { |collection, users| return :filtered}
DifferentiableAssignment.filter(:not_filtered, @user, @course, {}, &block)
end
it "should filter for students" do
student_in_course(:course => @course)
expect(call_filter).to eq :filtered
end
context "observer" do
before do
@observer = User.create(name: "observer")
@observer_enrollment = @course.enroll_user(@observer, 'ObserverEnrollment', :section => @section2, :enrollment_state => 'active')
end
it "should not filter when no observed students" do
@user = @observer_enrollment.user
expect(call_filter).to eq :not_filtered
end
it "should filter with observed students" do
student_in_course(:course => @course)
@observer_enrollment.update_attribute(:associated_user_id, @user.id)
@user = @observer_enrollment.user
@observer_enrollment.update_attribute(:associated_user_id, @user.id)
expect(call_filter).to eq :filtered
end
end
it "should not filter for the teacher" do
teacher_in_course(:course => @course)
expect(call_filter).to eq :not_filtered
end
it "should not filter if no user" do
@user = nil
expect(call_filter).to eq :not_filtered
end
it "should not filter if user not in course" do
original_user = @user
# override @user and @course
student_in_course(:course => course_factory)
@user = original_user
expect(call_filter).to eq :not_filtered
end
end
end
describe Assignment do
include_examples "a differentiable_object"
let(:differentiable) { assignment_model(:due_at => 5.days.ago, :only_visible_to_overrides => true) }
let(:differentiable_view) { AssignmentStudentVisibility }
end
describe Quizzes::Quiz do
include_examples "a differentiable_object"
let(:differentiable) { quiz_model(:due_at => 5.days.ago, :only_visible_to_overrides => true) }
let(:differentiable_view) { Quizzes::QuizStudentVisibility }
end