Skip to content
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

Open
wants to merge 5 commits into
base: development
Choose a base branch
from

Conversation

Creiwry
Copy link
Collaborator

@Creiwry Creiwry commented Feb 27, 2023

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.

@Mate2xo
Copy link
Owner

Mate2xo commented Feb 28, 2023

@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

@Creiwry Creiwry requested a review from Mate2xo March 2, 2023 08:40
@@ -25,6 +25,18 @@
end
end

describe 'validations' do
context 'when a new enrollment is created where mission is full' do
Copy link
Owner

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 ?

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
Copy link
Owner

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

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

@Creiwry Creiwry requested a review from Mate2xo March 22, 2023 19:19
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