@@ -12,26 +12,31 @@ namespace :test_seeds do
1212 Rails . logger . info 'Destroying existing seeds...'
1313 creator_id = ENV . fetch ( 'SEEDING_CREATOR_ID' , TEST_USERS [ :jane_doe ] )
1414 teacher_id = ENV . fetch ( 'SEEDING_TEACHER_ID' , TEST_USERS [ :john_doe ] )
15+ teacher_signup_id = TEST_USERS [ :jim_dun ]
1516
1617 # Hard coded as the student's school needs to match
1718 student_ids = [ TEST_USERS [ :jane_smith ] , TEST_USERS [ :john_smith ] , TEST_USERS [ :emily_ssouser ] ]
1819 school_id = TEST_SCHOOL
20+ teacher_signup_school_id =
21+ School . find_by ( creator_id : teacher_signup_id ) &.id
1922
2023 # Remove the roles first
24+ Role . where ( user_id : teacher_signup_id ) . destroy_all
2125 Role . where ( user_id : [ creator_id , teacher_id ] + student_ids ) . destroy_all
2226
2327 # Destroy the project and then the lesson itself (The lesson's `before_destroy` prevents us using destroy)
2428 lesson_ids = Lesson . where ( school_id :) . pluck ( :id )
25- Project . where ( lesson_id : [ lesson_ids ] ) . destroy_all
26- Lesson . where ( id : [ lesson_ids ] ) . delete_all
29+ Project . where ( lesson_id : lesson_ids ) . destroy_all
30+ Lesson . where ( id : lesson_ids ) . delete_all
2731
2832 # Destroy the class members and then the class itself
29- school_class_ids = SchoolClass . where ( school_id :) . pluck ( :id )
30- ClassStudent . where ( school_class_id : [ school_class_ids ] ) . destroy_all
31- SchoolClass . where ( id : [ school_class_ids ] ) . destroy_all
33+ school_class_ids = SchoolClass . where ( school_id : [ school_id , teacher_signup_school_id ] . compact ) . pluck ( :id )
34+ ClassStudent . where ( school_class_id : school_class_ids ) . destroy_all
35+ SchoolClass . where ( id : school_class_ids ) . destroy_all
3236
33- # Destroy the school
34- School . find ( school_id ) . destroy
37+ # Destroy the schools
38+ school_ids = [ school_id , teacher_signup_school_id ] . compact
39+ School . where ( id : school_ids ) . destroy_all
3540
3641 Rails . logger . info 'Done...'
3742 rescue StandardError => e
0 commit comments