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

View file

@ -0,0 +1,9 @@
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :audience do
registration_start_date { 3.days.from_now }
registration_end_date { 5.days.from_now }
registration_description 'Lorem ipsum dolorem ...'
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,46 @@
require 'spec_helper'
feature Audience 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) }
shared_examples 'audience' do |user|
scenario 'updates audience', js: true do
conference = create(:conference)
audience = create(:audience)
conference.audience = audience
sign_in create(user)
visit edit_admin_conference_audience_path(
conference_id: conference.short_title)
page.
execute_script("$('#registration-start-datepicker').val('" +
"#{Date.today.strftime('%d/%m/%Y')}')")
page.
execute_script("$('#registration-end-datepicker').val('" +
"#{(Date.today + 7).strftime('%d/%m/%Y')}')")
fill_in 'audience_registration_description', with: 'audience registration description'
click_button 'Save Audience'
expect(flash).to eq('Audience was successfully updated.')
audience.reload
expect(audience.registration_start_date).to eq(Date.today)
expect(audience.registration_end_date).to eq(Date.today + 7)
expect(audience.registration_description).to eq('audience registration description')
end
end
describe 'admin' do
it_behaves_like 'audience', :admin
end
describe 'organizer' do
it_behaves_like 'audience', :organizer
end
end

View file

@ -966,8 +966,9 @@ describe Conference do
end
it 'calculates correct for new conference' do
subject.registration_start_date = nil
subject.registration_end_date = nil
subject.audience = create(:audience,
registration_start_date: nil,
registration_end_date: nil)
subject.call_for_papers = nil
subject.venue = nil
subject.rooms = []
@ -980,8 +981,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.audience = create(:audience,
registration_start_date: Date.today,
registration_end_date: Date.today + 14)
subject.call_for_papers = nil
subject.rooms = []
subject.tracks = []
@ -996,8 +998,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.audience = create(:audience,
registration_start_date: Date.today,
registration_end_date: Date.today + 14)
subject.call_for_papers = create(:call_for_papers)
subject.rooms = []
subject.tracks = []
@ -1013,8 +1016,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.audience = create(:audience,
registration_start_date: Date.today,
registration_end_date: Date.today + 14)
subject.call_for_papers = create(:call_for_papers)
subject.venue = create(:venue)
subject.rooms = []
@ -1033,8 +1037,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.audience = create(:audience,
registration_start_date: Date.today,
registration_end_date: Date.today + 14)
subject.call_for_papers = create(:call_for_papers)
subject.venue = create(:venue)
subject.tracks = []
@ -1054,8 +1059,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.audience = create(:audience,
registration_start_date: Date.today,
registration_end_date: Date.today + 14)
subject.call_for_papers = create(:call_for_papers)
subject.venue = create(:venue)
subject.event_types = []
@ -1077,8 +1083,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.audience = create(:audience,
registration_start_date: Date.today,
registration_end_date: Date.today + 14)
subject.call_for_papers = create(:call_for_papers)
subject.venue = create(:venue)
subject.difficulty_levels = []
@ -1100,8 +1107,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.audience = create(:audience,
registration_start_date: Date.today,
registration_end_date: Date.today + 14)
subject.venue = create(:venue)
subject.call_for_papers = create(:call_for_papers)
subject.venue = create(:venue)
@ -1114,26 +1122,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.audience = create(:audience,
registration_start_date: Date.new(2013, 12, 31),
registration_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.audience = create(:audience,
registration_start_date: Date.new(2014, 05, 26),
registration_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.audience = create(:audience,
registration_start_date: Date.new(2014, 05, 26),
registration_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.audience = create(:audience,
registration_start_date: Date.new(2014, 05, 26),
registration_end_date: Date.new(2014, 05, 26) + 10)
expect(subject.registration_weeks).to eq(2)
end
end
@ -1265,15 +1277,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.audience = create(:audience,
registration_start_date: Date.new(2014, 05, 26),
registration_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.audience = create(:audience,
registration_start_date: Date.new(2014, 05, 26),
registration_end_date: Date.new(2014, 05, 26) + 28)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26) + 7)
@ -1286,8 +1300,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.audience = create(:audience,
registration_start_date: Date.new(2014, 05, 26),
registration_end_date: Date.new(2014, 05, 26) + 7)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26))
@ -1295,8 +1310,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.audience = create(:audience,
registration_start_date: Date.new(2014, 05, 26),
registration_end_date: Date.new(2014, 05, 26) + 21)
create(:registration, conference: subject, created_at: Date.new(2014, 05, 26))
create(:registration, conference: subject,
@ -1308,8 +1324,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.audience = create(:audience,
registration_start_date: Date.new(2014, 05, 26),
registration_end_date: Date.new(2014, 05, 26) + 28)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26) + 7)
@ -1322,8 +1339,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.audience = create(:audience,
registration_start_date: Date.new(2014, 05, 26),
registration_end_date: Date.new(2014, 05, 26) + 35)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26) + 21)
@ -1336,8 +1354,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.audience = create(:audience,
registration_start_date: Date.new(2014, 05, 26),
registration_end_date: Date.new(2014, 05, 26) + 35)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26))
@ -1348,8 +1367,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.audience = create(:audience,
registration_start_date: Date.new(2014, 05, 26),
registration_end_date: Date.new(2014, 05, 26) + 35)
create(:registration, conference: subject,
created_at: Date.new(2014, 05, 26))
@ -1391,8 +1411,10 @@ describe Conference do
context 'open registration' do
before do
subject.registration_start_date = Date.today - 1
subject.registration_end_date = Date.today + 7
audience = create(:audience,
registration_start_date: Date.today - 1,
registration_end_date: Date.today + 7)
subject.audience = audience
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.audience = create(:audience,
registration_description: 'Lorem Ipsum Dolor',
registration_start_date: Date.today,
registration_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.audience.registration_description}")
expect(view).to render_template(partial: 'conference/_registration')
end