Skip to content

Commit

Permalink
refactor(test): make changes to the enrollment validation test based …
Browse files Browse the repository at this point in the history
…on feedback #338
  • Loading branch information
Creiwry committed Mar 3, 2023
1 parent 2eb0f76 commit c3b84d4
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions spec/models/enrollment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit c3b84d4

Please sign in to comment.