Open
Conversation
Contributor
bagedevimo
commented
Jul 11, 2025
- Add tests for (and fix) the after_save behaviour for contest
- Refactor contest#after_save
This after_save hook is supposed to be handling the cases where the contest is changed, but there are all sorts of things going on that means it's being overwritten or ignored or just not called at all. I'd like to write out the weird stuff around contest_relation#finish_at, so this is step 1 of that. before_save is changed to after_save, as that's really what it should have been in the first place. The only reason it works now is that the calculation of finish_at is done inside `Contest` instead of `ContestRelation` which is 'a bit odd', but fine.
The prior version of this code is a bit hard to follow as also has one hook doing two responsibilities. This is just a minor factor to hopefully clear it all up a bit and move some of the responsibilities around. The long term goal is to let ContestRelation calculate it's own finish_at from its parent Contest, then changes to Contest just ask ContestRelation to recalculate, like every other way a contest_relation might need to be updated. We _could_ use touch: true on the has_many so that any saved changed to contest causes an update of contest_relation, then have the set_finish_at be a before_validation callback on ContestRelation, but I always feel a little weird about the implictness of that.
9f70875 to
2dcf8fd
Compare
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.