Tests for ConferenceRegistrations controller
Authorization needs to be done first or else it will give CanCan::AuthorizationNotPerformed error for some of branches. Removed if condition is dead code. Small fix in flash message of destroy and its feature test.
This commit is contained in:
parent
13a6586f81
commit
5bff60ec7d
4 changed files with 314 additions and 18 deletions
|
|
@ -5,6 +5,9 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
before_action :set_registration, only: [:edit, :update, :destroy, :show]
|
||||
|
||||
def new
|
||||
@registration = Registration.new(conference_id: @conference.id)
|
||||
authorize! :new, @registration
|
||||
|
||||
# Redirect to registration edit when user is already registered
|
||||
if @conference.user_registered?(current_user)
|
||||
redirect_to edit_conference_conference_registrations_path(@conference.short_title)
|
||||
|
|
@ -15,19 +18,11 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
# avoid openid sign_in to redirect to register/new when the sign_in user had already a registration
|
||||
if current_user && @conference.user_registered?(current_user)
|
||||
redirect_to edit_conference_conference_registrations_path(@conference.short_title)
|
||||
end
|
||||
|
||||
if @conference.registration_limit_exceeded?
|
||||
redirect_to root_path, alert: "Sorry, registration limit exceeded for #{@conference.title}"
|
||||
return
|
||||
end
|
||||
|
||||
@registration = Registration.new(conference_id: @conference.id)
|
||||
# make sure that conference is open for registration
|
||||
authorize! :new, @registration
|
||||
# @user variable needs to be set so that _sign_up_form_embedded works properly
|
||||
@user = @registration.build_user
|
||||
end
|
||||
|
|
@ -91,9 +86,9 @@ class ConferenceRegistrationsController < ApplicationController
|
|||
redirect_to root_path,
|
||||
notice: "You are not registered for #{@conference.title} anymore!"
|
||||
else
|
||||
redirect_to root_path,
|
||||
error: "Could not update your registration for #{@conference.title}: "\
|
||||
"#{@registration.errors.full_messages.join('. ')}."
|
||||
redirect_to conference_conference_registrations_path(@conference.short_title),
|
||||
flash: { error: "Could not delete your registration for #{@conference.title}: "\
|
||||
"#{@registration.errors.full_messages.join('. ')}." }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue