feat: refactor group creation#7975
Open
YheChen wants to merge 4 commits into
Open
Conversation
Collaborator
Coverage Report for CI Build 26826100410Warning No base build found for commit Coverage: 90.314%Details
Uncovered Changes
Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
(Describe your changes here. Also describe the motivation for your changes: what problem do they solve, or how do they improve the application or codebase? If this pull request fixes an open issue, use a keyword to link this pull request to the issue.)
Refactors
Groupcreation to assign the group'sid,group_name, andrepo_nameup front in abefore_validationcallback, eliminating the previous "save with nil name → assign name from id → save again" pattern.What changed:
before_validation :assign_id_and_default_names, on: :createtoGroup. The callback reserves the next value fromgroups_id_seqvianextval, then uses that id to populateid/group_name/repo_nameonly when the caller hasn't supplied them.set_repo_nameafter_createcallback. Its job is now done by the newbefore_validationcallback.check_repo_uniquenessfrom anafter_createcallback that raised on conflict into a standardvalidate :check_repo_uniqueness, on: :createthat adds an error. This avoids partway-through-creation exceptions.Assignment#add_group,Assignment#add_group_api,Student#create_group_for_working_alone_student, andStudent#create_autogenerated_name_group— each collapses from a four-line save/assign/save dance into a singleGroup.create/Group.newcall.NOT NULLconstraint ongroups.group_namein a new migration, now that the model guarantees the column is set before save. Removed the correspondingmissing_non_null_constraintexception from.active_record_doctor.rb.group_spec.rb(validate_presence_of,validate_uniqueness_of,belong_to(:course)forgroup_name) that are no longer testable on:createcontext as the callback fills nil values before validation runs. Added a comment noting that those invariants are now enforced by the callback, the unique index, and the foreign key respectively.Screenshots of your changes (if applicable)
Associated documentation repository pull request (if applicable)
Type of Change
(Write an
Xor a brief description next to the type or types that best describe your changes.)Checklist
(Complete each of the following items for your pull request. Indicate that you have completed an item by changing the
[ ]into a[x]in the raw text, or by clicking on the checkbox in the rendered description on GitHub.)Before opening your pull request:
After opening your pull request:
Questions and Comments
(Include any questions or comments you have regarding your changes.)