Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tasks/seeds_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create_school(creator_id, school_id = nil)
# Country-specific required fields
school.reference = format('%06d', rand(100_000..999_999)) if country_code == 'GB'
if country_code == 'US'
school.district_nces_id = format('%012d', rand(10**12))
school.district_nces_id = format('%07d', rand(10**7))
school.district_name = Faker::Address.community
end
school.school_roll_number = "#{rand(10_000..99_999)}#{('A'..'Z').to_a.sample}" if country_code == 'IE'
Expand Down
17 changes: 17 additions & 0 deletions spec/lib/test_seeds_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@

describe ':seed_a_school_with_lessons_and_students' do
let(:task) { Rake::Task['test_seeds:create'] }
let(:seed_country_code) { nil }

before do
allow(Faker::Address).to receive(:country_code).and_return(seed_country_code) if seed_country_code
task.reenable
task.invoke
end
Expand Down Expand Up @@ -90,5 +92,20 @@
expect(Role.student.where(user_id: student_2, school_id:)).to exist
expect(ClassStudent.where(student_id: student_2, school_class_id:)).to exist
end

context 'when the seeded school is in the US' do
let(:seed_country_code) { 'US' }

it 'creates a valid school and owner lessons' do
school = School.find_by(creator_id:)
school_class = SchoolClass.joins(:teachers).find_by(school_id: school.id, teachers: { teacher_id: creator_id })

expect(school).to be_valid
expect(school.district_nces_id).to match(/\A\d{7}\z/)
expect(school.district_name).to be_present
expect(school_class).not_to be_nil
expect(Lesson.where(school_id: school.id, school_class_id: school_class.id).length).to eq(2)
end
end
end
end
Loading