Introduces new RegistrationPeriod Object for Conference

#416
This commit is contained in:
Chrisbr 2014-08-18 14:33:02 +02:00
parent a620950383
commit ed55e2bf3a
25 changed files with 529 additions and 131 deletions

View file

@ -48,16 +48,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
@ -141,13 +131,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

View file

@ -0,0 +1,165 @@
require 'spec_helper'
describe Admin::RegistrationPeriodsController do
# It is necessary to use bang version of let to build roles before user
let(:conference) { create(:conference) }
let!(:first_user) { create(:user) }
let!(:organizer_role) { create(:role, name: 'organizer', resource: conference) }
let(:organizer) { create(:user, role_ids: organizer_role.id) }
let(:organizer2) { create(:user, email: 'organizer2@email.osem', role_ids: organizer_role.id) }
let(:participant) { create(:user) }
shared_examples 'access as administration or organizer' do
before do
conference.registration_period = create(:registration_period)
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(:registration_period)
expect(assigns(:registration_period)).to eq(conference.registration_period)
end
it 'changes audience attributes' do
patch :update, conference_id: conference.short_title, registration_period:
attributes_for(:registration_period,
description: 'Test')
conference.reload
expect(conference.registration_period.description).to eq('Test')
end
it 'redirects to the updated conference' do
patch :update, conference_id: conference.short_title, registration_period:
attributes_for(:registration_period)
conference.reload
expect(response).to redirect_to admin_conference_registration_period_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.registration_period = create(:registration_period,
start_date: Date.today,
end_date: Date.today + 2.days)
patch :update, conference_id: conference.short_title, registration_period:
attributes_for(:registration_period,
start_date: Date.today + 2.days,
end_date: Date.today + 4.days)
conference.reload
allow(Mailbot).to receive(:conference_registration_date_update_mail).and_return(mailer)
end
end
end
describe 'POST #create' do
context 'with valid attributes' do
it 'saves the registration period to the database' do
expected = expect do
post :create,
conference_id: conference.short_title,
registration_period: attributes_for(:registration_period)
end
expected.to change { RegistrationPeriod.count }.by 1
end
it 'redirects to registration_periods#show' do
post :create,
conference_id: conference.short_title,
registration_period: attributes_for(:registration_period)
expect(response).to redirect_to admin_conference_registration_period_path(
assigns[:conference].short_title)
end
end
context 'with invalid attributes' do
it 'does not save the conference to the database' do
expected = expect do
post :create,
conference_id: conference.short_title,
registration_period: attributes_for(:registration_period,
start_date: nil,
end_date: nil)
end
expected.to_not change { Conference.count }
end
it 're-renders the new template' do
post :create,
conference_id: conference.short_title,
registration_period: attributes_for(:registration_period,
start_date: nil,
end_date: nil)
expect(response).to be_success
end
end
end
describe 'GET #edit' do
it 'assigns the requested conference to conference' do
get :edit, conference_id: conference.short_title
expect(assigns(:registration_period)).to eq conference.registration_period
end
it 'renders the show template' do
get :edit, conference_id: conference.short_title
expect(response).to render_template :edit
end
end
describe 'GET #show' do
it 'assigns the requested registration period to registration period' do
get :show, conference_id: conference.short_title
expect(assigns(:registration_period)).to eq conference.registration_period
end
it 'renders the show template' do
get :show, conference_id: conference.short_title
expect(response).to render_template :show
end
end
describe 'GET #new' do
it 'assigns a new conference to conference' do
get :new, conference_id: conference.short_title
expect(assigns(:registration_period)).to be_a_new(RegistrationPeriod)
end
it 'renders the :new template' do
get :new, conference_id: conference.short_title
expect(response).to render_template :new
end
end
describe 'DELETE #destroy' do
it 'it deletes the registration period' do
expect { delete :destroy, conference_id: conference.short_title }.to change(RegistrationPeriod, :count).by(-1)
end
it 'redirects to users#show' do
delete :destroy, conference_id: conference.short_title
expect(response).to redirect_to admin_conference_registration_period_path
end
end
end
describe 'organizer access' do
before(:each) do
sign_in(organizer)
end
it_behaves_like 'access as administration or organizer'
end
end

