Fix validation bug on missions update #338 - #339
Open
Creiwry wants to merge 5 commits into
Open
Conversation
…o validate on create only, ticket #338
Owner
|
@Creiwry To be sure we get the intended result, please write a test to simulate what happens on a full slot when another member tries to join in |
Mate2xo
requested changes
Mar 2, 2023
| end | ||
|
|
||
| describe 'validations' do | ||
| context 'when a new enrollment is created where mission is full' do |
Owner
There was a problem hiding this comment.
[...] is created on a full mission
might be better ?
Comment on lines
+30
to
+36
| it 'raises an error' do | ||
| mission = create :mission, max_member_count: 4 | ||
| enroll_n_members_on_mission(mission, 4) | ||
| extra_enrollment = Enrollment.new(mission: mission) | ||
|
|
||
| expect(extra_enrollment).to_not be_valid | ||
| end |
Owner
There was a problem hiding this comment.
Instead of creating a method helper that is used only once in that file (meaning, it only moves the logic elsewhere), I think this setup can be done directly under this context. You could either create a new trait in the mission factory, or directly set the setup here in a let. Here, the let directly illustrates what is the actual context in terms of code
Suggested change
| it 'raises an error' do | |
| mission = create :mission, max_member_count: 4 | |
| enroll_n_members_on_mission(mission, 4) | |
| extra_enrollment = Enrollment.new(mission: mission) | |
| expect(extra_enrollment).to_not be_valid | |
| end | |
| let(:full_mission) do | |
| create :mission, max_member_count: 4 do |mission| | |
| create_list :enrollment, | |
| 4, | |
| mission: mission, | |
| start_time: mission.start_time, | |
| end_time: mission.start_date + 3.hours | |
| end | |
| end | |
| end | |
| it 'is invalid' do | |
| extra_enrollment = Enrollment.new(mission: full_mission) | |
| expect(extra_enrollment).to_not be_valid | |
| end |
Also, it's better to be specific if we can on what error is raised. Here, it's an invalidation
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.
Issue:
The enrollments validator was raising an AvailabilityPlaceValidator error when enrollments were updated. Only this issue from the ticket is being addressed here due to priority.
Implemented changes:
The AvailabilityPlaceValidator scope has been changed to on: create, as that is the only time it is helpful to check if the max_member_count condition has been reached.