|
140 | 140 | end
|
141 | 141 |
|
142 | 142 | # rubocop:disable RSpec/MultipleMemoizedHelpers
|
143 |
| - context 'with a teachers project where the lesson is visible to students' do |
| 143 | + context "with a teacher's project where the lesson is visible to students" do |
144 | 144 | let(:user) { create(:user) }
|
145 | 145 | let(:school) { create(:school) }
|
146 | 146 | let(:teacher) { create(:teacher, school:) }
|
|
154 | 154 | end
|
155 | 155 |
|
156 | 156 | it { is_expected.to be_able_to(:read, project) }
|
| 157 | + it { is_expected.to be_able_to(:show_context, project) } |
157 | 158 | it { is_expected.not_to be_able_to(:create, project) }
|
158 | 159 | it { is_expected.not_to be_able_to(:update, project) }
|
159 | 160 | it { is_expected.not_to be_able_to(:set_finished, project.school_project) }
|
|
166 | 167 | end
|
167 | 168 |
|
168 | 169 | it { is_expected.to be_able_to(:read, project) }
|
| 170 | + it { is_expected.to be_able_to(:show_context, project) } |
169 | 171 | it { is_expected.not_to be_able_to(:create, project) }
|
170 | 172 | it { is_expected.to be_able_to(:update, project) }
|
171 | 173 | it { is_expected.not_to be_able_to(:set_finished, project.school_project) }
|
|
179 | 181 | end
|
180 | 182 |
|
181 | 183 | it { is_expected.to be_able_to(:read, project) }
|
| 184 | + it { is_expected.to be_able_to(:show_context, project) } |
182 | 185 | it { is_expected.not_to be_able_to(:create, project) }
|
183 | 186 | it { is_expected.not_to be_able_to(:update, project) }
|
184 | 187 | it { is_expected.not_to be_able_to(:set_finished, project.school_project) }
|
|
191 | 194 | end
|
192 | 195 |
|
193 | 196 | it { is_expected.not_to be_able_to(:read, project) }
|
| 197 | + it { is_expected.not_to be_able_to(:show_context, project) } |
| 198 | + it { is_expected.not_to be_able_to(:create, project) } |
| 199 | + it { is_expected.not_to be_able_to(:update, project) } |
| 200 | + it { is_expected.not_to be_able_to(:set_finished, project.school_project) } |
| 201 | + it { is_expected.not_to be_able_to(:destroy, project) } |
| 202 | + end |
| 203 | + end |
| 204 | + |
| 205 | + context 'with a teachers project where the lesson is not visible to students' do |
| 206 | + let(:user) { create(:user) } |
| 207 | + let(:school) { create(:school) } |
| 208 | + let(:teacher) { create(:teacher, school:) } |
| 209 | + let(:school_class) { build(:school_class, school:, teacher_ids: [teacher.id]) } |
| 210 | + let(:lesson) { build(:lesson, school:, school_class:, user_id: teacher.id, visibility: 'teachers') } |
| 211 | + let!(:project) { build(:project, school:, lesson:, user_id: teacher.id) } |
| 212 | + |
| 213 | + context 'when user is a school owner' do |
| 214 | + before do |
| 215 | + create(:owner_role, user_id: user.id, school:) |
| 216 | + end |
| 217 | + |
| 218 | + it { is_expected.to be_able_to(:read, project) } |
| 219 | + it { is_expected.to be_able_to(:show_context, project) } |
| 220 | + it { is_expected.not_to be_able_to(:create, project) } |
| 221 | + it { is_expected.not_to be_able_to(:update, project) } |
| 222 | + it { is_expected.not_to be_able_to(:set_finished, project.school_project) } |
| 223 | + it { is_expected.not_to be_able_to(:destroy, project) } |
| 224 | + end |
| 225 | + |
| 226 | + context 'when user is a school teacher' do |
| 227 | + before do |
| 228 | + create(:teacher_role, user_id: user.id, school:) |
| 229 | + end |
| 230 | + |
| 231 | + it { is_expected.to be_able_to(:read, project) } |
| 232 | + it { is_expected.to be_able_to(:show_context, project) } |
| 233 | + it { is_expected.not_to be_able_to(:create, project) } |
| 234 | + it { is_expected.to be_able_to(:update, project) } |
| 235 | + it { is_expected.not_to be_able_to(:set_finished, project.school_project) } |
| 236 | + it { is_expected.not_to be_able_to(:destroy, project) } |
| 237 | + end |
| 238 | + |
| 239 | + context 'when user is a school student and belongs to the teachers class' do |
| 240 | + before do |
| 241 | + create(:student_role, user_id: user.id, school:) |
| 242 | + create(:class_student, school_class:, student_id: user.id) |
| 243 | + end |
| 244 | + |
| 245 | + it { is_expected.not_to be_able_to(:read, project) } |
| 246 | + it { is_expected.not_to be_able_to(:show_context, project) } |
| 247 | + it { is_expected.not_to be_able_to(:create, project) } |
| 248 | + it { is_expected.not_to be_able_to(:update, project) } |
| 249 | + it { is_expected.not_to be_able_to(:set_finished, project.school_project) } |
| 250 | + it { is_expected.not_to be_able_to(:destroy, project) } |
| 251 | + end |
| 252 | + |
| 253 | + context 'when user is a school student and does not belong to the teachers class' do |
| 254 | + before do |
| 255 | + create(:student_role, user_id: user.id, school:) |
| 256 | + end |
| 257 | + |
| 258 | + it { is_expected.not_to be_able_to(:read, project) } |
| 259 | + it { is_expected.not_to be_able_to(:show_context, project) } |
194 | 260 | it { is_expected.not_to be_able_to(:create, project) }
|
195 | 261 | it { is_expected.not_to be_able_to(:update, project) }
|
196 | 262 | it { is_expected.not_to be_able_to(:set_finished, project.school_project) }
|
|
200 | 266 |
|
201 | 267 | # TODO: Handle other visibilities
|
202 | 268 |
|
203 |
| - context 'with a remix of a teachers project' do |
| 269 | + context "with a remix of a teacher's project" do |
204 | 270 | let(:school) { create(:school) }
|
205 | 271 | let(:student) { create(:student, school:) }
|
206 | 272 | let(:teacher) { create(:teacher, school:) }
|
|
221 | 287 | it { is_expected.to be_able_to(:set_finished, remixed_project.school_project) }
|
222 | 288 | end
|
223 | 289 |
|
| 290 | + context 'when user is a student and the lesson is not visible to students' do |
| 291 | + let(:user) { student } |
| 292 | + |
| 293 | + before do |
| 294 | + lesson.update(visibility: 'teachers') |
| 295 | + end |
| 296 | + |
| 297 | + it { is_expected.not_to be_able_to(:read, remixed_project) } |
| 298 | + it { is_expected.not_to be_able_to(:create, remixed_project) } |
| 299 | + it { is_expected.not_to be_able_to(:update, remixed_project) } |
| 300 | + it { is_expected.not_to be_able_to(:destroy, remixed_project) } |
| 301 | + end |
| 302 | + |
224 | 303 | context 'when user is teacher that does not own the orginal project' do
|
225 | 304 | let(:user) { create(:teacher, school:) }
|
226 | 305 |
|
|
0 commit comments