View file

@ -7,8 +7,6 @@ FactoryGirl.define do
timezone 'Amsterdam'
start_date { Date.today }
end_date { 6.days.from_now }
registration_start_date { 3.days.from_now }
registration_end_date { 5.days.from_now }
make_conference_public true
venue
end

View file

@ -0,0 +1,9 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :registration_period do
start_date { 3.days.from_now }
end_date { 5.days.from_now }
description 'Lorem ipsum dolorem ...'
end
end

View file

@ -0,0 +1,47 @@
require 'spec_helper'
feature RegistrationPeriod do
# It is necessary to use bang version of let to build roles before user
let!(:conference) { create(:conference) }
let!(:organizer_role) { create(:organizer_role, resource: conference) }
let!(:organizer) { create(:user, email: 'admin@example.com', role_ids: [organizer_role.id]) }
shared_examples 'successfully' do
scenario 'create and update registration period', js: true do
sign_in organizer
visit admin_conference_registration_period_path(
conference_id: conference.short_title)
click_link 'New Registration Period'
fill_in 'registration_period_description', with: 'The description'
click_button 'Save Registration Period'
expect(flash).
to eq("A error prohibited the Registration Period from being saved: " \
"Start date can't be blank. End date can't be blank.")
page.
execute_script("$('#registration-period-start-datepicker').val('" +
"#{Date.today.strftime('%d/%m/%Y')}')")
page.
execute_script("$('#registration-period-end-datepicker').val('" +
"#{(Date.today + 7).strftime('%d/%m/%Y')}')")
click_button 'Save Registration Period'
expect(flash).to eq('Registration Period successfully updated.')
expect(current_path).to eq(admin_conference_registration_period_path(conference.short_title))
registration_period = RegistrationPeriod.where(conference_id: conference.id).first
registration_period.reload
expect(registration_period.start_date).to eq(Date.today)
expect(registration_period.end_date).to eq(Date.today + 7)
expect(registration_period.description).to eq('The description')
end
end
describe 'organizer' do
it_behaves_like 'successfully'
end
end

View file

