2014-08-28 15:21:05 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
|
|
feature Registration do
|
2016-02-29 00:21:24 +05:30
|
|
|
let!(:first_user) { create(:user) } # first user is admin
|
2014-08-28 15:21:05 +02:00
|
|
|
let!(:conference) { create(:conference, registration_period: create(:registration_period, start_date: 3.days.ago)) }
|
|
|
|
|
let!(:participant) { create(:user) }
|
|
|
|
|
|
|
|
|
|
context 'as a participant' do
|
|
|
|
|
before(:each) do
|
|
|
|
|
sign_in participant
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
after(:each) do
|
|
|
|
|
sign_out
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'who is already registered' do
|
|
|
|
|
let!(:registration) { create(:registration, user: participant, conference: conference) }
|
|
|
|
|
|
|
|
|
|
scenario 'updates conference registration', feature: true, js: true do
|
|
|
|
|
visit root_path
|
2014-12-05 16:04:34 +01:00
|
|
|
click_link 'My Registration'
|
|
|
|
|
expect(current_path).to eq(conference_conference_registrations_path(conference.short_title))
|
2014-08-28 15:21:05 +02:00
|
|
|
|
2014-12-05 16:04:34 +01:00
|
|
|
click_link 'Edit your Registration'
|
2014-08-28 15:21:05 +02:00
|
|
|
expect(current_path).to eq(edit_conference_conference_registrations_path(conference.short_title))
|
|
|
|
|
|
2014-12-05 16:04:34 +01:00
|
|
|
click_button 'Update Registration'
|
2014-08-28 15:21:05 +02:00
|
|
|
expect(conference.user_registered?(participant)).to be(true)
|
|
|
|
|
end
|
|
|
|
|
|
2016-02-29 00:21:24 +05:30
|
|
|
context 'unregisters for a conference', feature: true, js: true do
|
|
|
|
|
before do
|
|
|
|
|
visit root_path
|
|
|
|
|
click_link 'My Registration'
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'deletion of registration is successful' do
|
|
|
|
|
expect(current_path).to eq(conference_conference_registrations_path(conference.short_title))
|
|
|
|
|
|
|
|
|
|
click_link 'Unregister'
|
|
|
|
|
expect(conference.user_registered?(participant)).to be(false)
|
|
|
|
|
expect(current_path).to eq root_path
|
2016-03-12 17:46:50 +05:30
|
|
|
expect(flash).to eq 'You are not registered for The dog and pony show anymore!'
|
2016-02-29 00:21:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
|
|
scenario 'deletion of registration is unsuccessful' do
|
|
|
|
|
allow_any_instance_of(Registration).to receive(:destroy).and_return(false)
|
2014-08-28 15:21:05 +02:00
|
|
|
|
2016-02-29 00:21:24 +05:30
|
|
|
click_link 'Unregister'
|
|
|
|
|
expect(conference.user_registered?(participant)).to be(true)
|
|
|
|
|
expect(current_path).to eq conference_conference_registrations_path(conference.short_title)
|
|
|
|
|
expect(flash).to eq "Could not delete your registration for #{conference.title}: #{registration.errors.full_messages.join('. ')}."
|
|
|
|
|
end
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'who is not registered' do
|
|
|
|
|
scenario 'registers for a conference', feature: true, js: true do
|
|
|
|
|
visit root_path
|
|
|
|
|
click_link 'Register'
|
|
|
|
|
|
|
|
|
|
expect(current_path).to eq(new_conference_conference_registrations_path(conference.short_title))
|
|
|
|
|
click_button 'Register'
|
|
|
|
|
|
|
|
|
|
expect(conference.user_registered?(participant)).to be(true)
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-02-28 12:07:13 +05:30
|
|
|
|
|
|
|
|
context 'registration is closed' do
|
|
|
|
|
let(:conference_with_closed_registration) { create(:conference, registration_period: create(:registration_period)) }
|
|
|
|
|
|
|
|
|
|
scenario 'registers for a conference', feature: true do
|
|
|
|
|
visit new_conference_conference_registrations_path(conference_with_closed_registration.short_title)
|
|
|
|
|
expect(current_path).to eq(root_path)
|
|
|
|
|
expect(flash).to eq 'You are not authorized to access this page.'
|
|
|
|
|
end
|
|
|
|
|
end
|
2014-08-28 15:21:05 +02:00
|
|
|
end
|
|
|
|
|
end
|