-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fix validation bug on missions update #338 #339
base: development
Are you sure you want to change the base?
Conversation
…o validate on create only, ticket #338
@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 |
spec/models/enrollment_spec.rb
Outdated
@@ -25,6 +25,18 @@ | |||
end | |||
end | |||
|
|||
describe 'validations' do | |||
context 'when a new enrollment is created where mission is full' do |
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.
[...] is created on a full mission
might be better ?
spec/models/enrollment_spec.rb
Outdated
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 |
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.
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
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
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.