Skip to content

feat: refactor group creation#7975

Open
YheChen wants to merge 4 commits into
MarkUsProject:masterfrom
YheChen:feat/auto-group-id
Open

feat: refactor group creation#7975
YheChen wants to merge 4 commits into
MarkUsProject:masterfrom
YheChen:feat/auto-group-id

Conversation

@YheChen
Copy link
Copy Markdown
Contributor

@YheChen YheChen commented Jun 2, 2026

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 Group creation to assign the group's id, group_name, and repo_name up front in a before_validation callback, eliminating the previous "save with nil name → assign name from id → save again" pattern.

What changed:

  • Added before_validation :assign_id_and_default_names, on: :create to Group. The callback reserves the next value from groups_id_seq via nextval, then uses that id to populate id/group_name/repo_name only when the caller hasn't supplied them.
  • Removed the set_repo_name after_create callback. Its job is now done by the new before_validation callback.
  • Converted check_repo_uniqueness from an after_create callback that raised on conflict into a standard validate :check_repo_uniqueness, on: :create that adds an error. This avoids partway-through-creation exceptions.
  • Simplified the four call sites in Assignment#add_group, Assignment#add_group_api, Student#create_group_for_working_alone_student, and Student#create_autogenerated_name_group — each collapses from a four-line save/assign/save dance into a single Group.create / Group.new call.
  • Re-added the NOT NULL constraint on groups.group_name in a new migration, now that the model guarantees the column is set before save. Removed the corresponding missing_non_null_constraint exception from .active_record_doctor.rb.
  • Removed three tests in group_spec.rb (validate_presence_of, validate_uniqueness_of, belong_to(:course) for group_name) that are no longer testable on :create context 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 X or a brief description next to the type or types that best describe your changes.)

Type Applies?
🚨 Breaking change (fix or feature that would cause existing functionality to change)
New feature (non-breaking change that adds functionality)
🐛 Bug fix (non-breaking change that fixes an issue)
🎨 User interface change (change to user interface; provide screenshots)
♻️ Refactoring (internal change to codebase, without changing functionality) x
🚦 Test update (change that only adds or modifies tests)
📦 Dependency update (change that updates a dependency)
🔧 Internal (change that only affects developers or continuous integration)

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:

  • I have performed a self-review of my changes.
    • Check that all changed files included in this pull request are intentional changes.
    • Check that all changes are relevant to the purpose of this pull request, as described above.
  • I have added tests for my changes, if applicable.
    • This is required for all bug fixes and new features.
  • I have updated the project documentation, if applicable.
    • This is required for new features.
  • If this is my first contribution, I have added myself to the list of contributors.

After opening your pull request:

  • I have updated the project Changelog (this is required for all changes).
  • I have verified that the pre-commit.ci checks have passed.
  • I have verified that the CI tests have passed.
  • I have reviewed the test coverage changes reported by Coveralls.
  • I have requested a review from a project maintainer.

Questions and Comments

(Include any questions or comments you have regarding your changes.)

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Jun 2, 2026

Coverage Report for CI Build 26826100410

Warning

No base build found for commit 00ab1bb on master.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 90.314%

Details

  • Patch coverage: 1 uncovered change across 1 file (12 of 13 lines covered, 92.31%).

Uncovered Changes

File Changed Covered %
app/models/group.rb 11 10 90.91%
Total (3 files) 13 12 92.31%

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 49961
Covered Lines: 46086
Line Coverage: 92.24%
Relevant Branches: 2175
Covered Branches: 1000
Branch Coverage: 45.98%
Branches in Coverage %: Yes
Coverage Strength: 125.7 hits per line

💛 - Coveralls

@YheChen YheChen changed the title WIP: feat: refactor group creation feat: refactor group creation Jun 2, 2026
@YheChen YheChen requested a review from david-yz-liu June 2, 2026 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants