Add email notifications for events registrations, add switch-checkboxes, create EventsRegistrations controller, separate page for events that require registration

This commit is contained in:
Stella Rouzi 2016-06-06 12:31:57 +03:00
parent 139a8565e2
commit 77af75f319
38 changed files with 1313 additions and 403 deletions

View file

@ -0,0 +1,178 @@
require 'spec_helper'
describe Admin::EventsRegistrationsController do
let(:conference) { create(:conference) }
let(:user_organizer) { create(:user, role_ids: [Role.find_by(name: 'organizer', resource: conference).id]) }
let(:user_cfp) { create(:user, role_ids: [Role.find_by(name: 'cfp', resource: conference).id]) }
let(:user) { create(:user) }
let(:user1) { create(:user) }
let(:user2) { create(:user) }
let(:submitter1) { create(:user) }
let(:submitter2) { create(:user) }
let(:registration1) { create(:registration, user: user1, conference: conference) }
let(:registration2) { create(:registration, user: user2, conference: conference) }
let!(:event_of_submitter1) do
create(:event, program: conference.program,
require_registration: true,
max_attendees: 3,
users: [submitter1])
end
let!(:event_of_submitter2) { create(:event, program: conference.program, users: [submitter2]) }
let(:event_other) { create(:event) }
let!(:events_registration1) do
create(:events_registration,
event: event_of_submitter1,
registration: registration1,
attended: false)
end
let!(:events_registration2) do
create(:events_registration,
event: event_of_submitter2,
registration: registration2,
attended: false)
end
shared_examples 'access allowed' do
describe 'GET #show' do
before :each do
get :show, conference_id: conference.short_title, event_id: event_of_submitter1.id
end
it 'renders show template' do
expect(response).to render_template :show
end
end
describe 'PATCH #toggle' do
it 'unregisters user from event' do
event_of_submitter1.registrations = [registration1]
event_of_submitter1.save!
patch :toggle, conference_id: conference.short_title,
event_id: event_of_submitter1.id,
registration_id: registration1.id,
state: 'false', format: 'js'
event_of_submitter1.reload
expect(event_of_submitter1.registrations).to eq []
end
it 'registers user to event' do
event_of_submitter1.registrations = []
event_of_submitter1.save!
patch :toggle, conference_id: conference.short_title,
event_id: event_of_submitter1.id,
registration_id: registration1.id,
state: 'true', format: 'js'
event_of_submitter1.reload
expect(event_of_submitter1.registrations).to eq [registration1]
end
end
describe 'PATCH #toggle_attendance' do
it 'marks registered user as present' do
events_registration1.attended = false
events_registration1.save!
patch :toggle_attendance, conference_id: conference.short_title,
event_id: event_of_submitter1.id,
registration_id: registration1.id, format: 'js'
events_registration1.reload
expect(events_registration1.attended).to eq true
end
it 'marks registered user as absent' do
events_registration1.attended = true
events_registration1.save!
patch :toggle_attendance, conference_id: conference.short_title,
event_id: event_of_submitter1.id,
registration_id: registration1.id, format: 'js'
events_registration1.reload
expect(events_registration1.attended).to eq false
end
end
end
shared_examples 'access not allowed' do |path|
describe 'GET #show' do
before :each do
get :show, conference_id: conference.short_title, event_id: event_of_submitter1.id
end
it 'redirects to root path' do
expect(response).to redirect_to send(path)
end
end
describe 'PATCH #toggle' do
it 'does not register user to event' do
event_of_submitter1.registrations = []
event_of_submitter1.save!
patch :toggle, conference_id: conference.short_title,
event_id: event_of_submitter1.id,
registration_id: registration1.id,
state: 'true', format: 'js'
expect(event_of_submitter1.registrations).to eq []
end
it 'does not unregister user from event' do
patch :toggle, conference_id: conference.short_title,
event_id: event_of_submitter1.id,
registration_id: registration1.id,
state: 'false', format: 'js'
expect(event_of_submitter1.registrations).to eq [registration1]
end
end
describe 'PATCH #toggle_attendance' do
it 'does not mark registered user as present' do
events_registration1.attended = false
events_registration1.save!
patch :toggle_attendance, conference_id: conference.short_title,
event_id: event_of_submitter1.id,
registration_id: registration1.id, format: 'js'
expect(events_registration1.attended).to eq false
end
it 'does not mark registered user as absent' do
events_registration1.attended = true
events_registration1.save!
patch :toggle_attendance, conference_id: conference.short_title,
event_id: event_of_submitter1.id,
registration_id: registration1.id, format: 'js'
expect(events_registration1.attended).to eq true
end
end
end
describe 'organizer access' do
before(:each) do
sign_in user_organizer
end
it_behaves_like 'access allowed'
end
describe 'cfp access' do
before(:each) do
sign_in user_cfp
end
it_behaves_like 'access allowed'
end
describe 'submitter access' do
before(:each) do
sign_in submitter1
end
it_behaves_like 'access not allowed', :root_path
end
describe 'without user access' do
it_behaves_like 'access not allowed', :new_user_session_path
end
end

