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
8 changes: 7 additions & 1 deletion app/controllers/waiting_lists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@ def create # rubocop:disable Metrics/MethodLength
end

def destroy
WaitingList.find_by(invitation_id: @invitation.id).destroy
entry = WaitingList.find_by(invitation_id: @invitation.id)
unless entry
return redirect_to(invitation_path(@invitation),
notice: 'You are not on the waiting list')
end

entry.destroy
MemberActivityRecorder.record(actor: @invitation.member, key: 'waiting_list.left',
trackable: @invitation)

Expand Down
15 changes: 15 additions & 0 deletions spec/controllers/waiting_lists_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@
end

describe 'DELETE #destroy' do
context 'when the waiting-list entry is already gone' do
it 'redirects with a notice instead of raising' do
delete :destroy, params: { invitation_id: invitation.token }

expect(response).to redirect_to(invitation_path(invitation))
expect(flash[:notice]).to eq('You are not on the waiting list')
end

it 'does not record a "waiting_list.left" activity' do
delete :destroy, params: { invitation_id: invitation.token }

expect(PublicActivity::Activity.where(key: 'waiting_list.left')).to be_empty
end
end

context 'without a CSRF token (browser did not send session cookie)' do
include_context 'with forgery protection enforced'

Expand Down
Loading