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
5 changes: 3 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ def latest_model_updated

def find_invitation_and_redirect_to_event(role)
set_event
@invitation = Invitation.create_or_find_by(event: @event, member: current_user, role: role)
redirect_to event_invitation_path(@event, @invitation)
invitation = Invitation.create_or_find_by(event: @event, member: current_user, role: role)
invitation = Invitation.find_by(event: @event, member: current_user, role: role) unless invitation.persisted?
redirect_to event_invitation_path(@event, invitation)
end

def set_event
Expand Down
72 changes: 72 additions & 0 deletions spec/controllers/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,78 @@
end
end

describe 'GET #student' do
let(:member) { Fabricate(:member) }
let(:event) { Fabricate(:event) }

before { login(member) }

context 'when the member already has an invitation for the event and role with attending nil' do
let!(:invitation) do
Fabricate(:invitation, event: event, member: member, role: 'Student', attending: nil)
end

it 'redirects to the existing invitation page' do
get :student, params: { event_id: event.slug }

expect(response).to redirect_to(event_invitation_path(event, invitation))
end

it 'does not create a new invitation' do
expect do
get :student, params: { event_id: event.slug }
end.not_to change(Invitation, :count)
end
end

context 'when the member does not have an invitation for the event and role' do
it 'creates a new invitation and redirects' do
expect do
get :student, params: { event_id: event.slug }
end.to change(Invitation, :count).by(1)

invitation = Invitation.last
expect(response).to redirect_to(event_invitation_path(event, invitation))
end
end
end

describe 'GET #coach' do
let(:member) { Fabricate(:member) }
let(:event) { Fabricate(:event) }

before { login(member) }

context 'when the member already has a coach invitation for the event with attending nil' do
let!(:invitation) do
Fabricate(:coach_invitation, event: event, member: member, attending: nil)
end

it 'redirects to the existing invitation page' do
get :coach, params: { event_id: event.slug }

expect(response).to redirect_to(event_invitation_path(event, invitation))
end

it 'does not create a new invitation' do
expect do
get :coach, params: { event_id: event.slug }
end.not_to change(Invitation, :count)
end
end

context 'when the member does not have a coach invitation for the event' do
it 'creates a new coach invitation and redirects' do
expect do
get :coach, params: { event_id: event.slug }
end.to change(Invitation, :count).by(1)

invitation = Invitation.last
expect(response).to redirect_to(event_invitation_path(event, invitation))
end
end
end

describe '#past' do
before { Fabricate(:event, date_and_time: 2.weeks.ago) }

Expand Down