View file

@ -0,0 +1,185 @@
require 'spec_helper'
describe EventsRegistrationsController do
let!(:conference) { create(:conference) }
let(:user_organizer) { create(:user, role_ids: [Role.find_by(name: 'organizer', resource: conference).id]) }
let(:user_cfp) { create(:user, role_ids: [Role.find_by(name: 'cfp', resource: conference).id]) }
let(:user) { create(:user) }
let(:user1) { create(:user) }
let(:user2) { create(:user) }
let(:submitter1) { create(:user) }
let(:submitter2) { create(:user) }
let(:registration1) { create(:registration, user: user1, conference: conference) }
let(:registration2) { create(:registration, user: user2, conference: conference) }
let!(:event_of_submitter1) do
create(:event, program: conference.program,
require_registration: true,
max_attendees: 3,
users: [submitter1])
end
let!(:event_of_submitter2) { create(:event, program: conference.program, users: [submitter2]) }
let(:event_other) { create(:event) }
let!(:events_registration1) do
create(:events_registration,
event: event_of_submitter1,
registration: registration1,
attended: false)
end
let!(:events_registration2) do
create(:events_registration,
event: event_of_submitter2,
registration: registration2,
attended: false)
end
shared_examples 'access allowed' do
describe 'GET #show' do
before :each do
get :show, conference_id: conference.short_title, proposal_id: event_of_submitter1.id
end
it 'renders show template' do
expect(response).to render_template :show
end
end
describe 'PATCH #toggle' do
it 'unregisters user from event' do
event_of_submitter1.registrations = [registration1]
event_of_submitter1.save!
patch :toggle, conference_id: conference.short_title,
proposal_id: event_of_submitter1.id,
registration_id: registration1.id,
state: 'false', format: 'js'
event_of_submitter1.reload
expect(event_of_submitter1.registrations).to eq []
end
it 'registers user to event' do
event_of_submitter1.registrations = []
event_of_submitter1.save!
patch :toggle, conference_id: conference.short_title,
proposal_id: event_of_submitter1.id,
registration_id: registration1.id,
state: 'true', format: 'js'
event_of_submitter1.reload
expect(event_of_submitter1.registrations).to eq [registration1]
end
end
describe 'PATCH #toggle_attendance' do
it 'marks registered user as present' do
events_registration1.attended = false
events_registration1.save!
patch :toggle_attendance, conference_id: conference.short_title,
proposal_id: event_of_submitter1.id,
registration_id: registration1.id, format: 'js'
events_registration1.reload
expect(events_registration1.attended).to eq true
end
it 'marks registered user as absent' do
events_registration1.attended = true
events_registration1.save!
patch :toggle_attendance, conference_id: conference.short_title,
proposal_id: event_of_submitter1.id,
registration_id: registration1.id, format: 'js'
events_registration1.reload
expect(events_registration1.attended).to eq false
end
end
end
shared_examples 'access not allowed' do |path|
describe 'GET #show' do
before :each do
get :show, conference_id: conference.short_title, proposal_id: event_of_submitter1.id
end
it 'redirects to root path' do
expect(response).to redirect_to send(path)
end
end
describe 'PATCH #toggle' do
it 'does not register user to event' do
event_of_submitter1.registrations = []
event_of_submitter1.save!
patch :toggle, conference_id: conference.short_title,
proposal_id: event_of_submitter1.id,
registration_id: registration1.id,
state: 'true', format: 'js'
expect(event_of_submitter1.registrations).to eq []
end
it 'does not unregister user from event' do
patch :toggle, conference_id: conference.short_title,
proposal_id: event_of_submitter1.id,
registration_id: registration1.id,
state: 'false', format: 'js'
expect(event_of_submitter1.registrations).to eq [registration1]
end
end
describe 'PATCH #toggle_attendance' do
it 'does not mark registered user as present' do
events_registration1.attended = false
events_registration1.save!
patch :toggle_attendance, conference_id: conference.short_title,
proposal_id: event_of_submitter1.id,
registration_id: registration1.id, format: 'js'
expect(events_registration1.attended).to eq false
end
it 'does not mark registered user as absent' do
events_registration1.attended = true
events_registration1.save!
patch :toggle_attendance, conference_id: conference.short_title,
proposal_id: event_of_submitter1.id,
registration_id: registration1.id, format: 'js'
expect(events_registration1.attended).to eq true
end
end
end
describe 'organizer access' do
before(:each) do
sign_in user_organizer
end
it_behaves_like 'access allowed'
end
describe 'cfp access' do
before(:each) do
sign_in user_cfp
end
it_behaves_like 'access allowed'
end
describe 'submitter access' do
before(:each) do
sign_in submitter1
end
it_behaves_like 'access allowed'
end
describe 'other submitter access' do
before(:each) do
sign_in submitter2
end
it_behaves_like 'access not allowed', :root_path
end
describe 'without user access' do
it_behaves_like 'access not allowed', :root_path
end
end