@ -964,8 +964,6 @@ describe Conference do
end
it 'calculates correct for new conference' do
subject.registration_start_date = nil
subject.registration_end_date = nil
subject.call_for_papers = nil
subject.venue = nil
subject.rooms = []
@ -978,8 +976,9 @@ describe Conference do
end
it 'calculates correct for conference with registration' do
subject.registration_start_date = Date.today
subject.registration_end_date = Date.today + 14
subject.registration_period = create(:registration_period,
start_date: Date.today,
end_date: Date.today + 14)
subject.call_for_papers = nil
subject.rooms = []
subject.tracks = []
@ -994,8 +993,9 @@ describe Conference do
end
it 'calculates correct for conference with registration, cfp' do
subject.registration_start_date = Date.today
subject.registration_end_date = Date.today + 14
subject.registration_period = create(:registration_period,
start_date: Date.today,
end_date: Date.today + 14)
subject.call_for_papers = create(:call_for_papers)
subject.rooms = []
subject.tracks = []
@ -1011,8 +1011,9 @@ describe Conference do
end
it 'calculates correct for conference with registration, cfp, venue' do
subject.registration_start_date = Date.today
subject.registration_end_date = Date.today + 14
subject.registration_period = create(:registration_period,
start_date: Date.today,
end_date: Date.today + 14)
subject.call_for_papers = create(:call_for_papers)
subject.venue = create(:venue)
subject.rooms = []
@ -1031,8 +1032,9 @@ describe Conference do
it 'calculates correct for conference with registration, cfp, venue, rooms' do
subject.rooms = [create(:room)]
subject.registration_start_date = Date.today
subject.registration_end_date = Date.today + 14
subject.registration_period = create(:registration_period,
start_date: Date.today,
end_date: Date.today + 14)
subject.call_for_papers = create(:call_for_papers)
subject.venue = create(:venue)
subject.tracks = []
@ -1052,8 +1054,9 @@ describe Conference do
it 'calculates correct for conference with registration, cfp, venue, rooms, tracks' do
subject.rooms = [create(:room)]
subject.tracks = [create(:track)]
subject.registration_start_date = Date.today
subject.registration_end_date = Date.today + 14
subject.registration_period = create(:registration_period,
start_date: Date.today,
end_date: Date.today + 14)
subject.call_for_papers = create(:call_for_papers)
subject.venue = create(:venue)
subject.event_types = []
@ -1075,8 +1078,9 @@ describe Conference do
subject.rooms = [create(:room)]
subject.tracks = [create(:track)]
subject.event_types = [create(:event_type)]
subject.registration_start_date = Date.today
subject.registration_end_date = Date.today + 14
subject.registration_period = create(:registration_period,
start_date: Date.today,
end_date: Date.today + 14)
subject.call_for_papers = create(:call_for_papers)
subject.venue = create(:venue)
subject.difficulty_levels = []
@ -1098,8 +1102,9 @@ describe Conference do
subject.tracks = [create(:track)]
subject.event_types = [create(:event_type)]
subject.difficulty_levels = [create(:difficulty_level)]
subject.registration_start_date = Date.today
subject.registration_end_date = Date.today + 14
subject.registration_period = create(:registration_period,
start_date: Date.today,
end_date: Date.today + 14)
subject.venue = create(:venue)
subject.call_for_papers = create(:call_for_papers)
subject.venue = create(:venue)
@ -1112,26 +1117,30 @@ describe Conference do
describe '#registration_weeks' do
it 'calculates new year' do
subject.registration_start_date = Date.new(2013, 12, 31)
subject.registration_end_date = Date.new(2013, 12, 30) + 6
subject.registration_period = create(:registration_period,
start_date: Date.new(2013, 12, 31),
end_date: Date.new(2013, 12, 30) + 6)
expect(subject.registration_weeks).to eq(1)
end
it 'is one if start and end are 6 days apart' do
subject.registration_start_date = Date.new(2014, 05, 26)
subject.registration_end_date = Date.new(2014, 05, 26) + 6
subject.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 26),
end_date: Date.new(2014, 05, 26) + 6)
expect(subject.registration_weeks).to eq(1)
end
it 'is one if start and end date are the same' do
subject.registration_start_date = Date.new(2014, 05, 26)
subject.registration_end_date = Date.new(2014, 05, 26)
subject.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 26),
end_date: Date.new(2014, 05, 26))
expect(subject.registration_weeks).to eq(1)
end
it 'is two if start and end are 10 days apart' do
subject.registration_start_date = Date.new(2014, 05, 26)
subject.registration_end_date = Date.new(2014, 05, 26) + 10
subject.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 26),
end_date: Date.new(2014, 05, 26) + 10)
expect(subject.registration_weeks).to eq(2)
end
end
@ -1263,15 +1272,17 @@ describe Conference do
describe '#get_registrations_per_week' do
it 'pads with zeros if there are no registrations' do
subject.registration_start_date = Date.new(2014, 05, 26)
subject.registration_end_date = Date.new(2014, 05, 26) + 21
subject.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 26),
end_date: Date.new(2014, 05, 26) + 21)
expect(subject.get_registrations_per_week).to eq([0, 0, 0, 0])
end
it 'summarized correct if there are no registrations in one week' do
subject.registration_start_date = Date.new(2014, 05, 26)
subject.registration_end_date = Date.new(2014, 05, 26) + 28
subject.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 26),
end_date: Date.new(2014, 05, 26) + 28)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26) + 7)
@ -1284,8 +1295,9 @@ describe Conference do
end
it 'returns [1] if there is one registration on the first day' do
subject.registration_start_date = Date.new(2014, 05, 26)
subject.registration_end_date = Date.new(2014, 05, 26) + 7
subject.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 26),
end_date: Date.new(2014, 05, 26) + 7)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26))
@ -1293,8 +1305,9 @@ describe Conference do
end
it 'summarized correct if there are registrations every week' do
subject.registration_start_date = Date.new(2014, 05, 26)
subject.registration_end_date = Date.new(2014, 05, 26) + 21
subject.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 26),
end_date: Date.new(2014, 05, 26) + 21)
create(:registration, conference: subject, created_at: Date.new(2014, 05, 26))
create(:registration, conference: subject,
@ -1306,8 +1319,9 @@ describe Conference do
end
it 'summarized correct if there are registrations every week except the first' do
subject.registration_start_date = Date.new(2014, 05, 26)
subject.registration_end_date = Date.new(2014, 05, 26) + 28
subject.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 26),
end_date: Date.new(2014, 05, 26) + 28)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26) + 7)
@ -1320,8 +1334,9 @@ describe Conference do
end
it 'pads left' do
subject.registration_start_date = Date.new(2014, 05, 26)
subject.registration_end_date = Date.new(2014, 05, 26) + 35
subject.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 26),
end_date: Date.new(2014, 05, 26) + 35)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26) + 21)
@ -1334,8 +1349,9 @@ describe Conference do
end
it 'pads middle' do
subject.registration_start_date = Date.new(2014, 05, 26)
subject.registration_end_date = Date.new(2014, 05, 26) + 35
subject.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 26),
end_date: Date.new(2014, 05, 26) + 35)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26))
@ -1346,8 +1362,9 @@ describe Conference do
end
it 'pads right' do
subject.registration_start_date = Date.new(2014, 05, 26)
subject.registration_end_date = Date.new(2014, 05, 26) + 35
subject.registration_period = create(:registration_period,
start_date: Date.new(2014, 05, 26),
end_date: Date.new(2014, 05, 26) + 35)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26))
@ -1389,8 +1406,10 @@ describe Conference do
context 'open registration' do
before do
subject.registration_start_date = Date.today - 1
subject.registration_end_date = Date.today + 7
enrollment = create(:registration_period,
start_date: Date.today - 1,
end_date: Date.today + 7)
subject.registration_period = enrollment
end
it '#registration_open? is true' do

