Skip to content

Commit 062a116

Browse files
Add jim dun seed data (#686)
## What's changed? - Small change to update the test seed data as part of RaspberryPiFoundation/digital-editor-issues#1156 --------- Co-authored-by: mwtrew <9936426+mwtrew@users.noreply.github.com>
1 parent 339c014 commit 062a116

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

lib/tasks/seeds_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ module SeedsHelper
66
john_doe: 'bbb9b8fd-f357-4238-983d-6f87b99bdbb2', # john.doe@example.com
77
jane_smith: 'e52de409-9210-4e94-b08c-dd11439e07d9', # student
88
john_smith: '0d488bec-b10d-46d3-b6f3-4cddf5d90c71', # student
9-
emily_ssouser: '88e0aed6-8f20-4e40-98f9-610a0ab1cfcc' # sso student
9+
emily_ssouser: '88e0aed6-8f20-4e40-98f9-610a0ab1cfcc', # sso student
10+
jim_dun: '019a649f-87f3-483b-8eea-39a05c324264' # user with no school
1011
}.freeze
1112

1213
# Match the school in profile...

lib/tasks/test_seeds.rake

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)