Skip to content

Commit e4b21b5

Browse files
committed
fix: use sponsor capacity for in-person workshop attendance checks
PR #2609 changed WorkshopPresenter to use model.student_spaces and model.coach_spaces for capacity checks, but this broke in-person workshops that rely on sponsor capacity. Most in-person workshops have student_spaces=0 and coach_spaces=0 in the database, with actual capacity coming from the sponsor/venue. This fix changes event_student_spaces? and event_coach_spaces? to use the presenter methods student_spaces and coach_spaces, which delegate to the sponsor for in-person workshops. - In-person workshops: use venue.seats and venue.coach_spots - Virtual workshops: use model.student_spaces and model.coach_spaces Fixes: Workshops incorrectly showing as full when sponsor has capacity
1 parent b381129 commit e4b21b5

4 files changed

Lines changed: 77 additions & 5 deletions

File tree

app/presenters/workshop_presenter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ def student_spaces
7575
end
7676

7777
def event_student_spaces?
78-
model.student_spaces > attending_students.length
78+
student_spaces > attending_students.length
7979
end
8080

8181
def event_coach_spaces?
82-
model.coach_spaces > attending_coaches.length
82+
coach_spaces > attending_coaches.length
8383
end
8484

8585
def pairing_csv

spec/features/accepting_invitation_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55
let(:invitation_route) { invitation_path(invitation) }
66
let(:accept_invitation_route) { accept_invitation_path(invitation) }
77
let(:reject_invitation_route) { reject_invitation_path(invitation) }
8-
let(:set_no_available_slots) { invitation.workshop.update_attribute(:student_spaces, 0) }
8+
let(:set_no_available_slots) do
9+
# Fill up the workshop by creating attending students up to capacity
10+
# This ensures the waiting list/full state is triggered properly
11+
workshop = invitation.workshop
12+
capacity = workshop.host.seats
13+
attending_count = workshop.attending_students.count
14+
spots_to_fill = capacity - attending_count
15+
16+
spots_to_fill.times do
17+
member = Fabricate(:member)
18+
Fabricate(:workshop_invitation, workshop: workshop, member: member, role: 'Student', attending: true)
19+
end
20+
end
921
let!(:tutorial) { Fabricate(:tutorial) }
1022

1123
it_behaves_like 'invitation route'

spec/features/coach_accepting_invitation_spec.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,19 @@
66
let(:reject_invitation_route) { reject_invitation_path(invitation) }
77
let(:accept_invitation_route) { accept_invitation_path(invitation) }
88

9-
let(:set_no_available_slots) { invitation.workshop.update_attribute(:coach_spaces, 0) }
9+
let(:set_no_available_slots) do
10+
# Fill up the workshop by creating attending coaches up to capacity
11+
# This ensures the waiting list/full state is triggered properly
12+
workshop = invitation.workshop
13+
capacity = workshop.host.coach_spots
14+
attending_count = workshop.attending_coaches.count
15+
spots_to_fill = capacity - attending_count
16+
17+
spots_to_fill.times do
18+
member = Fabricate(:member)
19+
Fabricate(:workshop_invitation, workshop: workshop, member: member, role: 'Coach', attending: true)
20+
end
21+
end
1022

1123
before(:each) do
1224
login(member)

spec/presenters/workshop_presenter_capacity_spec.rb

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
it 'returns false when no spaces are available' do
1818
expect(workshop.attending_students.count).to eq(2)
1919
expect(workshop.student_spaces).to eq(2)
20-
expect(presenter.event_student_spaces?).to eq(false),
20+
expect(presenter.event_student_spaces?).to eq(false),
2121
"Expected event_student_spaces? to be false when at capacity (2/2), but got true"
2222
end
2323
end
@@ -36,6 +36,30 @@
3636
"Expected event_student_spaces? to be true when spaces available (1/2), but got false"
3737
end
3838
end
39+
40+
context 'when workshop.student_spaces is 0 but sponsor has capacity (production data scenario)' do
41+
let(:sponsor) { Fabricate(:sponsor, seats: 20, number_of_coaches: 10) }
42+
let(:workshop_with_zero_spaces) do
43+
Fabricate(:workshop_no_sponsor, student_spaces: 0, coach_spaces: 0).tap do |ws|
44+
Fabricate(:workshop_sponsor, workshop: ws, sponsor: sponsor, host: true)
45+
end
46+
end
47+
let(:presenter_zero_spaces) { WorkshopPresenter.new(workshop_with_zero_spaces) }
48+
49+
before do
50+
# Create 1 attending student
51+
member = Fabricate(:member)
52+
Fabricate(:workshop_invitation, workshop: workshop_with_zero_spaces, member: member, role: 'Student', attending: true)
53+
end
54+
55+
it 'returns true because capacity comes from sponsor, not workshop.student_spaces' do
56+
expect(workshop_with_zero_spaces.attending_students.count).to eq(1)
57+
expect(workshop_with_zero_spaces.student_spaces).to eq(0)
58+
expect(presenter_zero_spaces.student_spaces).to eq(20), 'Capacity should come from sponsor'
59+
expect(presenter_zero_spaces.event_student_spaces?).to eq(true),
60+
"Expected event_student_spaces? to be true when sponsor has capacity (1/20), but got false"
61+
end
62+
end
3963
end
4064

4165
describe '#event_coach_spaces?' do
@@ -71,5 +95,29 @@
7195
"Expected event_coach_spaces? to be true when spaces available (1/2), but got false"
7296
end
7397
end
98+
99+
context 'when workshop.coach_spaces is 0 but sponsor has capacity (production data scenario)' do
100+
let(:sponsor) { Fabricate(:sponsor, seats: 20, number_of_coaches: 10) }
101+
let(:workshop_with_zero_spaces) do
102+
Fabricate(:workshop_no_sponsor, student_spaces: 0, coach_spaces: 0).tap do |ws|
103+
Fabricate(:workshop_sponsor, workshop: ws, sponsor: sponsor, host: true)
104+
end
105+
end
106+
let(:presenter_zero_spaces) { WorkshopPresenter.new(workshop_with_zero_spaces) }
107+
108+
before do
109+
# Create 1 attending coach
110+
member = Fabricate(:member)
111+
Fabricate(:workshop_invitation, workshop: workshop_with_zero_spaces, member: member, role: 'Coach', attending: true)
112+
end
113+
114+
it 'returns true because capacity comes from sponsor, not workshop.coach_spaces' do
115+
expect(workshop_with_zero_spaces.attending_coaches.count).to eq(1)
116+
expect(workshop_with_zero_spaces.coach_spaces).to eq(0)
117+
expect(presenter_zero_spaces.coach_spaces).to eq(10), 'Capacity should come from sponsor'
118+
expect(presenter_zero_spaces.event_coach_spaces?).to eq(true),
119+
"Expected event_coach_spaces? to be true when sponsor has capacity (1/10), but got false"
120+
end
121+
end
74122
end
75123
end

0 commit comments

Comments
 (0)