|
11 | 11 | let(:starter_project) { build(:project, user_id: nil) }
|
12 | 12 |
|
13 | 13 | describe 'Project' do
|
14 |
| - context 'when no user' do |
| 14 | + context 'with no user' do |
15 | 15 | let(:user) { nil }
|
16 | 16 |
|
17 | 17 | context 'with a starter project' do
|
|
31 | 31 | end
|
32 | 32 | end
|
33 | 33 |
|
34 |
| - context 'when user present' do |
| 34 | + context 'with a standard user' do |
35 | 35 | let(:user) { build(:user, id: user_id) }
|
36 | 36 | let(:another_project) { build(:project) }
|
37 | 37 |
|
|
58 | 58 | end
|
59 | 59 | end
|
60 | 60 |
|
| 61 | + context 'with a teacher' do |
| 62 | + let(:user) { build(:teacher, id: user_id) } |
| 63 | + let(:another_project) { build(:project) } |
| 64 | + |
| 65 | + context 'with a starter project' do |
| 66 | + it { is_expected.not_to be_able_to(:index, starter_project) } |
| 67 | + it { is_expected.to be_able_to(:show, starter_project) } |
| 68 | + it { is_expected.not_to be_able_to(:create, starter_project) } |
| 69 | + it { is_expected.not_to be_able_to(:update, starter_project) } |
| 70 | + it { is_expected.not_to be_able_to(:destroy, starter_project) } |
| 71 | + end |
| 72 | + |
| 73 | + context 'with own project' do |
| 74 | + it { is_expected.to be_able_to(:read, project) } |
| 75 | + it { is_expected.to be_able_to(:create, project) } |
| 76 | + it { is_expected.to be_able_to(:update, project) } |
| 77 | + it { is_expected.to be_able_to(:destroy, project) } |
| 78 | + end |
| 79 | + |
| 80 | + context 'with another user\'s project' do |
| 81 | + it { is_expected.not_to be_able_to(:read, another_project) } |
| 82 | + it { is_expected.not_to be_able_to(:create, another_project) } |
| 83 | + it { is_expected.not_to be_able_to(:update, another_project) } |
| 84 | + it { is_expected.not_to be_able_to(:destroy, another_project) } |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | + context 'with an owner' do |
| 89 | + let(:user) { build(:owner, id: user_id) } |
| 90 | + let(:another_project) { build(:project) } |
| 91 | + |
| 92 | + context 'with a starter project' do |
| 93 | + it { is_expected.not_to be_able_to(:index, starter_project) } |
| 94 | + it { is_expected.to be_able_to(:show, starter_project) } |
| 95 | + it { is_expected.not_to be_able_to(:create, starter_project) } |
| 96 | + it { is_expected.not_to be_able_to(:update, starter_project) } |
| 97 | + it { is_expected.not_to be_able_to(:destroy, starter_project) } |
| 98 | + end |
| 99 | + |
| 100 | + context 'with own project' do |
| 101 | + it { is_expected.to be_able_to(:read, project) } |
| 102 | + it { is_expected.to be_able_to(:create, project) } |
| 103 | + it { is_expected.to be_able_to(:update, project) } |
| 104 | + it { is_expected.to be_able_to(:destroy, project) } |
| 105 | + end |
| 106 | + |
| 107 | + context 'with another user\'s project' do |
| 108 | + it { is_expected.not_to be_able_to(:read, another_project) } |
| 109 | + it { is_expected.not_to be_able_to(:create, another_project) } |
| 110 | + it { is_expected.not_to be_able_to(:update, another_project) } |
| 111 | + it { is_expected.not_to be_able_to(:destroy, another_project) } |
| 112 | + end |
| 113 | + end |
| 114 | + |
| 115 | + context 'with a student' do |
| 116 | + let(:user) { build(:student, id: user_id) } |
| 117 | + let(:another_project) { build(:project) } |
| 118 | + |
| 119 | + context 'with a starter project' do |
| 120 | + it { is_expected.not_to be_able_to(:index, starter_project) } |
| 121 | + it { is_expected.to be_able_to(:show, starter_project) } |
| 122 | + it { is_expected.not_to be_able_to(:create, starter_project) } |
| 123 | + it { is_expected.not_to be_able_to(:update, starter_project) } |
| 124 | + it { is_expected.not_to be_able_to(:destroy, starter_project) } |
| 125 | + end |
| 126 | + |
| 127 | + context 'with own project' do |
| 128 | + it { is_expected.to be_able_to(:read, project) } |
| 129 | + it { is_expected.to be_able_to(:create, project) } |
| 130 | + it { is_expected.to be_able_to(:update, project) } |
| 131 | + it { is_expected.to be_able_to(:destroy, project) } |
| 132 | + end |
| 133 | + |
| 134 | + context 'with another user\'s project' do |
| 135 | + it { is_expected.not_to be_able_to(:read, another_project) } |
| 136 | + it { is_expected.not_to be_able_to(:create, another_project) } |
| 137 | + it { is_expected.not_to be_able_to(:update, another_project) } |
| 138 | + it { is_expected.not_to be_able_to(:destroy, another_project) } |
| 139 | + end |
| 140 | + end |
| 141 | + |
61 | 142 | # rubocop:disable RSpec/MultipleMemoizedHelpers
|
62 |
| - context 'when the project belongs to a school and the associated lesson is not private' do |
| 143 | + context 'with a teachers project where the lesson is visible to students' do |
63 | 144 | let(:user) { create(:user) }
|
64 | 145 | let(:school) { create(:school) }
|
65 | 146 | let(:teacher) { create(:teacher, school:) }
|
|
73 | 154 | end
|
74 | 155 |
|
75 | 156 | it { is_expected.to be_able_to(:read, school_project) }
|
| 157 | + it { is_expected.not_to be_able_to(:create, school_project) } |
76 | 158 | it { is_expected.not_to be_able_to(:update, school_project) }
|
77 | 159 | it { is_expected.not_to be_able_to(:toggle_finished, school_project) }
|
78 | 160 | it { is_expected.not_to be_able_to(:destroy, school_project) }
|
|
84 | 166 | end
|
85 | 167 |
|
86 | 168 | it { is_expected.to be_able_to(:read, school_project) }
|
87 |
| - it { is_expected.not_to be_able_to(:update, school_project) } |
| 169 | + it { is_expected.not_to be_able_to(:create, school_project) } |
| 170 | + it { is_expected.to be_able_to(:update, school_project) } |
88 | 171 | it { is_expected.not_to be_able_to(:toggle_finished, school_project) }
|
89 | 172 | it { is_expected.not_to be_able_to(:destroy, school_project) }
|
90 | 173 | end
|
91 | 174 |
|
92 |
| - context 'when user is a school student and belongs to a class' do |
| 175 | + context 'when user is a school student and belongs to the teachers class' do |
93 | 176 | before do
|
94 | 177 | create(:student_role, user_id: user.id, school:)
|
95 | 178 | create(:class_member, school_class:, student_id: user.id)
|
96 | 179 | end
|
97 | 180 |
|
98 | 181 | it { is_expected.to be_able_to(:read, school_project) }
|
| 182 | + it { is_expected.not_to be_able_to(:create, school_project) } |
99 | 183 | it { is_expected.not_to be_able_to(:update, school_project) }
|
100 | 184 | it { is_expected.not_to be_able_to(:toggle_finished, school_project) }
|
101 | 185 | it { is_expected.not_to be_able_to(:destroy, school_project) }
|
102 | 186 | end
|
103 | 187 |
|
104 |
| - context 'when user is a school student and does not belong to a class' do |
| 188 | + context 'when user is a school student and does not belong to the teachers class' do |
105 | 189 | before do
|
106 | 190 | create(:student_role, user_id: user.id, school:)
|
107 | 191 | end
|
108 | 192 |
|
109 | 193 | it { is_expected.not_to be_able_to(:read, school_project) }
|
| 194 | + it { is_expected.not_to be_able_to(:create, school_project) } |
110 | 195 | it { is_expected.not_to be_able_to(:update, school_project) }
|
111 | 196 | it { is_expected.not_to be_able_to(:toggle_finished, school_project) }
|
112 | 197 | it { is_expected.not_to be_able_to(:destroy, school_project) }
|
113 | 198 | end
|
114 | 199 | end
|
115 | 200 |
|
116 |
| - context 'when the project belongs to a student' do |
| 201 | + # TODO: Handle other visibilities |
| 202 | + |
| 203 | + context 'with a remix of a teachers project' do |
117 | 204 | let(:school) { create(:school) }
|
118 | 205 | let(:student) { create(:student, school:) }
|
119 | 206 | let(:teacher) { create(:teacher, school:) }
|
|
126 | 213 | context 'when user is the student' do
|
127 | 214 | let(:user) { student }
|
128 | 215 |
|
| 216 | + it { is_expected.to be_able_to(:read, remixed_project) } |
| 217 | + it { is_expected.to be_able_to(:create, remixed_project) } |
| 218 | + it { is_expected.to be_able_to(:update, remixed_project) } |
| 219 | + it { is_expected.not_to be_able_to(:destroy, remixed_project) } |
129 | 220 | it { is_expected.to be_able_to(:toggle_finished, remixed_project) }
|
130 | 221 | end
|
131 | 222 |
|
132 | 223 | context 'when user is teacher that does not own the orginal project' do
|
133 | 224 | let(:user) { create(:teacher, school:) }
|
134 | 225 |
|
135 | 226 | it { is_expected.not_to be_able_to(:read, remixed_project) }
|
| 227 | + it { is_expected.not_to be_able_to(:create, remixed_project) } |
136 | 228 | it { is_expected.not_to be_able_to(:update, remixed_project) }
|
137 | 229 | it { is_expected.not_to be_able_to(:destroy, remixed_project) }
|
138 | 230 | it { is_expected.not_to be_able_to(:toggle_finished, remixed_project) }
|
|
142 | 234 | let(:user) { teacher }
|
143 | 235 |
|
144 | 236 | it { is_expected.to be_able_to(:read, remixed_project) }
|
| 237 | + it { is_expected.not_to be_able_to(:create, remixed_project) } |
145 | 238 | it { is_expected.not_to be_able_to(:update, remixed_project) }
|
146 | 239 | it { is_expected.not_to be_able_to(:destroy, remixed_project) }
|
147 | 240 | it { is_expected.not_to be_able_to(:toggle_finished, remixed_project) }
|
|
0 commit comments