View file

@ -13,15 +13,18 @@ describe ApplicationHelper, type: :helper do
describe '#registered_text' do
describe 'returns correct string' do
before :each do
event.require_registration = true
event.max_attendees = 3
end
it 'when there are no registrations' do
expect(registered_text(event)).to eq 'Registered: 0'
expect(registered_text(event)).to eq '0/3'
end
it 'when there is 1 registration' do
event.require_registration = true
event.max_attendees = 3
event.registrations << create(:registration, user: event.submitter)
expect(registered_text(event)).to eq 'Registered: 1/3'
event.registrations << create(:registration)
expect(registered_text(event)).to eq '1/3'
end
end
end

View file

@ -90,6 +90,52 @@ describe 'User' do
let(:user_event_with_cfp) { create(:event, users: [user], program: program_with_cfp) }
let(:user_commercial) { create(:commercial, commercialable: user_event_with_cfp) }
let(:event_of_user) do
create(:event, program: my_conference.program,
require_registration: true,
max_attendees: 3,
users: [user])
end
let(:event_of_user2) do
create(:event, program: my_conference.program,
require_registration: true,
max_attendees: 3,
users: [user2])
end
let(:user_registration) { create(:registration, user: user, conference: my_conference) }
let(:event_no_require_registration) { create(:event, program: my_conference.program) }
let!(:registration_to_event_no_require_registration) do
create(:events_registration,
event: event_no_require_registration,
registration: my_registration)
end
let(:registration_to_event_of_user) do
create(:events_registration,
event: event_of_user,
registration: my_registration,
attended: false)
end
let(:user_registration_to_event_of_user) do
create(:events_registration,
event: event_of_user,
registration: other_registration,
attended: false)
end
let(:registration_to_event_of_user2) do
create(:events_registration,
event: event_of_user2,
registration: my_registration,
attended: false)
end
let(:user_registration_to_event_of_user2) do
create(:events_registration,
event: event_of_user2,
registration: user_registration,
attended: false)
end
it{ should be_able_to(:manage, user) }
it{ should be_able_to(:manage, registration_public) }
@ -118,6 +164,30 @@ describe 'User' do
it{ should be_able_to(:create, user_event_with_cfp.commercials.new) }
it{ should be_able_to(:manage, user_commercial) }
it{ should_not be_able_to(:manage, commercial_event_unconfirmed) }
# Submitter can show/toggle/toggle_attendance of registration of another user to his/her event
it{ should be_able_to(:show, registration_to_event_of_user) }
it{ should be_able_to(:toggle, registration_to_event_of_user) }
it{ should be_able_to(:toggle_attendance, registration_to_event_of_user) }
it{ should be_able_to(:show, user_registration_to_event_of_user) }
it{ should be_able_to(:toggle, user_registration_to_event_of_user) }
it{ should be_able_to(:toggle_attendance, user_registration_to_event_of_user) }
# User can only toggle his/her own registration to an event
it{ should be_able_to(:toggle, user_registration_to_event_of_user2) }
it{ should_not be_able_to(:show, user_registration_to_event_of_user2) }
it{ should_not be_able_to(:toggle_attendance, user_registration_to_event_of_user2) }
# User cannot show/toggle/toggle_attendance of registration of other person to an event he/she is not a submitter of
it{ should_not be_able_to(:show, registration_to_event_of_user2) }
it{ should_not be_able_to(:toggle, registration_to_event_of_user2) }
it{ should_not be_able_to(:toggle_attendance, registration_to_event_of_user2) }
# User cannot show/toggle/toggle_attendance registration to an event that does not require_registration
it{ should_not be_able_to(:show, registration_to_event_no_require_registration) }
it{ should_not be_able_to(:toggle, registration_to_event_no_require_registration) }
it{ should_not be_able_to(:toggle_attendance, registration_to_event_no_require_registration) }
end
context 'user #is_admin?' do

View file

@ -0,0 +1,21 @@
require 'spec_helper'
describe Sponsor do
subject { create(:events_registration) }
describe 'association' do
it { is_expected.to belong_to :event }
it { is_expected.to belong_to :registration }
it { is_expected.to have_one :user }
end
describe 'validations' do
it 'has a valid factory' do
expect(build(:events_registration)).to be_valid
end
it { is_expected.to validate_presence_of(:event) }
it { is_expected.to validate_presence_of(:registration) }
it { is_expected.to validate_uniqueness_of(:event).scoped_to(:registration_id) }
end
end

View file

@ -8,7 +8,7 @@ describe 'admin/emails/index' do
assign :settings, @settings
render
expect(rendered).
to have_selector("input[type='checkbox'][value='1']", count: 9)
to have_selector("input[type='checkbox'][value='1']", count: 12)
expect(rendered).
to have_selector("input[checked='checked'][type='checkbox'][value='1']", count: 6)
expect(rendered).to include('Lorem Ipsum Dolsum')