Skip to content

Fix validation bug on missions update #338 - #339

Open
Creiwry wants to merge 5 commits into
developmentfrom
fix-bug-on-missions
Open

Fix validation bug on missions update #338#339
Creiwry wants to merge 5 commits into
developmentfrom
fix-bug-on-missions

Conversation

@Creiwry

@Creiwry Creiwry commented Feb 27, 2023

Copy link
Copy Markdown
Collaborator

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

Mate2xo commented Feb 28, 2023

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

@Creiwry
Creiwry requested a review from Mate2xo March 2, 2023 08:40
Comment thread spec/models/enrollment_spec.rb Outdated
end

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

Copy link
Copy Markdown
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 thread spec/models/enrollment_spec.rb Outdated
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
Copy Markdown
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