|
17 | 17 | it 'returns false when no spaces are available' do |
18 | 18 | expect(workshop.attending_students.count).to eq(2) |
19 | 19 | 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), |
21 | 21 | "Expected event_student_spaces? to be false when at capacity (2/2), but got true" |
22 | 22 | end |
23 | 23 | end |
|
36 | 36 | "Expected event_student_spaces? to be true when spaces available (1/2), but got false" |
37 | 37 | end |
38 | 38 | 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 |
39 | 63 | end |
40 | 64 |
|
41 | 65 | describe '#event_coach_spaces?' do |
|
71 | 95 | "Expected event_coach_spaces? to be true when spaces available (1/2), but got false" |
72 | 96 | end |
73 | 97 | 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 |
74 | 122 | end |
75 | 123 | end |
0 commit comments