From c3b84d40cbf0a57274082a72824795a136286e46 Mon Sep 17 00:00:00 2001 From: Creiwry Date: Fri, 3 Mar 2023 19:18:52 +0100 Subject: [PATCH] refactor(test): make changes to the enrollment validation test based on feedback #338 --- spec/models/enrollment_spec.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/spec/models/enrollment_spec.rb b/spec/models/enrollment_spec.rb index 93cf74d2..e0edc96a 100644 --- a/spec/models/enrollment_spec.rb +++ b/spec/models/enrollment_spec.rb @@ -26,11 +26,19 @@ end describe 'validations' do - context 'when a new enrollment is created where mission is full' do - 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) + context 'when a new enrollment is created on a full mission' do + let(:full_mission) do + create :mission, max_member_count:4 do |mission| + create_list :enrollment, + 4, + mission: mission, + start_time: mission.start_date, + end_time: mission.start_date + 3.hours + end + end + + it 'the enrollment is invalid' do + extra_enrollment = Enrollment.new(mission: full_mission) expect(extra_enrollment).to_not be_valid end @@ -70,15 +78,4 @@ end end end - - def enroll_n_members_on_mission(mission, members_count) - members = create_list :member, members_count - members.each do |member| - create :enrollment, - member: member, - mission: mission, - start_time: mission.start_date, - end_time: mission.start_date + 3.hours - end - end end