|
330 | 330 | it 'sets the user_origin to for_education by default' do |
331 | 331 | expect(school.user_origin).to eq('for_education') |
332 | 332 | end |
333 | | - |
334 | | - describe 'duplicate detection' do |
335 | | - let(:existing_school) do |
336 | | - create(:school, |
337 | | - name: 'Riverside Academy', |
338 | | - municipality: 'Greenville', |
339 | | - postal_code: 'GV1 2XY', |
340 | | - administrative_area: 'Greenshire') |
341 | | - end |
342 | | - |
343 | | - before { existing_school } |
344 | | - |
345 | | - it 'allows schools with the same name in different countries' do |
346 | | - duplicate = build(:school, |
347 | | - name: existing_school.name, |
348 | | - municipality: existing_school.municipality, |
349 | | - postal_code: existing_school.postal_code, |
350 | | - administrative_area: existing_school.administrative_area, |
351 | | - country_code: 'US') |
352 | | - expect(duplicate).to be_valid |
353 | | - end |
354 | | - |
355 | | - it 'allows schools with the same name in different cities' do |
356 | | - duplicate = build(:school, |
357 | | - name: existing_school.name, |
358 | | - municipality: 'Bluetown', |
359 | | - postal_code: 'BT3 4ZW', |
360 | | - administrative_area: 'Blueshire') |
361 | | - expect(duplicate).to be_valid |
362 | | - end |
363 | | - |
364 | | - it 'allows schools with the same name but very different postal codes' do |
365 | | - duplicate = build(:school, |
366 | | - name: existing_school.name, |
367 | | - municipality: existing_school.municipality, |
368 | | - postal_code: 'NE1 7RU', |
369 | | - administrative_area: existing_school.administrative_area) |
370 | | - expect(duplicate).to be_valid |
371 | | - end |
372 | | - |
373 | | - it 'blocks duplicate with missing apostrophe in name' do |
374 | | - duplicate = build(:school, |
375 | | - name: 'Riverside Acadmy', |
376 | | - municipality: existing_school.municipality, |
377 | | - postal_code: existing_school.postal_code, |
378 | | - administrative_area: existing_school.administrative_area) |
379 | | - expect { duplicate.save! }.to raise_error(School::DuplicateSchoolError, I18n.t('validations.school.duplicate_school')) |
380 | | - end |
381 | | - |
382 | | - it 'blocks duplicate with typo in name' do |
383 | | - duplicate = build(:school, |
384 | | - name: 'Riversid Academy', |
385 | | - municipality: existing_school.municipality, |
386 | | - postal_code: existing_school.postal_code, |
387 | | - administrative_area: existing_school.administrative_area) |
388 | | - expect { duplicate.save! }.to raise_error(School::DuplicateSchoolError, I18n.t('validations.school.duplicate_school')) |
389 | | - end |
390 | | - |
391 | | - it 'blocks duplicate with similar municipality spelling' do |
392 | | - duplicate = build(:school, |
393 | | - name: existing_school.name, |
394 | | - municipality: 'Greenvile', |
395 | | - postal_code: existing_school.postal_code, |
396 | | - administrative_area: existing_school.administrative_area) |
397 | | - expect { duplicate.save! }.to raise_error(School::DuplicateSchoolError, I18n.t('validations.school.duplicate_school')) |
398 | | - end |
399 | | - |
400 | | - it 'blocks duplicate with slightly different postal code spacing' do |
401 | | - duplicate = build(:school, |
402 | | - name: existing_school.name, |
403 | | - municipality: existing_school.municipality, |
404 | | - postal_code: 'GV12XY', |
405 | | - administrative_area: existing_school.administrative_area) |
406 | | - expect { duplicate.save! }.to raise_error(School::DuplicateSchoolError, I18n.t('validations.school.duplicate_school')) |
407 | | - end |
408 | | - |
409 | | - it 'allows updating existing school without triggering duplicate detection' do |
410 | | - existing_school.update(address_line_1: Faker::Address.street_address) |
411 | | - expect(existing_school).to be_valid |
412 | | - end |
413 | | - |
414 | | - it 'allows school with very different name despite same location' do |
415 | | - duplicate = build(:school, |
416 | | - name: 'Completely Different Academy', |
417 | | - municipality: existing_school.municipality, |
418 | | - postal_code: existing_school.postal_code, |
419 | | - administrative_area: existing_school.administrative_area) |
420 | | - expect(duplicate).to be_valid |
421 | | - end |
422 | | - |
423 | | - it 'allows schools with similar but sufficiently different names in same location' do |
424 | | - duplicate = build(:school, |
425 | | - name: 'Riverside Institute', |
426 | | - municipality: existing_school.municipality, |
427 | | - postal_code: existing_school.postal_code, |
428 | | - administrative_area: existing_school.administrative_area) |
429 | | - expect(duplicate).to be_valid |
430 | | - end |
431 | | - end |
432 | 333 | end |
433 | 334 |
|
434 | 335 | describe '#creator' do |
|
0 commit comments