|
104 | 104 | end |
105 | 105 | end |
106 | 106 |
|
| 107 | + describe '#suspend' do |
| 108 | + subject { patch :suspend, params: { course_id: course } } |
| 109 | + |
| 110 | + context 'when the user is a Course Owner' do |
| 111 | + let(:user) { create(:course_owner, course: course).user } |
| 112 | + |
| 113 | + it 'suspends the course' do |
| 114 | + subject |
| 115 | + expect(course.reload.is_suspended).to be true |
| 116 | + end |
| 117 | + end |
| 118 | + |
| 119 | + context 'when the user is a Course Manager' do |
| 120 | + let(:user) { create(:course_manager, course: course).user } |
| 121 | + |
| 122 | + it 'suspends the course' do |
| 123 | + subject |
| 124 | + expect(course.reload.is_suspended).to be true |
| 125 | + end |
| 126 | + end |
| 127 | + |
| 128 | + context 'when the user is a Teaching Assistant' do |
| 129 | + let(:user) { create(:course_teaching_assistant, course: course).user } |
| 130 | + |
| 131 | + it { expect { subject }.to raise_exception(CanCan::AccessDenied) } |
| 132 | + end |
| 133 | + |
| 134 | + context 'when the user is a Course Student' do |
| 135 | + let(:user) { create(:course_student, course: course).user } |
| 136 | + |
| 137 | + it { expect { subject }.to raise_exception(CanCan::AccessDenied) } |
| 138 | + end |
| 139 | + end |
| 140 | + |
| 141 | + describe '#unsuspend' do |
| 142 | + let(:course) { create(:course, is_suspended: true) } |
| 143 | + subject { patch :unsuspend, params: { course_id: course } } |
| 144 | + |
| 145 | + context 'when the user is a Course Owner' do |
| 146 | + let(:user) { create(:course_owner, course: course).user } |
| 147 | + |
| 148 | + it 'unsuspends the course' do |
| 149 | + subject |
| 150 | + expect(course.reload.is_suspended).to be false |
| 151 | + end |
| 152 | + end |
| 153 | + |
| 154 | + context 'when the user is a Course Manager' do |
| 155 | + let(:user) { create(:course_manager, course: course).user } |
| 156 | + |
| 157 | + it 'unsuspends the course' do |
| 158 | + subject |
| 159 | + expect(course.reload.is_suspended).to be false |
| 160 | + end |
| 161 | + end |
| 162 | + |
| 163 | + context 'when the user is a Teaching Assistant' do |
| 164 | + let(:user) { create(:course_teaching_assistant, course: course).user } |
| 165 | + |
| 166 | + it { expect { subject }.to raise_exception(CanCan::AccessDenied) } |
| 167 | + end |
| 168 | + |
| 169 | + context 'when the user is a Course Student' do |
| 170 | + let(:user) { create(:course_student, course: course).user } |
| 171 | + |
| 172 | + it { expect { subject }.to raise_exception(CanCan::AccessDenied) } |
| 173 | + end |
| 174 | + end |
| 175 | + |
107 | 176 | describe '#destroy' do |
108 | 177 | subject { delete :destroy, params: { course_id: course } } |
109 | 178 | before { controller.instance_variable_set(:@course, course) } |
|
0 commit comments