View file

@ -2,24 +2,26 @@ require 'spec_helper'
describe 'conference/show.html.haml' do
before(:each) do
allow(view).to receive(:date_string).and_return("January 17 - 21 2014")
@conference = create(:conference, registration_description: 'Lorem Ipsum Dolor',
registration_start_date: Date.today,
registration_end_date: Date.tomorrow,
description: 'Lorem Ipsum',
sponsor_description: 'Lorem Ipsum Dolor',
sponsor_email: 'example@example.com',
include_registrations_in_splash: true,
include_program_in_splash: true,
include_sponsors_in_splash: true,
include_tracks_in_splash: true,
include_tickets_in_splash: true,
include_banner_in_splash: true)
@conference = create(:conference,
description: 'Lorem Ipsum',
sponsor_description: 'Lorem Ipsum Dolor',
sponsor_email: 'example@example.com',
include_registrations_in_splash: true,
include_program_in_splash: true,
include_sponsors_in_splash: true,
include_tracks_in_splash: true,
include_tickets_in_splash: true,
include_banner_in_splash: true)
@conference.contact.update(facebook: 'http://www.fbexample.com',
googleplus: 'http://www.google-example.com',
instagram: 'http://instagram.com',
twitter: 'http://twitter.com',
public: true
)
@conference.registration_period = create(:registration_period,
description: 'Lorem Ipsum Dolor',
start_date: Date.today,
end_date: Date.tomorrow)
@conference.call_for_papers = create(:call_for_papers, conference: @conference,
include_cfp_in_splash: true)
@conference.call_for_papers = create(:call_for_papers, conference: @conference,
@ -45,7 +47,7 @@ describe 'conference/show.html.haml' do
end
it 'renders registration partial' do
expect(view.content_for(:splash)).to include("#{@conference.registration_description}")
expect(view.content_for(:splash)).to include("#{@conference.registration_period.description}")
expect(view).to render_template(partial: 'conference/_registration')
end