Skip to content

Comments

Add jim dun seed data#686

Open
jamiebenstead wants to merge 1 commit intomainfrom
update-test-seed-data
Open

Add jim dun seed data#686
jamiebenstead wants to merge 1 commit intomainfrom
update-test-seed-data

Conversation

@jamiebenstead
Copy link
Contributor

@jamiebenstead jamiebenstead commented Feb 17, 2026

What's changed?

Copilot AI review requested due to automatic review settings February 17, 2026 15:14
@cla-bot cla-bot bot added the cla-signed label Feb 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new test user jim_dun to the seed data system and updates the test_seeds:destroy rake task to clean up data associated with this user. The PR also includes minor improvements to array syntax in the cleanup logic.

Changes:

  • Added jim_dun test user UUID to TEST_USERS constant in seeds_helper.rb
  • Updated test_seeds:destroy task to clean up roles and optionally schools created by the jim_dun user
  • Refactored array syntax to remove unnecessary nested array wrapping

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
lib/tasks/seeds_helper.rb Adds jim_dun UUID to TEST_USERS hash with comment indicating "user with no school"
lib/tasks/test_seeds.rake Adds cleanup logic for jim_dun's roles and school; refactors array syntax in where clauses

Comment on lines 27 to +30
# 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
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.
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)
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.
Comment on lines +38 to +40
# 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
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.
Comment on lines +15 to +24
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
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.
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.
@mwtrew mwtrew self-assigned this Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants