forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutcomes_controller_spec.rb
More file actions
353 lines (298 loc) · 10.9 KB
/
Copy pathoutcomes_controller_spec.rb
File metadata and controls
353 lines (298 loc) · 10.9 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
#
# 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 OutcomesController do
def context_outcome(context)
@outcome_group ||= context.root_outcome_group
@outcome = context.created_learning_outcomes.create!(:title => 'outcome')
@outcome_group.add_outcome(@outcome)
end
def course_outcome
context_outcome(@course)
end
def account_outcome
context_outcome(@account)
end
before :once do
course_with_teacher(active_all: true)
student_in_course(active_all: true)
@account = Account.default
account_admin_user
end
describe "GET 'index'" do
it "should require authorization" do
get 'index', :course_id => @course.id
assert_unauthorized
end
it "should redirect 'disabled', if disabled by the teacher" do
user_session(@student)
@course.update_attribute(:tab_configuration, [{'id'=>15,'hidden'=>true}])
get 'index', :course_id => @course.id
expect(response).to be_redirect
expect(flash[:notice]).to match(/That page has been disabled/)
end
it "should assign variables" do
user_session(@student)
get 'index', :course_id => @course.id
expect(response).to be_success
end
it "should work in accounts" do
user_session(@admin)
account_outcome
get 'index', :account_id => @account.id
end
it "should find a common core group from settings" do
user_session(@admin)
account_outcome
Setting.set(AcademicBenchmark.common_core_setting_key, @outcome_group.id)
get 'index', :account_id => @account.id
expect(assigns[:js_env][:COMMON_CORE_GROUP_ID]).to eq @outcome_group.id
end
end
describe "GET 'show'" do
it "should require authorization" do
course_outcome
get 'show', :course_id => @course.id, :id => @outcome.id
assert_unauthorized
end
it "should not allow students to view outcomes" do
user_session(@student)
course_outcome
get 'show', :course_id => @course.id, :id => @outcome.id
assert_unauthorized
end
it "should assign variables" do
user_session(@teacher)
course_outcome
get 'show', :course_id => @course.id, :id => @outcome.id
expect(response).to be_success
end
it "should work in accounts" do
user_session(@admin)
account_outcome
get 'show', :account_id => @account.id, :id => @outcome.id
expect(response).to be_success
end
it "should include tags from courses when viewed in the account" do
account_outcome
quiz = @course.quizzes.create!
alignment = @outcome.align(quiz, @course)
user_session(@admin)
get 'show', :account_id => @account.id, :id => @outcome.id
expect(assigns[:alignments].any?{ |a| a.id == alignment.id }).to be_truthy
end
it "should not allow access to individual outcomes for large_roster courses" do
course_outcome
@course.large_roster = true
@course.save!
get 'show', :course_id => @course.id, :id => @outcome.id
expect(response).to be_redirect
end
end
describe "GET 'details'" do
it "should require authorization" do
course_outcome
get 'details', :course_id => @course.id, :outcome_id => @outcome.id
assert_unauthorized
end
it "should assign variables" do
user_session(@student)
course_outcome
get 'details', :course_id => @course.id, :outcome_id => @outcome.id
expect(response).to be_success
end
it "should work in accounts" do
user_session(@admin)
account_outcome
get 'details', :account_id => @account.id, :outcome_id => @outcome.id
end
end
describe "GET 'user_outcome_results'" do
it "should require authorization" do
account_outcome
get 'user_outcome_results', :account_id => @account.id, :user_id => @student.id
assert_unauthorized
end
it "should return outcomes for the given user" do
account_outcome
user_session(@admin)
get 'user_outcome_results', :account_id => @account.id, :user_id => @student.id
expect(response).to be_success
expect(response).to render_template('user_outcome_results')
end
end
describe "GET 'list'" do
it "should list account outcomes for an account context" do
account_outcome
user_session(@admin)
get 'list', :account_id => @account.id
expect(response).to be_success
data = json_parse
expect(data).not_to be_empty
end
it "should list account outcomes for a subaccount context" do
account_outcome
sub_account_1 = @account.sub_accounts.create!
user_session(@admin)
get 'list', :account_id => sub_account_1.id
expect(response).to be_success
data = json_parse
expect(data).not_to be_empty
end
it "should list account outcomes for a course context" do
account_outcome
user_session(@teacher)
get 'list', :course_id => @course.id
expect(response).to be_success
data = json_parse
expect(data).not_to be_empty
end
end
describe "POST 'create'" do
before :once do
OUTCOME_PARAMS = {
:description => "A long description",
:short_description => "A short description"
}
end
it "should require authorization" do
course_outcome
post 'create', :course_id => @course.id
assert_unauthorized
end
it "should not let a student create a outcome" do
user_session(@student)
post 'create', :course_id => @course.id,
:learning_outcome => { :short_description => TEST_STRING }
assert_unauthorized
end
it "should allow creating a new outcome with the root group" do
user_session(@teacher)
post 'create', :course_id => @course.id, :learning_outcome => OUTCOME_PARAMS
expect(response).to be_redirect
expect(assigns[:outcome]).not_to be_nil
expect(assigns[:outcome][:description]).to eql("A long description")
expect(assigns[:outcome][:short_description]).to eql("A short description")
expect(@course.learning_outcome_links.map { |n| n.content }.include?(assigns[:outcome])).to be_truthy
@course.learning_outcome_groups.each do |group|
if group.child_outcome_links.map { |n| n.content }.include?(assigns[:outcome])
expect(group).to eql(@course.root_outcome_group)
end
end
end
it "should allow creating a new outcome with a specific group" do
# create a new group that is a child of the root group that we can
# set our new outcome to belong to
user_session(@teacher)
outcome_group = @course.root_outcome_group.child_outcome_groups.build(
:title => "Child outcome group", :context => @course)
expect(outcome_group.save).to be_truthy
expect(outcome_group.id).not_to be_nil
expect(outcome_group).not_to be_nil
post 'create', :course_id => @course.id, :learning_outcome_group_id => outcome_group.id,
:learning_outcome => OUTCOME_PARAMS
expect(response).to be_redirect
expect(assigns[:outcome]).not_to be_nil
expect(assigns[:outcome][:description]).to eql("A long description")
expect(assigns[:outcome][:short_description]).to eql("A short description")
expect(@course.learning_outcome_links.map { |n| n.content }.include?(assigns[:outcome])).to be_truthy
@course.learning_outcome_groups.each do |group|
if group.child_outcome_links.map { |n| n.content }.include?(assigns[:outcome])
expect(group).to eql(outcome_group)
end
end
end
end
describe "PUT 'update'" do
TEST_STRING = "Some test String"
before :each do
course_outcome
end
it "should require authorization" do
put 'update', :course_id => @course.id, :id => @outcome.id,
:learning_outcome => { :short_description => TEST_STRING }
assert_unauthorized
end
it "should not let a student update the outcome" do
user_session(@student)
put 'update', :course_id => @course.id, :id => @outcome.id,
:learning_outcome => { :short_description => TEST_STRING }
assert_unauthorized
end
it "should allow updating the outcome" do
user_session(@teacher)
put 'update', :course_id => @course.id, :id => @outcome.id,
:learning_outcome => { :short_description => TEST_STRING }
@outcome.reload
expect(@outcome[:short_description]).to eql TEST_STRING
end
end
describe "DELETE 'destroy'" do
before :each do
course_outcome
end
it "should require authorization" do
delete 'destroy', :course_id => @course.id, :id => @outcome.id
assert_unauthorized
end
it "should not let a student delete the outcome" do
user_session(@student)
delete 'destroy', :course_id => @course.id, :id => @outcome.id
assert_unauthorized
end
it "should delete the outcome from the database" do
user_session(@teacher)
delete 'destroy', :course_id => @course.id, :id => @outcome.id
@outcome.reload
expect(@outcome).to be_deleted
end
end
describe "GET 'outcome_result" do
before :each do
course_outcome
end
context "with a quiz result" do
before :each do
assessment_question_bank_with_questions
@outcome.align(@bank, @bank.context, :mastery_score => 0.7)
@quiz = @course.quizzes.create!(:title => "a quiz")
@quiz.add_assessment_questions [ @q1, @q2 ]
@submission = @quiz.generate_submission @student
@submission.quiz_data = @quiz.generate_quiz_data
@submission.mark_completed
Quizzes::SubmissionGrader.new(@submission).grade_submission
end
it "should require teacher authorization" do
user_session(@student)
get 'outcome_result',
:course_id => @course.id,
:outcome_id => @outcome.id,
:id => @outcome.learning_outcome_results.last
assert_unauthorized
end
it "should redirect to show quiz when result is a quiz" do
user_session(@teacher)
get 'outcome_result',
:course_id => @course.id,
:outcome_id => @outcome.id,
:id => @outcome.learning_outcome_results.last
expect(response).to redirect_to(/#{Regexp.quote(course_quiz_history_url(quiz_id: @submission.quiz_id))}/)
end
end
end
end