Tests for registration model
Before registration we need to make sure that conference has registration_period
This commit is contained in:
parent
c71d15565e
commit
13a6586f81
2 changed files with 70 additions and 15 deletions
|
|
@ -7,7 +7,7 @@ FactoryGirl.define do
|
||||||
timezone 'Amsterdam'
|
timezone 'Amsterdam'
|
||||||
start_date { Date.today }
|
start_date { Date.today }
|
||||||
end_date { 6.days.from_now }
|
end_date { 6.days.from_now }
|
||||||
registration_limit 0
|
registration_limit 10
|
||||||
|
|
||||||
after(:create) do |conference|
|
after(:create) do |conference|
|
||||||
Role.where(name: 'organizer', resource: conference).first_or_create(description: 'For the organizers of the conference (who shall have full access)')
|
Role.where(name: 'organizer', resource: conference).first_or_create(description: 'For the organizers of the conference (who shall have full access)')
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,79 @@
|
||||||
#!/bin/env ruby
|
|
||||||
# encoding: utf-8
|
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe 'Registration' do
|
describe Registration do
|
||||||
describe 'validations' do
|
subject { create(:registration) }
|
||||||
|
|
||||||
|
describe 'validation' do
|
||||||
|
|
||||||
it 'has a valid factory' do
|
it 'has a valid factory' do
|
||||||
expect(build(:registration)).to be_valid
|
expect(build(:registration)).to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it { should validate_presence_of(:user) }
|
||||||
|
|
||||||
|
it 'validates uniqueness of user in scope of conference' do
|
||||||
|
expect(build(:registration, conference: subject.conference, user: subject.user)).not_to be_valid
|
||||||
|
end
|
||||||
|
|
||||||
describe 'registration_limit_not_exceed' do
|
describe 'registration_limit_not_exceed' do
|
||||||
it 'is not valid when limit exceeded' do
|
context 'registration_limit has exceeded' do
|
||||||
conference = build(:conference)
|
before do
|
||||||
conference.registration_limit = 1
|
conference = create(:conference, registration_limit: 1)
|
||||||
registration1 = build(:registration, conference: conference)
|
create(:registration, conference: conference)
|
||||||
registration1.save
|
@second_registration = build(:registration, conference: conference)
|
||||||
registration2 = build(:registration, conference: conference)
|
end
|
||||||
registration2.save
|
|
||||||
expect(conference.registrations.size).to be 1
|
it 'is not valid factory' do
|
||||||
expect(registration2.valid?).to be false
|
expect(@second_registration.valid?).to be false
|
||||||
expect(registration2.errors.full_messages).to eq(['Registration limit exceeded'])
|
expect(@second_registration.errors.full_messages).to eq(['Registration limit exceeded'])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'association' do
|
||||||
|
it { should belong_to(:user) }
|
||||||
|
it { should belong_to(:conference) }
|
||||||
|
it { should belong_to(:dietary_choice) }
|
||||||
|
it { should have_and_belong_to_many(:social_events) }
|
||||||
|
it { should have_and_belong_to_many(:events) }
|
||||||
|
it { should have_and_belong_to_many(:qanswers) }
|
||||||
|
it { should have_and_belong_to_many(:vchoices) }
|
||||||
|
it { should have_many(:events_registrations) }
|
||||||
|
it { should have_many(:workshops) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'callback' do
|
||||||
|
after { subject.run_callbacks(:create) }
|
||||||
|
|
||||||
|
# set_week and subscribe_to_conference are private methods
|
||||||
|
describe '#set_week' do
|
||||||
|
before { subject.created_at = Time.utc(2014, 5, 10) }
|
||||||
|
|
||||||
|
it 'sets week of registration' do
|
||||||
|
expect(subject).to receive(:set_week)
|
||||||
|
expect(subject.week).to eq 18
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#subscribe_to_conference' do
|
||||||
|
it 'subscribes to conference' do
|
||||||
|
expect(subject).to receive(:subscribe_to_conference)
|
||||||
|
expect(subject.user.subscribed?(subject.conference)).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'sends registrations mail' do
|
||||||
|
expect(subject).to receive(:send_registration_mail)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'method' do
|
||||||
|
describe '#week' do
|
||||||
|
before { subject.created_at = Date.new(2014, 06, 30) }
|
||||||
|
|
||||||
|
it 'returns week number of created_at' do
|
||||||
|
expect(subject.week).to eq(26)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue