Introduces new audience object

#416
This commit is contained in:
Chrisbr 2014-08-12 17:59:35 +02:00
parent 63d2980fe3
commit 27fc0acbf8
24 changed files with 388 additions and 116 deletions

View file

@ -0,0 +1,97 @@
require 'spec_helper'
describe Admin::AudiencesController do
# It is necessary to use bang version of let to build roles before user
let!(:organizer_role) { create(:organizer_role) }
let!(:participant_role) { create(:participant_role) }
let!(:admin_role) { create(:admin_role) }
let(:conference) { create(:conference) }
let(:admin) { create(:admin) }
let(:organizer) { create(:organizer) }
let(:participant) { create(:participant) }
shared_examples 'access as administration or organizer' do
before do
conference.audience = create(:audience)
end
describe 'PATCH #update' do
context 'valid attributes' do
it 'locates the requested audience object' do
patch :update, conference_id: conference.short_title, conference: attributes_for(:audience)
expect(assigns(:audience)).to eq(conference.audience)
end
it 'changes audience attributes' do
patch :update, conference_id: conference.short_title, audience:
attributes_for(:audience,
registration_description: 'Test')
conference.reload
expect(conference.audience.registration_description).to eq('Test')
end
it 'redirects to the updated conference' do
patch :update, conference_id: conference.short_title, audience:
attributes_for(:audience)
conference.reload
expect(response).to redirect_to edit_admin_conference_audience_path(
conference.short_title)
end
it 'sends email notification on conference registration date update' do
mailer = double
allow(mailer).to receive(:deliver)
conference.email_settings = create(:email_settings)
conference.audience = create(:audience,
registration_start_date: Date.today,
registration_end_date: Date.today + 2.days)
patch :update, conference_id: conference.short_title, audience:
attributes_for(:audience,
registration_start_date: Date.today + 2.days,
registration_end_date: Date.today + 4.days)
conference.reload
allow(Mailbot).to receive(:conference_registration_date_update_mail).and_return(mailer)
end
end
end
describe 'GET #edit' do
it 'assigns the requested conference to conference' do
get :edit, conference_id: conference.short_title
expect(assigns(:audience)).to eq conference.audience
end
it 'renders the show template' do
get :edit, conference_id: conference.short_title
expect(response).to render_template :edit
end
end
end
describe 'administrator access' do
before do
sign_in(admin)
end
it_behaves_like 'access as administration or organizer'
end
describe 'organizer access' do
before(:each) do
sign_in(organizer)
end
it_behaves_like 'access as administration or organizer'
end
end

View file

@ -50,16 +50,6 @@ describe Admin::ConferenceController do
conference.reload
allow(Mailbot).to receive(:conference_date_update_mail).and_return(mailer)
end
it 'sends email notification on conference registration date update' do
mailer = double
allow(mailer).to receive(:deliver)
conference.email_settings = create(:email_settings)
patch :update, id: conference.short_title, conference:
attributes_for(:conference, registration_start_date: Date.today + 2.days, registration_end_date: Date.today + 4.days)
conference.reload
allow(Mailbot).to receive(:conference_registration_date_update_mail).and_return(mailer)
end
end
context 'invalid attributes' do
@ -143,13 +133,13 @@ describe Admin::ConferenceController do
describe 'GET #edit' do
it 'assigns the requested conference to conference' do
get :show, id: conference.short_title
get :edit, id: conference.short_title
expect(assigns(:conference)).to eq conference
end
it 'renders the show template' do
get :show, id: conference.short_title
expect(response).to render_template :show
get :edit, id: conference.short_title
expect(response).to render_template :edit
end
end