File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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'
Original file line number Diff line number Diff line change 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
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
94111end
You can’t perform that action at this time.
0 commit comments