Add registration_limit to conference model. Added the input for registration limit in the edit conference form. In the controller, if the limit has exceeded redirect to root_path with an alert. fix #761

This commit is contained in:
David Sedeño 2016-02-02 00:16:43 +01:00
parent 2034c0f965
commit 28fbc518f3
12 changed files with 124 additions and 16 deletions

View file

@ -1479,6 +1479,48 @@ describe Conference do
end
end
describe 'registration_limit_exceeded?' do
context 'limit less than 0' do
before do
subject.registration_limit = -1
end
it '#registration_limit_exceeded? is false' do
expect(subject.registration_limit_exceeded?).to be false
end
end
context 'limit is 0' do
before do
subject.registration_limit = 0
end
it '#registration_limit_exceeded? is false' do
expect(subject.registration_limit_exceeded?).to be false
end
end
context 'limit is 1' do
before do
subject.registration_limit = 1
end
context 'there are no registration' do
it '#registration_limit_exceeded? is false' do
expect(subject.registration_limit_exceeded?).to be false
end
end
context 'there are 1 registration' do
before do
registration1 = create(:registration)
subject.registrations << registration1
end
it '#registration_limit_exceeded? is true' do
expect(subject.registration_limit_exceeded?).to be true
end
end
end
end
describe 'validations' do
it 'has a valid factory' do
@ -1513,6 +1555,14 @@ describe Conference do
should_not allow_value('&%§!?äÄüÜ/()').for(:short_title)
end
it 'is not valid with a registration limit as float' do
should_not allow_value(0.5).for(:registration_limit)
end
it 'is not valid with a negative registration limit' do
should_not allow_value(-1).for(:registration_limit)
end
describe 'valid_date_range?' do
it 'is not valid if start date is greater than end date' do

View file

@ -0,0 +1,25 @@
#!/bin/env ruby
# encoding: utf-8
require 'spec_helper'
describe 'Registration' do
describe 'validations' do
it 'has a valid factory' do
expect(build(:registration)).to be_valid
end
describe 'registration_limit_not_exceed' do
it 'is not valid when limit exceeded' do
conference = build(:conference)
conference.registration_limit = 1
registration1 = build(:registration, conference: conference)
registration1.save
registration2 = build(:registration, conference: conference)
registration2.save
expect(conference.registrations.size).to be 1
expect(registration2.valid?).to be false
expect(registration2.errors.full_messages).to eq(['Registration limit exceeded'])
end
end
end
end