2018-05-07 16:47:29 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2016-02-02 00:16:43 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
2018-10-23 19:31:46 -07:00
|
|
|
describe Registration do
|
2016-03-17 14:31:13 +05:30
|
|
|
subject { create(:registration) }
|
2016-03-12 11:57:48 +05:30
|
|
|
let!(:user) { create(:user) }
|
|
|
|
|
let!(:conference) { create(:conference) }
|
2016-04-22 18:18:46 +03:00
|
|
|
let!(:registration) { create(:registration, conference: conference, user: user) }
|
2016-03-17 14:31:13 +05:30
|
|
|
|
|
|
|
|
describe 'validation' do
|
|
|
|
|
it { is_expected.to 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
|
|
|
|
|
|
2016-02-02 00:16:43 +01:00
|
|
|
describe 'registration_limit_not_exceed' do
|
|
|
|
|
it 'is not valid when limit exceeded' do
|
|
|
|
|
conference.registration_limit = 1
|
2017-08-22 21:41:13 +05:30
|
|
|
expect { create(:registration, conference: conference, user: user) }.to raise_error('Validation failed: User already Registered!, Registration limit exceeded')
|
2016-03-12 11:57:48 +05:30
|
|
|
expect(user.registrations.size).to be 1
|
2016-02-02 00:16:43 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-03-12 11:57:48 +05:30
|
|
|
|
2016-03-17 14:31:13 +05:30
|
|
|
describe 'association' do
|
|
|
|
|
it { is_expected.to belong_to(:user) }
|
|
|
|
|
it { is_expected.to belong_to(:conference) }
|
|
|
|
|
it { is_expected.to have_and_belong_to_many(:qanswers) }
|
|
|
|
|
it { is_expected.to have_and_belong_to_many(:vchoices) }
|
|
|
|
|
it { is_expected.to have_many(:events_registrations) }
|
2016-04-22 18:18:46 +03:00
|
|
|
it { is_expected.to have_many(:events) }
|
2016-03-17 14:31:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'after create' do
|
|
|
|
|
after { subject.run_callbacks(:create) }
|
|
|
|
|
|
|
|
|
|
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 true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
it 'sends registrations mail' do
|
|
|
|
|
expect(subject).to receive(:send_registration_mail)
|
|
|
|
|
end
|
|
|
|
|
end
|
2016-02-02 00:16:43 +01:00
|
|
|
end
|