Skip to content
Open
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
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "user with no school", but the code at lines 20-21 and 40 specifically looks for and destroys a school created by this user. This creates an inconsistency - either jim_dun should never have a school (in which case lines 20-21 and 40 are unnecessary), or the comment should be updated to reflect that jim_dun might create a school during testing.

Consider clarifying the intended behavior and updating either the comment or the code accordingly.

Suggested change
jim_dun: '019a649f-87f3-483b-8eea-39a05c324264' # user with no school
jim_dun: '019a649f-87f3-483b-8eea-39a05c324264' # user initially without a school (can be used to create schools in tests)

Copilot uses AI. Check for mistakes.
}.freeze

# Match the school in profile...
Expand Down
18 changes: 12 additions & 6 deletions lib/tasks/test_seeds.rake
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,32 @@ 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
Comment on lines +15 to +24
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test suite for test_seeds:destroy doesn't verify the new jim_dun cleanup logic. Consider adding test coverage for scenarios where teacher_signup_id (jim_dun) has associated roles and potentially a school, to ensure the cleanup works correctly.

Copilot uses AI. Check for mistakes.
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
Comment on lines 27 to +30
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup logic only processes lessons and projects for the primary school_id (TEST_SCHOOL), but doesn't handle the teacher_signup_school_id. If jim_dun has created a school with lessons and projects, those won't be cleaned up before the school is destroyed at line 40. This could lead to orphaned records or issues with the Lesson before_destroy callback.

Consider extending the cleanup to include both schools, similar to:

lesson_ids = Lesson.where(school_id: [school_id, teacher_signup_school_id].compact).pluck(:id)

Copilot uses AI. Check for mistakes.

# Destroy the class members and then the class itself
school_class_ids = SchoolClass.where(school_id:).pluck(:id)
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SchoolClass cleanup only handles the primary school_id, not the teacher_signup_school_id. If jim_dun has created a school with classes and class members, those won't be cleaned up before the school is destroyed at line 40.

Consider extending the cleanup to include both schools:

school_class_ids = SchoolClass.where(school_id: [school_id, teacher_signup_school_id].compact).pluck(:id)
Suggested change
school_class_ids = SchoolClass.where(school_id:).pluck(:id)
school_class_ids = SchoolClass.where(school_id: [school_id, teacher_signup_school_id].compact).pluck(:id)

Copilot uses AI. Check for mistakes.
ClassStudent.where(school_class_id: [school_class_ids]).destroy_all
SchoolClass.where(id: [school_class_ids]).destroy_all
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_id).destroy_all
School.where(id: teacher_signup_school_id).destroy_all
Comment on lines +38 to +40
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commented-out code suggests the intended approach was to use compact to handle nil values. Either remove this commented line or refactor lines 39-40 to use this more elegant approach:

School.where(id: [school_id, teacher_signup_school_id].compact).destroy_all

This would handle both schools in a single call and safely exclude nil values.

Suggested change
# school_ids = [school_id, teacher_signup_school_id].compact
School.where(id: school_id).destroy_all
School.where(id: teacher_signup_school_id).destroy_all
School.where(id: [school_id, teacher_signup_school_id].compact).destroy_all

Copilot uses AI. Check for mistakes.

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