Skip to content

Commit 5cd14f0

Browse files
committed
Cover US path deterministically
- district_nces_id now generates 7 digits instead of 12 - we were using school id instead
1 parent 3bcf627 commit 5cd14f0

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/tasks/seeds_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def create_school(creator_id, school_id = nil)
3232
# Country-specific required fields
3333
school.reference = format('%06d', rand(100_000..999_999)) if country_code == 'GB'
3434
if country_code == 'US'
35-
school.district_nces_id = format('%012d', rand(10**12))
35+
school.district_nces_id = format('%07d', rand(10**7))
3636
school.district_name = Faker::Address.community
3737
end
3838
school.school_roll_number = "#{rand(10_000..99_999)}#{('A'..'Z').to_a.sample}" if country_code == 'IE'

spec/lib/test_seeds_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@
3636

3737
describe ':seed_a_school_with_lessons_and_students' do
3838
let(:task) { Rake::Task['test_seeds:create'] }
39+
let(:seed_country_code) { nil }
3940

4041
before do
42+
allow(Faker::Address).to receive(:country_code).and_return(seed_country_code) if seed_country_code
4143
task.reenable
4244
task.invoke
4345
end
@@ -90,5 +92,20 @@
9092
expect(Role.student.where(user_id: student_2, school_id:)).to exist
9193
expect(ClassStudent.where(student_id: student_2, school_class_id:)).to exist
9294
end
95+
96+
context 'when the seeded school is in the US' do
97+
let(:seed_country_code) { 'US' }
98+
99+
it 'creates a valid school and owner lessons' do
100+
school = School.find_by(creator_id:)
101+
school_class = SchoolClass.joins(:teachers).find_by(school_id: school.id, teachers: { teacher_id: creator_id })
102+
103+
expect(school).to be_valid
104+
expect(school.district_nces_id).to match(/\A\d{7}\z/)
105+
expect(school.district_name).to be_present
106+
expect(school_class).not_to be_nil
107+
expect(Lesson.where(school_id: school.id, school_class_id: school_class.id).length).to eq(2)
108+
end
109+
end
93110
end
94111
end

0 commit comments

Comments
 (0)