Ability of user to create registration is fixed Closes #1628

Speaker's ability to create registration and corresponding tests are improved
This commit is contained in:
namangupta01 2017-08-08 05:19:02 +05:30 committed by Stella Rouzi
parent 63515cef58
commit 7326bd132f
2 changed files with 130 additions and 4 deletions

View file

@ -89,11 +89,131 @@ describe 'User' do
let(:other_self_organized_track) { create(:track, :self_organized) }
it{ should be_able_to(:manage, user) }
it{ should be_able_to(:manage, registration_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))}
# Test for user can register or not
context 'when user is not a speaker with event confirmed' do
let(:conference) { create(:conference) }
context 'when the registration is closed' do
before :each do
create(:registration_period, conference: conference, start_date: Date.current - 6.days, end_date: Date.current - 6.days)
end
it{ should_not be_able_to(:new, Registration.new(conference: conference)) }
it{ should_not be_able_to(:create, Registration.new(conference: conference)) }
end
context 'when the registration period is not set' do
it{ should_not be_able_to(:new, Registration.new(conference: conference)) }
it{ should_not be_able_to(:create, Registration.new(conference: conference)) }
end
context 'when user has already registered' do
before :each do
create(:registration, conference: conference, user: user)
end
it{ should_not be_able_to(:new, Registration.new(conference: conference)) }
it{ should_not be_able_to(:create, Registration.new(conference: conference)) }
end
context 'when registrations are open' do
before :each do
create(:registration_period, conference: conference)
end
it{ should be_able_to(:new, Registration.new(conference: conference)) }
it{ should be_able_to(:create, Registration.new(conference: conference)) }
context 'when user has not registered with no registration_limit_exceeded' do
before :each do
conference.registration_limit = 1
end
it{ should be_able_to(:new, Registration.new(conference: conference)) }
it{ should be_able_to(:create, Registration.new(conference: conference)) }
end
context 'when user has not registered with registration_limit_exceeded' do
before :each do
conference.registration_limit = 1
create(:registration, conference: conference, user: user2)
end
it{ should_not be_able_to(:new, Registration.new(conference: conference)) }
it{ should_not be_able_to(:create, Registration.new(conference: conference)) }
end
end
end
context 'when user is a speaker with event confirmed' do
let(:conference_with_speaker_confirmed) { create(:conference) }
let(:event_with_speaker_confirmed) { create(:event, state: 'confirmed', program: conference_with_speaker_confirmed.program) }
before :each do
event_with_speaker_confirmed.speakers << user
end
context 'when registration period is not set' do
it{ should_not be_able_to(:new, Registration.new(conference: conference_with_speaker_confirmed)) }
it{ should_not be_able_to(:create, Registration.new(conference: conference_with_speaker_confirmed)) }
end
context 'when speaker has already registered' do
before :each do
create(:registration, conference: conference_with_speaker_confirmed, user: user)
end
it{ should_not be_able_to(:new, Registration.new(conference: conference_with_speaker_confirmed)) }
it{ should_not be_able_to(:create, Registration.new(conference: conference_with_speaker_confirmed)) }
end
context 'when registration period is set' do
before :each do
create(:registration_period, conference: conference_with_speaker_confirmed)
end
context 'when registrations are open' do
context 'when speaker has not registered' do
it{ should be_able_to(:new, Registration.new(conference: conference_with_speaker_confirmed)) }
it{ should be_able_to(:create, Registration.new(conference: conference_with_speaker_confirmed)) }
end
context 'when registration_limit_exceeded' do
before :each do
conference_with_speaker_confirmed.registration_limit = 1
create(:registration, conference: conference_with_speaker_confirmed, user: user2)
end
it{ should be_able_to(:new, Registration.new(conference: conference_with_speaker_confirmed)) }
it{ should be_able_to(:create, Registration.new(conference: conference_with_speaker_confirmed)) }
end
end
context 'when registrations are closed' do
before :each do
create(:registration_period, conference: conference_with_speaker_confirmed, start_date: Date.current - 6.days, end_date: Date.current - 6.days)
end
context 'when speaker has not registered' do
it{ should be_able_to(:new, Registration.new(conference: conference_with_speaker_confirmed)) }
it{ should be_able_to(:create, Registration.new(conference: conference_with_speaker_confirmed)) }
end
context 'with registration_limit_exceeded' do
before :each do
conference_with_speaker_confirmed.registration_limit = 1
create(:registration, conference: conference_with_speaker_confirmed, user: user2)
end
it{ should be_able_to(:new, Registration.new(conference: conference_with_speaker_confirmed)) }
it{ should be_able_to(:create, Registration.new(conference: conference_with_speaker_confirmed)) }
end
end
end
end
it{ should be_able_to(:index, Ticket) }
it{ should be_able_to(:manage, TicketPurchase.new(user_id: user.id)) }