Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/presenters/workshop_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ def student_spaces
end

def event_student_spaces?
model.student_spaces > attending_students.length
student_spaces > attending_students.length
end

def event_coach_spaces?
model.coach_spaces > attending_coaches.length
coach_spaces > attending_coaches.length
end

def pairing_csv
Expand Down
14 changes: 13 additions & 1 deletion spec/features/accepting_invitation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,19 @@
let(:invitation_route) { invitation_path(invitation) }
let(:accept_invitation_route) { accept_invitation_path(invitation) }
let(:reject_invitation_route) { reject_invitation_path(invitation) }
let(:set_no_available_slots) { invitation.workshop.update_attribute(:student_spaces, 0) }
let(:set_no_available_slots) do
# Fill up the workshop by creating attending students up to capacity
# This ensures the waiting list/full state is triggered properly
workshop = invitation.workshop
capacity = workshop.host.seats
attending_count = workshop.attending_students.count
spots_to_fill = capacity - attending_count

spots_to_fill.times do
member = Fabricate(:member)
Fabricate(:workshop_invitation, workshop: workshop, member: member, role: 'Student', attending: true)
end
end
let!(:tutorial) { Fabricate(:tutorial) }

it_behaves_like 'invitation route'
Expand Down
14 changes: 13 additions & 1 deletion spec/features/coach_accepting_invitation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
let(:reject_invitation_route) { reject_invitation_path(invitation) }
let(:accept_invitation_route) { accept_invitation_path(invitation) }

let(:set_no_available_slots) { invitation.workshop.update_attribute(:coach_spaces, 0) }
let(:set_no_available_slots) do
# Fill up the workshop by creating attending coaches up to capacity
# This ensures the waiting list/full state is triggered properly
workshop = invitation.workshop
capacity = workshop.host.coach_spots
attending_count = workshop.attending_coaches.count
spots_to_fill = capacity - attending_count

spots_to_fill.times do
member = Fabricate(:member)
Fabricate(:workshop_invitation, workshop: workshop, member: member, role: 'Coach', attending: true)
end
end

before(:each) do
login(member)
Expand Down
50 changes: 49 additions & 1 deletion spec/presenters/workshop_presenter_capacity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
it 'returns false when no spaces are available' do
expect(workshop.attending_students.count).to eq(2)
expect(workshop.student_spaces).to eq(2)
expect(presenter.event_student_spaces?).to eq(false),
expect(presenter.event_student_spaces?).to eq(false),
"Expected event_student_spaces? to be false when at capacity (2/2), but got true"
end
end
Expand All @@ -36,6 +36,30 @@
"Expected event_student_spaces? to be true when spaces available (1/2), but got false"
end
end

context 'when workshop.student_spaces is 0 but sponsor has capacity (production data scenario)' do
let(:sponsor) { Fabricate(:sponsor, seats: 20, number_of_coaches: 10) }
let(:workshop_with_zero_spaces) do
Fabricate(:workshop_no_sponsor, student_spaces: 0, coach_spaces: 0).tap do |ws|
Fabricate(:workshop_sponsor, workshop: ws, sponsor: sponsor, host: true)
end
end
let(:presenter_zero_spaces) { WorkshopPresenter.new(workshop_with_zero_spaces) }

before do
# Create 1 attending student
member = Fabricate(:member)
Fabricate(:workshop_invitation, workshop: workshop_with_zero_spaces, member: member, role: 'Student', attending: true)
end

it 'returns true because capacity comes from sponsor, not workshop.student_spaces' do
expect(workshop_with_zero_spaces.attending_students.count).to eq(1)
expect(workshop_with_zero_spaces.student_spaces).to eq(0)
expect(presenter_zero_spaces.student_spaces).to eq(20), 'Capacity should come from sponsor'
expect(presenter_zero_spaces.event_student_spaces?).to eq(true),
"Expected event_student_spaces? to be true when sponsor has capacity (1/20), but got false"
end
end
end

describe '#event_coach_spaces?' do
Expand Down Expand Up @@ -71,5 +95,29 @@
"Expected event_coach_spaces? to be true when spaces available (1/2), but got false"
end
end

context 'when workshop.coach_spaces is 0 but sponsor has capacity (production data scenario)' do
let(:sponsor) { Fabricate(:sponsor, seats: 20, number_of_coaches: 10) }
let(:workshop_with_zero_spaces) do
Fabricate(:workshop_no_sponsor, student_spaces: 0, coach_spaces: 0).tap do |ws|
Fabricate(:workshop_sponsor, workshop: ws, sponsor: sponsor, host: true)
end
end
let(:presenter_zero_spaces) { WorkshopPresenter.new(workshop_with_zero_spaces) }

before do
# Create 1 attending coach
member = Fabricate(:member)
Fabricate(:workshop_invitation, workshop: workshop_with_zero_spaces, member: member, role: 'Coach', attending: true)
end

it 'returns true because capacity comes from sponsor, not workshop.coach_spaces' do
expect(workshop_with_zero_spaces.attending_coaches.count).to eq(1)
expect(workshop_with_zero_spaces.coach_spaces).to eq(0)
expect(presenter_zero_spaces.coach_spaces).to eq(10), 'Capacity should come from sponsor'
expect(presenter_zero_spaces.event_coach_spaces?).to eq(true),
"Expected event_coach_spaces? to be true when sponsor has capacity (1/10), but got false"
end
end
end
end