Do not allow signed in users to registor unless registration is open

This commit is contained in:
Aditya Prakash 2016-03-14 23:38:55 +05:30
parent 7e4d91adaf
commit 7822a8d4e3
2 changed files with 11 additions and 5 deletions

View file

@ -72,6 +72,10 @@ class Ability
can :manage, Registration, user_id: user.id can :manage, Registration, user_id: user.id
can [:new, :create], Registration do |registration|
registration.conference.registration_open?
end
can :index, Ticket can :index, Ticket
can :manage, TicketPurchase, user_id: user.id can :manage, TicketPurchase, user_id: user.id

View file

@ -33,13 +33,13 @@ describe 'User' do
let(:registration) { create(:registration) } let(:registration) { create(:registration) }
# Test abilities for not signed in users
context 'when user is not signed in' do
let(:conference_with_open_registration) { create(:conference) } let(:conference_with_open_registration) { create(:conference) }
let!(:open_registration_period) { create(:registration_period, conference: conference_with_open_registration, start_date: Date.current - 6.days) } let!(:open_registration_period) { create(:registration_period, conference: conference_with_open_registration, start_date: Date.current - 6.days) }
let(:conference_with_closed_registration) { create(:conference) } let(:conference_with_closed_registration) { create(:conference) }
let!(:closed_registration_period) { create(:registration_period, conference: conference_with_closed_registration, start_date: Date.current - 6.days, end_date: Date.current - 6.days) } let!(:closed_registration_period) { create(:registration_period, conference: conference_with_closed_registration, start_date: Date.current - 6.days, end_date: Date.current - 6.days) }
# Test abilities for not signed in users
context 'when user is not signed in' do
it{ should be_able_to(:index, Conference)} it{ should be_able_to(:index, Conference)}
it{ should be_able_to(:show, conference_public)} it{ should be_able_to(:show, conference_public)}
@ -88,6 +88,8 @@ describe 'User' do
it{ should be_able_to(:manage, registration_public) } it{ should be_able_to(:manage, registration_public) }
it{ should be_able_to(:manage, registration_not_public) } it{ should be_able_to(:manage, registration_not_public) }
it{ should_not be_able_to(:new, Registration.new(conference_id: conference_with_closed_registration.id))}
it{ should_not be_able_to(:create, Registration.new(conference_id: conference_with_closed_registration.id))}
it{ should be_able_to(:index, Ticket) } it{ should be_able_to(:index, Ticket) }
it{ should be_able_to(:manage, TicketPurchase.new(user_id: user.id)) } it{ should be_able_to(:manage, TicketPurchase.new(user_id: user.id)) }