|
127 | 127 | end
|
128 | 128 |
|
129 | 129 | describe '.users' do
|
130 |
| - it 'returns User instances for the current scope' do |
131 |
| - student = create(:student, school:, name: 'School Student') |
132 |
| - stub_user_info_api_for(student) |
133 |
| - create(:project, user_id: student.id) |
| 130 | + let(:student) { create(:student, school:, name: 'School Student') } |
| 131 | + let(:teacher) { create(:teacher, school:) } |
| 132 | + |
| 133 | + let(:student_attributes) do |
| 134 | + [{ id: student.id, name: student.name, username: student.username }] |
| 135 | + end |
134 | 136 |
|
135 |
| - user = described_class.all.users.first |
| 137 | + before do |
| 138 | + stub_profile_api_list_school_students(school:, student_attributes:) |
| 139 | + end |
| 140 | + |
| 141 | + it 'returns User instances for the current scope' do |
| 142 | + create(:project, user_id: student.id, school_id: school.id) |
| 143 | + user = described_class.all.users(teacher).first |
136 | 144 | expect(user.name).to eq('School Student')
|
137 | 145 | end
|
138 | 146 |
|
139 | 147 | it 'ignores members where no profile account exists' do
|
140 | 148 | user_id = SecureRandom.uuid
|
141 |
| - stub_user_info_api_for_unknown_users(user_id:) |
142 | 149 | create(:project, user_id:)
|
143 | 150 |
|
144 |
| - user = described_class.all.users.first |
| 151 | + user = described_class.all.users(teacher).first |
145 | 152 | expect(user).to be_nil
|
146 | 153 | end
|
147 | 154 |
|
148 | 155 | it 'ignores members not included in the current scope' do
|
149 | 156 | create(:project)
|
150 | 157 |
|
151 |
| - user = described_class.none.users.first |
| 158 | + user = described_class.none.users(teacher).first |
152 | 159 | expect(user).to be_nil
|
153 | 160 | end
|
154 | 161 | end
|
155 | 162 |
|
156 | 163 | describe '.with_users' do
|
157 |
| - # rubocop:disable RSpec/ExampleLength |
| 164 | + let(:student) { create(:student, school:) } |
| 165 | + let(:teacher) { create(:teacher, school:) } |
| 166 | + |
| 167 | + let(:student_attributes) do |
| 168 | + [{ id: student.id, name: student.name, username: student.username }] |
| 169 | + end |
| 170 | + |
| 171 | + before do |
| 172 | + stub_profile_api_list_school_students(school:, student_attributes:) |
| 173 | + end |
| 174 | + |
158 | 175 | it 'returns an array of class members paired with their User instance' do
|
159 |
| - student = create(:student, school:) |
160 |
| - stub_user_info_api_for(student) |
161 | 176 | project = create(:project, user_id: student.id)
|
162 | 177 |
|
163 |
| - pair = described_class.all.with_users.first |
164 |
| - user = described_class.all.users.first |
| 178 | + pair = described_class.all.with_users(teacher).first |
| 179 | + user = described_class.all.users(teacher).first |
165 | 180 |
|
166 | 181 | expect(pair).to eq([project, user])
|
167 | 182 | end
|
168 |
| - # rubocop:enable RSpec/ExampleLength |
169 | 183 |
|
170 | 184 | it 'returns nil values for members where no profile account exists' do
|
171 | 185 | user_id = SecureRandom.uuid
|
172 |
| - stub_user_info_api_for_unknown_users(user_id:) |
173 | 186 | project = create(:project, user_id:)
|
174 | 187 |
|
175 |
| - pair = described_class.all.with_users.first |
| 188 | + pair = described_class.all.with_users(teacher).first |
176 | 189 | expect(pair).to eq([project, nil])
|
177 | 190 | end
|
178 | 191 |
|
179 | 192 | it 'ignores members not included in the current scope' do
|
180 | 193 | create(:project)
|
181 | 194 |
|
182 |
| - pair = described_class.none.with_users.first |
| 195 | + pair = described_class.none.with_users(teacher).first |
183 | 196 | expect(pair).to be_nil
|
184 | 197 | end
|
185 | 198 | end
|
186 | 199 |
|
187 | 200 | describe '#with_user' do
|
188 |
| - # rubocop:disable RSpec/ExampleLength |
| 201 | + let(:student) { create(:student, school:) } |
| 202 | + let(:teacher) { create(:teacher, school:) } |
| 203 | + |
| 204 | + let(:student_attributes) do |
| 205 | + [{ id: student.id, name: student.name, username: student.username }] |
| 206 | + end |
| 207 | + |
| 208 | + before do |
| 209 | + stub_profile_api_list_school_students(school:, student_attributes:) |
| 210 | + end |
| 211 | + |
189 | 212 | it 'returns the class member paired with their User instance' do
|
190 |
| - student = create(:student, school:) |
191 |
| - stub_user_info_api_for(student) |
192 | 213 | project = create(:project, user_id: student.id)
|
193 | 214 |
|
194 |
| - pair = project.with_user |
195 |
| - user = described_class.all.users.first |
| 215 | + pair = project.with_user(teacher) |
| 216 | + user = described_class.all.users(teacher).first |
196 | 217 |
|
197 | 218 | expect(pair).to eq([project, user])
|
198 | 219 | end
|
199 |
| - # rubocop:enable RSpec/ExampleLength |
200 | 220 |
|
201 | 221 | it 'returns a nil value if the member has no profile account' do
|
202 | 222 | user_id = SecureRandom.uuid
|
203 |
| - stub_user_info_api_for_unknown_users(user_id:) |
204 | 223 | project = create(:project, user_id:)
|
205 | 224 |
|
206 |
| - pair = project.with_user |
| 225 | + pair = project.with_user(teacher) |
207 | 226 | expect(pair).to eq([project, nil])
|
208 | 227 | end
|
209 | 228 | end
|
| 229 | + |
| 230 | + describe '#last_edited_at' do |
| 231 | + let(:project) { create(:project, updated_at: 1.day.ago) } |
| 232 | + let(:component) { create(:component, project:, updated_at: 2.days.ago) } |
| 233 | + |
| 234 | + it 'returns the project updated_at if most recent' do |
| 235 | + expect(project.last_edited_at).to eq(project.updated_at) |
| 236 | + end |
| 237 | + |
| 238 | + it 'returns the latest component updated_at if most recent' do |
| 239 | + latest_component = create(:component, project:, updated_at: 1.hour.ago) |
| 240 | + expect(project.last_edited_at).to eq(latest_component.updated_at) |
| 241 | + end |
| 242 | + end |
210 | 243 | end
|
0 commit comments