-
Notifications
You must be signed in to change notification settings - Fork 480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sample data generation #23558
Sample data generation #23558
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,13 +72,14 @@ def self.seed | |
# dependency when we delete the teacher; but to not leave a trail of | ||
# old test data behind, we explictly hard-delete. | ||
def self.create_teacher(email, password, name) | ||
raise "Should not be run outside of development" unless CDO.rack_env?(:development) | ||
# Delete any existing test data | ||
user = User.find_by_email_or_hashed_email(email) | ||
unless user.nil? | ||
user.sections.each do |section| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: The User.sections association is designated dependent destroy. Same with Section.followers. So, deleting one of these test users will (soft) delete all their sections and followers. It's worth a comment here to explain that this is to also (hard) delete the test users and to hard delete the section. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thx, commented |
||
# Hard-delete all students in each section. | ||
section.students.each do |student_user| | ||
raise "Not a sample student" unless student_user.name =~ SAMPLE_STUDENT_NAME_REGEX | ||
raise "Not a sample student - #{student_user.name}" unless student_user.name =~ SAMPLE_STUDENT_NAME_REGEX | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name is not unique. Why not provide something that we can identify the record with like id or hashed_email? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name is not unique, but it IS identifiable. The only way we could accidentally delete, say, prod data is if someone named a user "TestStudent[#] Codeberg" (AND other code here somehow went berzerk and found it). I think is is a sufficiently robust cross-check for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm referring to the error message, not the check. Getting an error "Not a sample student - Bobby Tables" is not that helpful if we want to find which student that is. I want the error message to have enough context to debug this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In other words, I don't think this really satisfies my earlier request |
||
raise "Should not be run outside of development" unless CDO.rack_env?(:development) | ||
UserGeo.where(user_id: student_user.id).destroy_all | ||
student_user.really_destroy! | ||
|
@@ -88,8 +89,9 @@ def self.create_teacher(email, password, name) | |
end | ||
UserGeo.where(user_id: user.id).destroy_all | ||
# Delete the existing test teacher | ||
raise "Not a sample teacher" unless user.name.eql? SAMPLE_TEACHER_NAME | ||
raise "Not a sample teacher" unless user.email.eql? SAMPLE_TEACHER_EMAIL | ||
unless (user.name.eql? SAMPLE_TEACHER_NAME) && (user.email.eql? SAMPLE_TEACHER_EMAIL) | ||
raise "Not a sample teacher - #{user.name}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Name is not unique. Why not provide something that we can identify the record with like id or email? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do check for email here as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above. I'm referring to the error message |
||
end | ||
raise "Should not be run outside of development" unless CDO.rack_env?(:development) | ||
user.really_destroy! | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since deleting happens in this method that could conceivably in the future be called from anywhere, how about duplicating the
check at the top of this method too, just to be paranoid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see you've done this down on line 82. I'd pull it up here - as currently written, you could hit the hard-delete on a section without raising if that section had no students.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Added another one at top of method. I'd like to have defense in depth as the code changes in the future, perhaps inadvertently gets copied/moved into other contexts, etc.