Skip to content
Merged
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
3 changes: 2 additions & 1 deletion lib/tasks/seeds_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ module SeedsHelper
john_doe: 'bbb9b8fd-f357-4238-983d-6f87b99bdbb2', # john.doe@example.com
jane_smith: 'e52de409-9210-4e94-b08c-dd11439e07d9', # student
john_smith: '0d488bec-b10d-46d3-b6f3-4cddf5d90c71', # student
emily_ssouser: '88e0aed6-8f20-4e40-98f9-610a0ab1cfcc' # sso student
emily_ssouser: '88e0aed6-8f20-4e40-98f9-610a0ab1cfcc', # sso student
jim_dun: '019a649f-87f3-483b-8eea-39a05c324264' # user with no school
}.freeze

# Match the school in profile...
Expand Down
19 changes: 12 additions & 7 deletions lib/tasks/test_seeds.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,31 @@ namespace :test_seeds do
Rails.logger.info 'Destroying existing seeds...'
creator_id = ENV.fetch('SEEDING_CREATOR_ID', TEST_USERS[:jane_doe])
teacher_id = ENV.fetch('SEEDING_TEACHER_ID', TEST_USERS[:john_doe])
teacher_signup_id = TEST_USERS[:jim_dun]

# Hard coded as the student's school needs to match
student_ids = [TEST_USERS[:jane_smith], TEST_USERS[:john_smith], TEST_USERS[:emily_ssouser]]
school_id = TEST_SCHOOL
teacher_signup_school_id =
School.find_by(creator_id: teacher_signup_id)&.id

# Remove the roles first
Role.where(user_id: teacher_signup_id).destroy_all
Role.where(user_id: [creator_id, teacher_id] + student_ids).destroy_all

# Destroy the project and then the lesson itself (The lesson's `before_destroy` prevents us using destroy)
lesson_ids = Lesson.where(school_id:).pluck(:id)
Project.where(lesson_id: [lesson_ids]).destroy_all
Lesson.where(id: [lesson_ids]).delete_all
Project.where(lesson_id: lesson_ids).destroy_all
Lesson.where(id: lesson_ids).delete_all

# Destroy the class members and then the class itself
school_class_ids = SchoolClass.where(school_id:).pluck(:id)
ClassStudent.where(school_class_id: [school_class_ids]).destroy_all
SchoolClass.where(id: [school_class_ids]).destroy_all
school_class_ids = SchoolClass.where(school_id: [school_id, teacher_signup_school_id].compact).pluck(:id)
ClassStudent.where(school_class_id: school_class_ids).destroy_all
SchoolClass.where(id: school_class_ids).destroy_all

# Destroy the school
School.find(school_id).destroy
# Destroy the schools
school_ids = [school_id, teacher_signup_school_id].compact
School.where(id: school_ids).destroy_all

Rails.logger.info 'Done...'
rescue StandardError => e
Expand Down