Add validations for registration_period
This commit is contained in:
parent
68cc4a73d9
commit
f567187d45
6 changed files with 122 additions and 32 deletions
|
|
@ -4,7 +4,7 @@ require 'spec_helper'
|
|||
|
||||
describe Conference do
|
||||
|
||||
let(:subject) { create(:conference, end_date: '2014-06-30') }
|
||||
let(:subject) { create(:conference, start_date: Date.new(2014, 06, 30), end_date: Date.new(2014, 06, 30)) }
|
||||
|
||||
describe '#write_event_distribution_to_db' do
|
||||
|
||||
|
|
@ -982,8 +982,8 @@ describe Conference do
|
|||
|
||||
it 'calculates correct for conference with registration' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.today,
|
||||
end_date: Date.today + 14)
|
||||
start_date: subject.end_date - 14,
|
||||
end_date: subject.end_date, conference: subject)
|
||||
subject.program.cfp = nil
|
||||
subject.venue = nil
|
||||
subject.program.event_types = []
|
||||
|
|
@ -1000,8 +1000,8 @@ describe Conference do
|
|||
|
||||
it 'calculates correct for conference with registration, cfp' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.today,
|
||||
end_date: Date.today + 14)
|
||||
start_date: subject.end_date - 14,
|
||||
end_date: subject.end_date, conference: subject)
|
||||
subject.program.cfp = create(:cfp)
|
||||
subject.venue = nil
|
||||
subject.program.tracks = []
|
||||
|
|
@ -1017,9 +1017,10 @@ describe Conference do
|
|||
end
|
||||
|
||||
it 'calculates correct for conference with registration, cfp, venue' do
|
||||
expect(subject.end_date).to eq Date.new(2014, 06, 30)
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.today,
|
||||
end_date: Date.today + 14)
|
||||
start_date: subject.end_date - 14,
|
||||
end_date: subject.end_date, conference: subject)
|
||||
subject.program.cfp = create(:cfp)
|
||||
subject.venue = create(:venue, conference: subject)
|
||||
subject.venue.rooms = []
|
||||
|
|
@ -1039,7 +1040,7 @@ describe Conference do
|
|||
it 'calculates correct for conference with registration, cfp, venue, rooms' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.today,
|
||||
end_date: Date.today + 14)
|
||||
end_date: Date.today + 14, conference: subject)
|
||||
subject.program.cfp = create(:cfp)
|
||||
subject.venue = create(:venue, conference: subject)
|
||||
subject.venue.rooms = [create(:room, venue: subject.venue)]
|
||||
|
|
@ -1063,7 +1064,7 @@ describe Conference do
|
|||
subject.program.tracks = [create(:track)]
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.today,
|
||||
end_date: Date.today + 14)
|
||||
end_date: Date.today + 14, conference: subject)
|
||||
subject.program.cfp = create(:cfp)
|
||||
subject.program.event_types = []
|
||||
subject.program.difficulty_levels = []
|
||||
|
|
@ -1085,7 +1086,7 @@ describe Conference do
|
|||
subject.program.event_types = [create(:event_type)]
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.today,
|
||||
end_date: Date.today + 14)
|
||||
end_date: Date.today + 14, conference: subject)
|
||||
subject.program.cfp = create(:cfp)
|
||||
subject.venue = create(:venue, conference: subject)
|
||||
subject.venue.rooms = [create(:room, venue: subject.venue)]
|
||||
|
|
@ -1109,7 +1110,7 @@ describe Conference do
|
|||
subject.program.difficulty_levels = [create(:difficulty_level)]
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.today,
|
||||
end_date: Date.today + 14)
|
||||
end_date: Date.today + 14, conference: subject)
|
||||
subject.program.cfp = create(:cfp)
|
||||
subject.venue = create(:venue, conference: subject)
|
||||
subject.venue.rooms = [create(:room, venue: subject.venue)]
|
||||
|
|
@ -1131,21 +1132,21 @@ describe Conference do
|
|||
it 'is one if start and end are 6 days apart' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.new(2014, 05, 26),
|
||||
end_date: Date.new(2014, 05, 26) + 6)
|
||||
end_date: Date.new(2014, 05, 26) + 6, conference: subject)
|
||||
expect(subject.registration_weeks).to eq(1)
|
||||
end
|
||||
|
||||
it 'is one if start and end date are the same' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.new(2014, 05, 26),
|
||||
end_date: Date.new(2014, 05, 26))
|
||||
end_date: Date.new(2014, 05, 26), conference: subject)
|
||||
expect(subject.registration_weeks).to eq(1)
|
||||
end
|
||||
|
||||
it 'is two if start and end are 10 days apart' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.new(2014, 05, 26),
|
||||
end_date: Date.new(2014, 05, 26) + 10)
|
||||
start_date: Date.new(2014, 05, 17),
|
||||
end_date: Date.new(2014, 05, 15) + 10, conference: subject)
|
||||
expect(subject.registration_weeks).to eq(2)
|
||||
end
|
||||
end
|
||||
|
|
@ -1279,7 +1280,7 @@ describe Conference do
|
|||
it 'pads with zeros if there are no registrations' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.new(2014, 05, 26),
|
||||
end_date: Date.new(2014, 05, 26) + 21)
|
||||
end_date: Date.new(2014, 05, 26) + 21, conference: subject)
|
||||
|
||||
expect(subject.get_registrations_per_week).to eq([0, 0, 0, 0])
|
||||
end
|
||||
|
|
@ -1287,7 +1288,7 @@ describe Conference do
|
|||
it 'summarized correct if there are no registrations in one week' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.new(2014, 05, 26),
|
||||
end_date: Date.new(2014, 05, 26) + 28)
|
||||
end_date: Date.new(2014, 05, 26) + 28, conference: subject)
|
||||
|
||||
create(:registration, conference: subject,
|
||||
created_at: Date.new(2014, 05, 26) + 7)
|
||||
|
|
@ -1302,7 +1303,7 @@ describe Conference do
|
|||
it 'returns [1] if there is one registration on the first day' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.new(2014, 05, 26),
|
||||
end_date: Date.new(2014, 05, 26) + 7)
|
||||
end_date: Date.new(2014, 05, 26) + 7, conference: subject)
|
||||
|
||||
create(:registration, conference: subject,
|
||||
created_at: Date.new(2014, 05, 26))
|
||||
|
|
@ -1312,7 +1313,7 @@ describe Conference do
|
|||
it 'summarized correct if there are registrations every week' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.new(2014, 05, 26),
|
||||
end_date: Date.new(2014, 05, 26) + 21)
|
||||
end_date: Date.new(2014, 05, 26) + 21, conference: subject)
|
||||
|
||||
create(:registration, conference: subject, created_at: Date.new(2014, 05, 26))
|
||||
create(:registration, conference: subject,
|
||||
|
|
@ -1326,7 +1327,7 @@ describe Conference do
|
|||
it 'summarized correct if there are registrations every week except the first' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.new(2014, 05, 26),
|
||||
end_date: Date.new(2014, 05, 26) + 28)
|
||||
end_date: Date.new(2014, 05, 26) + 28, conference: subject)
|
||||
|
||||
create(:registration, conference: subject,
|
||||
created_at: Date.new(2014, 05, 26) + 7)
|
||||
|
|
@ -1341,7 +1342,7 @@ describe Conference do
|
|||
it 'pads left' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.new(2014, 05, 26),
|
||||
end_date: Date.new(2014, 05, 26) + 35)
|
||||
end_date: Date.new(2014, 05, 26) + 35, conference: subject)
|
||||
|
||||
create(:registration, conference: subject,
|
||||
created_at: Date.new(2014, 05, 26) + 21)
|
||||
|
|
@ -1356,7 +1357,7 @@ describe Conference do
|
|||
it 'pads middle' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.new(2014, 05, 26),
|
||||
end_date: Date.new(2014, 05, 26) + 35)
|
||||
end_date: Date.new(2014, 05, 26) + 35, conference: subject)
|
||||
|
||||
create(:registration, conference: subject,
|
||||
created_at: Date.new(2014, 05, 26))
|
||||
|
|
@ -1369,7 +1370,7 @@ describe Conference do
|
|||
it 'pads right' do
|
||||
subject.registration_period = create(:registration_period,
|
||||
start_date: Date.new(2014, 05, 26),
|
||||
end_date: Date.new(2014, 05, 26) + 35)
|
||||
end_date: Date.new(2014, 05, 26) + 35, conference: subject)
|
||||
|
||||
create(:registration, conference: subject,
|
||||
created_at: Date.new(2014, 05, 26))
|
||||
|
|
@ -1411,9 +1412,10 @@ describe Conference do
|
|||
context 'open registration' do
|
||||
|
||||
before do
|
||||
subject.end_date = Date.today + 7
|
||||
enrollment = create(:registration_period,
|
||||
start_date: Date.today - 1,
|
||||
end_date: Date.today + 7)
|
||||
end_date: Date.today + 7, conference: subject)
|
||||
subject.registration_period = enrollment
|
||||
end
|
||||
|
||||
|
|
|
|||
74
spec/models/registration_period_spec.rb
Normal file
74
spec/models/registration_period_spec.rb
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe RegistrationPeriod do
|
||||
let!(:conference) { create(:conference, start_date: Date.today, end_date: Date.today + 6) }
|
||||
let!(:registration_period) { create(:registration_period, start_date: Date.today - 2, end_date: Date.today - 1, conference: conference) }
|
||||
|
||||
describe 'validations' do
|
||||
it 'has a valid factory' do
|
||||
expect(build(:registration_period)).to be_valid
|
||||
end
|
||||
|
||||
it 'is not valid without a start_date' do
|
||||
should validate_presence_of(:start_date)
|
||||
end
|
||||
|
||||
it 'is not valid without an end_date' do
|
||||
should validate_presence_of(:end_date)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#before_end_of_conference' do
|
||||
context 'is valid' do
|
||||
it 'when start_date and end_date are before conference end_date' do
|
||||
registration_period.start_date = conference.end_date - 2
|
||||
registration_period.end_date = conference.end_date - 1
|
||||
expect(registration_period.valid?).to eq true
|
||||
end
|
||||
|
||||
it 'when start_date and end_date are the same day as conference end_date' do
|
||||
registration_period.start_date = conference.end_date
|
||||
registration_period.end_date = conference.end_date
|
||||
expect(registration_period.valid?).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
context 'is invalid' do
|
||||
it 'when start_date and end_date are after conference end_date' do
|
||||
registration_period.start_date = conference.end_date + 1
|
||||
registration_period.end_date = conference.end_date + 2
|
||||
expect(registration_period.valid?).to eq false
|
||||
end
|
||||
|
||||
it 'when end_date is after conference end_date' do
|
||||
registration_period.start_date = conference.end_date - 1
|
||||
registration_period.end_date = conference.end_date + 1
|
||||
expect(registration_period.valid?).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#start_date_before_end_date' do
|
||||
context 'is valid' do
|
||||
it 'when start_date is before end_date' do
|
||||
registration_period.start_date = conference.end_date - 2
|
||||
registration_period.end_date = conference.end_date - 1
|
||||
expect(registration_period.valid?).to eq true
|
||||
end
|
||||
|
||||
it 'when start_date and end_date are on the same day' do
|
||||
registration_period.start_date = conference.end_date - 2
|
||||
registration_period.end_date = conference.end_date - 2
|
||||
expect(registration_period.valid?).to eq true
|
||||
end
|
||||
end
|
||||
|
||||
context 'is invalid' do
|
||||
it 'when start_date is after end_date' do
|
||||
registration_period.start_date = conference.start_date + 2
|
||||
registration_period.end_date = conference.start_date + 1
|
||||
expect(registration_period.valid?).to eq false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue