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
2 changes: 2 additions & 0 deletions app/controllers/workshop_invitation_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def reject
MemberActivityRecorder.record(actor: @invitation.member, key: 'workshop_invitation.rejected',
trackable: @invitation)

WaitingList.find_by(invitation_id: @invitation.id)&.destroy

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: if there is an association invitation on WaitingList, it can be used in the find_by args, like invitation: @invitation. ActiveRecord will iron that out into SQL.


next_spot = WaitingList.next_spot(@invitation.workshop, @invitation.role)

if next_spot.present?
Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/workshop_invitation_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,37 @@ def html_body(mail)
.not_to change(WaitingList, :count)
end
end

context 'when the rejecting member is on the waiting list' do
before do
invitation.update!(attending: true)
WaitingList.add(invitation, auto_rsvp: true)
end

it 'removes their own waiting-list entry' do
post :reject, params: { id: invitation.token }

expect(WaitingList.where(invitation:)).to be_empty
end

it 'does not redeliver the seat to the cancelling member' do
post :reject, params: { id: invitation.token }

expect(invitation.reload.attending).to be false
end

it 'promotes the next student on the waiting list instead' do
member_behind = Fabricate(:member)
invitation_behind = Fabricate(:workshop_invitation, workshop:, member: member_behind, role: 'Student')
WaitingList.add(invitation_behind, auto_rsvp: true)

post :reject, params: { id: invitation.token }

expect(invitation_behind.reload.attending).to be true
expect(invitation.reload.attending).to be false
expect(WaitingList.where(invitation:)).to be_empty
end
end
end

describe 'PATCH #update' do
Expand Down
Loading