|
45 | 45 | end.to change(WaitingList, :count).by(1) |
46 | 46 | end |
47 | 47 | end |
| 48 | + |
| 49 | + context 'when the custom close time has passed' do |
| 50 | + let(:workshop) { Fabricate(:workshop, rsvp_closes_at: 1.hour.ago, date_and_time: 4.hours.from_now) } |
| 51 | + |
| 52 | + it 'does not create a waiting list entry' do |
| 53 | + expect do |
| 54 | + post :create, params: { invitation_id: invitation.token } |
| 55 | + end.not_to change(WaitingList, :count) |
| 56 | + end |
| 57 | + |
| 58 | + it 'redirects with a closed message' do |
| 59 | + post :create, params: { invitation_id: invitation.token } |
| 60 | + |
| 61 | + expect(flash[:notice]).to include('RSVPs have now closed for this workshop') |
| 62 | + end |
| 63 | + end |
| 64 | + |
| 65 | + context 'when the 3.5 hour freeze has been reached' do |
| 66 | + let(:workshop) { Fabricate(:workshop, date_and_time: 3.hours.from_now) } |
| 67 | + |
| 68 | + it 'does not create a waiting list entry' do |
| 69 | + expect do |
| 70 | + post :create, params: { invitation_id: invitation.token } |
| 71 | + end.not_to change(WaitingList, :count) |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + context 'when the custom close time is later than the freeze' do |
| 76 | + let(:workshop) { Fabricate(:workshop, rsvp_closes_at: 2.hours.from_now, date_and_time: 4.hours.from_now) } |
| 77 | + |
| 78 | + # The earlier of the two instants is the gate: joins still work until |
| 79 | + # the freeze, even though the custom close time has not passed yet. |
| 80 | + it 'creates a waiting list entry' do |
| 81 | + expect do |
| 82 | + post :create, params: { invitation_id: invitation.token } |
| 83 | + end.to change(WaitingList, :count).by(1) |
| 84 | + end |
| 85 | + end |
| 86 | + |
| 87 | + context 'when the freeze passed but the custom close time is still in the future' do |
| 88 | + let(:workshop) { Fabricate(:workshop, rsvp_closes_at: 2.hours.from_now, date_and_time: 3.hours.from_now) } |
| 89 | + |
| 90 | + it 'does not create a waiting list entry' do |
| 91 | + expect do |
| 92 | + post :create, params: { invitation_id: invitation.token } |
| 93 | + end.not_to change(WaitingList, :count) |
| 94 | + end |
| 95 | + end |
48 | 96 | end |
49 | 97 |
|
50 | 98 | describe 'DELETE #destroy' do |
|
60 | 108 | end.to change(WaitingList, :count).by(-1) |
61 | 109 | end |
62 | 110 | end |
| 111 | + |
| 112 | + context 'when the waitlist is closed' do |
| 113 | + let(:waiting_list) { Fabricate(:waiting_list) } |
| 114 | + let(:invitation) { waiting_list.invitation } |
| 115 | + |
| 116 | + before do |
| 117 | + invitation.workshop.update!(date_and_time: 3.hours.from_now) |
| 118 | + invitation # materialize the fabricated waiting list entry outside the change block |
| 119 | + end |
| 120 | + |
| 121 | + it 'keeps the entry on the waiting list' do |
| 122 | + expect do |
| 123 | + delete :destroy, params: { invitation_id: invitation.token } |
| 124 | + end.not_to change(WaitingList, :count) |
| 125 | + end |
| 126 | + |
| 127 | + it 'redirects with a closed message' do |
| 128 | + delete :destroy, params: { invitation_id: invitation.token } |
| 129 | + |
| 130 | + expect(flash[:notice]).to include('RSVPs have now closed for this workshop') |
| 131 | + end |
| 132 | + end |
| 133 | + |
| 134 | + context 'when the waitlist is open' do |
| 135 | + let(:waiting_list) { Fabricate(:waiting_list) } |
| 136 | + let(:invitation) { waiting_list.invitation } |
| 137 | + |
| 138 | + before { invitation } # materialize the fabricated waiting list entry outside the change block |
| 139 | + |
| 140 | + it 'removes the entry' do |
| 141 | + expect do |
| 142 | + delete :destroy, params: { invitation_id: invitation.token } |
| 143 | + end.to change(WaitingList, :count).by(-1) |
| 144 | + end |
| 145 | + end |
63 | 146 | end |
64 | 147 | end |
0 commit comments