forked from capability-boosters-dev/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
change_enrollments_role_id_null_spec.rb
64 lines (53 loc) · 2.45 KB
/
change_enrollments_role_id_null_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
#
# 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')
require 'db/migrate/20141212134557_change_enrollments_role_id_null'
describe 'ChangeEnrollmentsRoleIdNull' do
it "should clean up StudentViewEnrollments" do
migration = ChangeEnrollmentsRoleIdNull.new
courses = (0..3).map do
course = course_model
course.student_view_student
course
end
migration.down
# courses[0] is a control course with a normal student view enrollment
# courses[1] will have a missing role_id in the student view enrollment...
courses[1].student_view_enrollments.update_all(role_id: nil)
# courses[2] will have an extra enrollment with a nil role_id
courses[2].student_view_enrollments.update_all(role_id: nil)
courses[2].student_view_student
student_role = Role.get_built_in_role('StudentEnrollment')
expect(courses[0].student_view_enrollments.pluck(:role_id)).to match_array([student_role.id])
expect(courses[1].student_view_enrollments.pluck(:role_id)).to match_array([nil])
expect(courses[2].student_view_enrollments.pluck(:role_id)).to match_array([student_role.id, nil])
migration.up
expect(courses[0].student_view_enrollments.pluck(:role_id)).to match_array([student_role.id])
expect(courses[1].student_view_enrollments.pluck(:role_id)).to match_array([student_role.id])
expect(courses[2].student_view_enrollments.pluck(:role_id)).to match_array([student_role.id])
end
it "should clean up ObserverEnrollments" do
migration = ChangeEnrollmentsRoleIdNull.new
course_with_observer
migration.down
@course.observer_enrollments.update_all(role_id: nil)
expect(@enrollment.reload.read_attribute(:role_id)).to be_nil
migration.up
expect(@enrollment.reload.role.name).to eq "ObserverEnrollment"
end
end