Skip to content

Commit bfbc498

Browse files
committed
An nces district id is 7 digits
1 parent 615375c commit bfbc498

5 files changed

Lines changed: 17 additions & 17 deletions

File tree

app/models/school.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class School < ApplicationRecord
2222
if: :united_kingdom?
2323
validates :district_nces_id,
2424
uniqueness: { conditions: -> { where(rejected_at: nil) }, case_sensitive: false, allow_blank: true, message: I18n.t('validations.school.district_nces_id_exists') },
25-
format: { with: /\A\d{12}\z/, allow_nil: true, message: I18n.t('validations.school.district_nces_id') },
25+
format: { with: /\A\d{7}\z/, allow_nil: true, message: I18n.t('validations.school.district_nces_id') },
2626
presence: true,
2727
if: :united_states?
2828
validates :district_name, presence: true, if: :united_states?

config/locales/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ en:
1717
website: "must be a valid URL"
1818
reference: "must be 5-6 digits (e.g., 100000)"
1919
reference_urn_exists: "URN number already exists"
20-
district_nces_id: "must be 12 digits (e.g., 010000000001)"
20+
district_nces_id: "must be 7 digits (e.g., 0100000)"
2121
district_nces_id_exists: "NCES ID already exists"
2222
school_roll_number: "must be numbers followed by letters (e.g., 01572D)"
2323
school_roll_number_exists: "School roll number already exists"

spec/features/admin/schools_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979

8080
describe 'when the school is in the United States and has a postal code' do
8181
before do
82-
school.update(country_code: 'US', postal_code: '90210', district_name: 'Some District', district_nces_id: '010000000001', reference: nil)
82+
school.update(country_code: 'US', postal_code: '90210', district_name: 'Some District', district_nces_id: '0100000', reference: nil)
8383
get admin_school_path(school)
8484
end
8585

spec/jobs/school_import_job_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
country_code: 'US',
2020
owner_email: 'owner1@example.com',
2121
district_name: 'Some District',
22-
district_nces_id: '010000000001'
22+
district_nces_id: '0100000'
2323
},
2424
{
2525
name: 'Test School 2',
@@ -29,7 +29,7 @@
2929
country_code: 'US',
3030
owner_email: 'owner2@example.com',
3131
district_name: 'Other District',
32-
district_nces_id: '010000000002'
32+
district_nces_id: '0100001'
3333
}
3434
]
3535
end
@@ -130,7 +130,7 @@
130130
'country_code' => 'us',
131131
'owner_email' => 'owner1@example.com',
132132
'district_name' => 'Some District',
133-
'district_nces_id' => '010000000001'
133+
'district_nces_id' => '0100000'
134134
}
135135
]
136136
end

spec/models/school_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let(:student) { create(:student, school:) }
77
let(:teacher) { create(:teacher, school:) }
88
let(:school) { create(:school, creator_id: SecureRandom.uuid) }
9-
let!(:us_school) { create(:school, country_code: 'US', district_name: 'Some District', district_nces_id: '010000000001', creator_id: SecureRandom.uuid) }
9+
let!(:us_school) { create(:school, country_code: 'US', district_name: 'Some District', district_nces_id: '0100000', creator_id: SecureRandom.uuid) }
1010
let!(:ireland_school) { create(:school, country_code: 'IE', school_roll_number: '01572D', creator_id: SecureRandom.uuid) }
1111

1212
describe 'associations' do
@@ -238,38 +238,38 @@
238238
end
239239

240240
it 'requires district_nces_id to be unique if provided' do
241-
duplicate_school = build(:school, country_code: 'US', district_nces_id: '010000000001')
241+
duplicate_school = build(:school, country_code: 'US', district_nces_id: '0100000')
242242
expect(duplicate_school).not_to be_valid
243243
end
244244

245245
it 'returns error if district_nces_id is not unique' do
246-
duplicate_school = build(:school, country_code: 'US', district_nces_id: '010000000001')
246+
duplicate_school = build(:school, country_code: 'US', district_nces_id: '0100000')
247247
duplicate_school.valid?
248248
expect(duplicate_school.errors.details[:district_nces_id]).to include(hash_including(error: :taken))
249249
end
250250

251-
it 'accepts a valid district_nces_id format (12 digits)' do
252-
us_school.district_nces_id = '010000000001'
251+
it 'accepts a valid district_nces_id format (7 digits)' do
252+
us_school.district_nces_id = '0100000'
253253
expect(us_school).to be_valid
254254
end
255255

256256
it 'rejects a district_nces_id with non-digit characters' do
257-
us_school.district_nces_id = '01000000000A'
257+
us_school.district_nces_id = '010000A'
258258
expect(us_school).not_to be_valid
259-
expect(us_school.errors[:district_nces_id]).to include('must be 12 digits (e.g., 010000000001)')
259+
expect(us_school.errors[:district_nces_id]).to include('must be 7 digits (e.g., 0100000)')
260260
end
261261

262262
it 'rejects a district_nces_id with wrong length' do
263-
us_school.district_nces_id = '12345678901'
263+
us_school.district_nces_id = '123456'
264264
expect(us_school).not_to be_valid
265-
expect(us_school.errors[:district_nces_id]).to include('must be 12 digits (e.g., 010000000001)')
265+
expect(us_school.errors[:district_nces_id]).to include('must be 7 digits (e.g., 0100000)')
266266
end
267267

268268
it 'allows district_nces_id reuse when original school is rejected' do
269-
us_school.district_nces_id = '010000000001'
269+
us_school.district_nces_id = '0100000'
270270
us_school.reject
271271

272-
new_school = build(:school, country_code: 'US', district_name: 'Some District', district_nces_id: '010000000001')
272+
new_school = build(:school, country_code: 'US', district_name: 'Some District', district_nces_id: '0100000')
273273
expect(new_school).to be_valid
274274
expect { new_school.save! }.not_to raise_error
275275
end

0 commit comments

Comments
 (0)