|
135 | 135 | expect(another_school.errors[:creator_id]).to include('has already been taken') |
136 | 136 | end |
137 | 137 |
|
| 138 | + it 'schools can re-use creator_ids if the original school is rejected' do |
| 139 | + rejected_school = create(:school, creator_id: SecureRandom.uuid, rejected_at: Time.zone.now) |
| 140 | + other_school = build(:school, creator_id: rejected_school.creator_id) |
| 141 | + expect(rejected_school).to be_valid |
| 142 | + expect(other_school).to be_valid |
| 143 | + end |
| 144 | + |
138 | 145 | it 'rejects a badly formed url for website' do |
139 | 146 | school.website = 'http://.example.com' |
140 | 147 | expect(school).not_to be_valid |
|
184 | 191 | expect(school).to be_valid |
185 | 192 | end |
186 | 193 |
|
187 | | - it 'rejects a reference with non-digit characters' do |
188 | | - school.reference = 'URN-123' |
| 194 | + it 'rejects new schools with a reference containing non-digit characters' do |
| 195 | + school = build(:school, reference: 'URN-123') |
189 | 196 | expect(school).not_to be_valid |
190 | 197 | expect(school.errors[:reference]).to include('must be 5-6 digits (e.g., 100000)') |
191 | 198 | end |
192 | 199 |
|
193 | | - it 'rejects a reference with too few digits' do |
194 | | - school.reference = '1234' |
| 200 | + it 'rejects new schools with a reference that has too few digits' do |
| 201 | + school = build(:school, reference: '1234') |
195 | 202 | expect(school).not_to be_valid |
196 | 203 | expect(school.errors[:reference]).to include('must be 5-6 digits (e.g., 100000)') |
197 | 204 | end |
198 | 205 |
|
199 | | - it 'rejects a reference with too many digits' do |
200 | | - school.reference = '1234567' |
| 206 | + it 'rejects new schools with a reference that has too many digits' do |
| 207 | + school = build(:school, reference: '1234567') |
201 | 208 | expect(school).not_to be_valid |
202 | 209 | expect(school.errors[:reference]).to include('must be 5-6 digits (e.g., 100000)') |
203 | 210 | end |
|
255 | 262 | expect(us_school).to be_valid |
256 | 263 | end |
257 | 264 |
|
258 | | - it 'rejects a district_nces_id with non-digit characters' do |
259 | | - us_school.district_nces_id = '010000A' |
| 265 | + it 'rejects new schools with a district_nces_id containing non-digit characters' do |
| 266 | + us_school = build(:school, country_code: 'US', district_nces_id: '010000A') |
260 | 267 | expect(us_school).not_to be_valid |
261 | 268 | expect(us_school.errors[:district_nces_id]).to include('must be 7 digits (e.g., 0100000)') |
262 | 269 | end |
263 | 270 |
|
264 | | - it 'rejects a district_nces_id with wrong length' do |
265 | | - us_school.district_nces_id = '123456' |
| 271 | + it 'rejects new schools with a district_nces_id with wrong length' do |
| 272 | + us_school = build(:school, country_code: 'US', district_nces_id: '123456') |
266 | 273 | expect(us_school).not_to be_valid |
267 | 274 | expect(us_school.errors[:district_nces_id]).to include('must be 7 digits (e.g., 0100000)') |
268 | 275 | end |
|
281 | 288 | expect(school).to be_valid |
282 | 289 | end |
283 | 290 |
|
284 | | - it 'requires school_roll_number for Ireland schools' do |
285 | | - ireland_school.school_roll_number = nil |
| 291 | + it 'requires school_roll_number for Ireland for new schools' do |
| 292 | + ireland_school = build(:school, country_code: 'IE', school_roll_number: nil) |
286 | 293 | expect(ireland_school).not_to be_valid |
287 | 294 | expect(ireland_school.errors[:school_roll_number]).to include("can't be blank") |
288 | 295 | end |
|
308 | 315 | expect(ireland_school).to be_valid |
309 | 316 | end |
310 | 317 |
|
311 | | - it 'rejects a school_roll_number with only numbers' do |
312 | | - ireland_school.school_roll_number = '01572' |
| 318 | + it 'rejects new schools with a school_roll_number that contains only numbers' do |
| 319 | + ireland_school = build(:school, country_code: 'IE', school_roll_number: '01572') |
313 | 320 | expect(ireland_school).not_to be_valid |
314 | 321 | expect(ireland_school.errors[:school_roll_number]).to include('must be numbers followed by letters (e.g., 01572D)') |
315 | 322 | end |
316 | 323 |
|
317 | | - it 'rejects a school_roll_number with only letters' do |
318 | | - ireland_school.school_roll_number = 'ABCDE' |
| 324 | + it 'rejects new schools with a school_roll_number containing only letters' do |
| 325 | + ireland_school = build(:school, country_code: 'IE', school_roll_number: 'ABCDE') |
319 | 326 | expect(ireland_school).not_to be_valid |
320 | 327 | expect(ireland_school.errors[:school_roll_number]).to include('must be numbers followed by letters (e.g., 01572D)') |
321 | 328 | end |
322 | 329 |
|
323 | | - it 'rejects a school_roll_number with special characters' do |
324 | | - ireland_school.school_roll_number = '01572-D' |
| 330 | + it 'rejects new schools with a school_roll_number containing special characters' do |
| 331 | + ireland_school = build(:school, country_code: 'IE', school_roll_number: '01572-D') |
325 | 332 | expect(ireland_school).not_to be_valid |
326 | 333 | expect(ireland_school.errors[:school_roll_number]).to include('must be numbers followed by letters (e.g., 01572D)') |
327 | 334 | end |
|
356 | 363 | expect(school).not_to be_valid |
357 | 364 | end |
358 | 365 |
|
359 | | - it 'requires an administrative_area' do |
360 | | - school.administrative_area = ' ' |
| 366 | + it 'requires an administrative_area for new schools' do |
| 367 | + school = build(:school, administrative_area: ' ') |
361 | 368 | expect(school).not_to be_valid |
362 | 369 | end |
363 | 370 |
|
|
0 commit comments