Skip to content
Merged
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
28 changes: 28 additions & 0 deletions spec/controllers/workshop_invitation_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

before { login(member) }

# The invitation mailer sends multipart/mixed > multipart/alternative > text/html;
# the root body is empty, so read the nested html part.
def html_body(mail)
parts = mail.parts.flat_map { |part| part.multipart? ? part.parts : [part] }
parts.find { |part| part.content_type.match?('text/html') }&.body&.decoded
end

describe 'GET #show' do
it 'returns http success' do
get :show, params: { id: invitation.token }
Expand Down Expand Up @@ -181,6 +188,27 @@
post :reject, params: { id: invitation.token }
expect(waitlisted_invitation.reload.attending).to be true
end

it 'emails the promoted member a confirmation they are attending' do
post :reject, params: { id: invitation.token }

mail = ActionMailer::Base.deliveries.find { |m| m.to.include?(waitlisted_member.email) }
expect(mail).not_to be_nil
expect(html_body(mail)).to include('been confirmed')
end

it 'sends the promotion variant of the email (waiting-list flag set)' do
post :reject, params: { id: invitation.token }

mail = ActionMailer::Base.deliveries.find { |m| m.to.include?(waitlisted_member.email) }
expect(html_body(mail)).to include('A spot became available and your attendance has now been confirmed!')
end

it 'does not email anyone else (the rejecting member gets no promotion copy)' do
expect do
post :reject, params: { id: invitation.token }
end.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end

context 'when a coach is waitlisted and a student seat frees up' do
Expand Down
Loading