2016-11-14 18:36:09 +01:00
|
|
|
require 'spec_helper'
|
2015-09-23 10:02:01 +02:00
|
|
|
|
|
|
|
describe User, type: :model do
|
|
|
|
describe 'database columns' do
|
|
|
|
it { is_expected.to have_db_column(:email) }
|
|
|
|
it { is_expected.to have_db_column(:encrypted_password) }
|
|
|
|
it { is_expected.to have_db_column(:reset_password_token) }
|
|
|
|
it { is_expected.to have_db_column(:reset_password_sent_at) }
|
|
|
|
it { is_expected.to have_db_column(:remember_created_at) }
|
|
|
|
it { is_expected.to have_db_column(:sign_in_count) }
|
|
|
|
it { is_expected.to have_db_column(:current_sign_in_at) }
|
|
|
|
it { is_expected.to have_db_column(:last_sign_in_at) }
|
|
|
|
it { is_expected.to have_db_column(:current_sign_in_ip) }
|
|
|
|
it { is_expected.to have_db_column(:last_sign_in_ip) }
|
|
|
|
it { is_expected.to have_db_column(:created_at) }
|
|
|
|
it { is_expected.to have_db_column(:updated_at) }
|
2015-10-07 10:29:44 +02:00
|
|
|
it { is_expected.to have_db_column(:siret) }
|
2015-10-08 11:26:12 +02:00
|
|
|
it { is_expected.to have_db_column(:loged_in_with_france_connect) }
|
2015-09-23 10:02:01 +02:00
|
|
|
end
|
2015-09-23 12:16:21 +02:00
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to have_many(:dossiers) }
|
2016-02-08 18:16:18 +01:00
|
|
|
it { is_expected.to have_many(:invites) }
|
2016-03-17 17:33:38 +01:00
|
|
|
it { is_expected.to have_many(:piece_justificative) }
|
|
|
|
it { is_expected.to have_many(:cerfa) }
|
2015-09-23 12:16:21 +02:00
|
|
|
end
|
2015-10-07 10:29:44 +02:00
|
|
|
describe '#find_for_france_connect' do
|
|
|
|
let(:siret) { '00000000000000' }
|
|
|
|
context 'when user exist' do
|
|
|
|
let!(:user) { create(:user) }
|
|
|
|
subject { described_class.find_for_france_connect(user.email, siret) }
|
|
|
|
it 'retrieves user' do
|
|
|
|
expect(subject).to eq(user)
|
|
|
|
end
|
|
|
|
it 'saves siret in user' do
|
|
|
|
expect(subject.siret).to eq(siret)
|
|
|
|
end
|
|
|
|
it 'does not create new user' do
|
2016-03-22 17:36:36 +01:00
|
|
|
expect { subject }.not_to change(User, :count)
|
2015-10-07 10:29:44 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
context 'when user does not exist' do
|
|
|
|
let(:email) { 'super-m@n.com' }
|
|
|
|
subject { described_class.find_for_france_connect(email, siret) }
|
|
|
|
it 'returns user' do
|
|
|
|
expect(subject).to be_an_instance_of(User)
|
|
|
|
end
|
|
|
|
it 'creates new user' do
|
2016-03-22 17:36:36 +01:00
|
|
|
expect { subject }.to change(User, :count).by(1)
|
2015-10-07 10:29:44 +02:00
|
|
|
end
|
|
|
|
it 'saves siret' do
|
|
|
|
expect(subject.siret).to eq(siret)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-03-22 17:36:36 +01:00
|
|
|
|
|
|
|
describe '#invite?' do
|
|
|
|
let(:dossier) { create :dossier }
|
|
|
|
let(:user) { dossier.user }
|
|
|
|
|
|
|
|
subject { user.invite? dossier.id }
|
|
|
|
|
|
|
|
context 'when user is invite at the dossier' do
|
|
|
|
before do
|
|
|
|
create :invite, dossier_id: dossier.id, user: user
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not invite at the dossier' do
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
2016-10-11 10:31:32 +02:00
|
|
|
|
2016-10-18 15:49:04 +02:00
|
|
|
context 'unified login' do
|
|
|
|
it 'syncs credentials to associated gestionnaire' do
|
|
|
|
user = create(:user)
|
|
|
|
gestionnaire = create(:gestionnaire, email: user.email)
|
2016-10-11 10:31:32 +02:00
|
|
|
|
2016-10-18 15:49:04 +02:00
|
|
|
user.update_attributes(email: 'whoami@plop.com', password: 'super secret')
|
|
|
|
|
|
|
|
gestionnaire.reload
|
|
|
|
expect(gestionnaire.email).to eq('whoami@plop.com')
|
|
|
|
expect(gestionnaire.valid_password?('super secret')).to be(true)
|
|
|
|
end
|
2016-12-07 17:24:01 +01:00
|
|
|
|
|
|
|
it 'syncs credentials to associated administrateur' do
|
|
|
|
user = create(:user)
|
|
|
|
admin = create(:administrateur, email: user.email)
|
|
|
|
|
|
|
|
user.update_attributes(email: 'whoami@plop.com', password: 'super secret')
|
|
|
|
|
|
|
|
admin.reload
|
|
|
|
expect(admin.email).to eq('whoami@plop.com')
|
|
|
|
expect(admin.valid_password?('super secret')).to be(true)
|
|
|
|
end
|
2016-10-11 10:31:32 +02:00
|
|
|
end
|
2015-09-23 10:02:01 +02:00
|
|
|
end
|