2015-08-13 15:55:19 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Dossier do
|
2015-09-24 11:17:17 +02:00
|
|
|
let(:user) { create(:user) }
|
2015-08-17 11:13:21 +02:00
|
|
|
describe 'database columns' do
|
|
|
|
it { is_expected.to have_db_column(:description) }
|
|
|
|
it { is_expected.to have_db_column(:autorisation_donnees) }
|
|
|
|
it { is_expected.to have_db_column(:nom_projet) }
|
2015-09-22 11:04:04 +02:00
|
|
|
it { is_expected.to have_db_column(:created_at) }
|
|
|
|
it { is_expected.to have_db_column(:updated_at) }
|
2015-11-02 18:56:41 +01:00
|
|
|
it { is_expected.to have_db_column(:state) }
|
|
|
|
it { is_expected.to have_db_column(:procedure_id) }
|
|
|
|
it { is_expected.to have_db_column(:user_id) }
|
2015-08-17 11:13:21 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'associations' do
|
2015-09-21 17:59:03 +02:00
|
|
|
it { is_expected.to belong_to(:procedure) }
|
|
|
|
it { is_expected.to have_many(:pieces_justificatives) }
|
2015-11-03 10:48:40 +01:00
|
|
|
it { is_expected.to have_many(:champs) }
|
2015-08-17 11:13:21 +02:00
|
|
|
it { is_expected.to have_many(:commentaires) }
|
2015-08-18 13:52:00 +02:00
|
|
|
it { is_expected.to have_one(:cerfa) }
|
2015-08-17 11:13:21 +02:00
|
|
|
it { is_expected.to have_one(:etablissement) }
|
|
|
|
it { is_expected.to have_one(:entreprise) }
|
2015-09-23 12:16:21 +02:00
|
|
|
it { is_expected.to belong_to(:user) }
|
2015-08-17 11:13:21 +02:00
|
|
|
end
|
|
|
|
|
2015-08-20 17:30:17 +02:00
|
|
|
describe 'delegation' do
|
2015-08-20 14:24:26 +02:00
|
|
|
it { is_expected.to delegate_method(:siren).to(:entreprise) }
|
|
|
|
it { is_expected.to delegate_method(:siret).to(:etablissement) }
|
2015-09-21 17:59:03 +02:00
|
|
|
it { is_expected.to delegate_method(:types_de_piece_justificative).to(:procedure) }
|
2015-11-03 15:27:49 +01:00
|
|
|
it { is_expected.to delegate_method(:types_de_champs).to(:procedure) }
|
2015-08-20 14:24:26 +02:00
|
|
|
end
|
|
|
|
|
2015-08-21 11:37:13 +02:00
|
|
|
describe 'validation' do
|
2015-08-25 10:19:39 +02:00
|
|
|
context 'nom_projet' do
|
|
|
|
it { is_expected.to allow_value(nil).for(:nom_projet) }
|
|
|
|
it { is_expected.not_to allow_value('').for(:nom_projet) }
|
|
|
|
it { is_expected.to allow_value('mon super projet').for(:nom_projet) }
|
|
|
|
end
|
|
|
|
context 'description' do
|
|
|
|
it { is_expected.to allow_value(nil).for(:description) }
|
|
|
|
it { is_expected.not_to allow_value('').for(:description) }
|
|
|
|
it { is_expected.to allow_value('ma superbe description').for(:description) }
|
|
|
|
end
|
2015-08-21 11:37:13 +02:00
|
|
|
end
|
2015-08-13 15:55:19 +02:00
|
|
|
|
2015-08-21 11:37:13 +02:00
|
|
|
describe 'methods' do
|
2015-09-24 11:17:17 +02:00
|
|
|
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure, user: user) }
|
2015-08-13 15:55:19 +02:00
|
|
|
|
2015-08-21 11:37:13 +02:00
|
|
|
let(:entreprise) { dossier.entreprise }
|
|
|
|
let(:etablissement) { dossier.etablissement }
|
2015-08-18 14:22:16 +02:00
|
|
|
|
2015-08-21 11:37:13 +02:00
|
|
|
subject { dossier }
|
2015-08-18 14:22:16 +02:00
|
|
|
|
2015-09-21 17:59:03 +02:00
|
|
|
describe '#types_de_piece_justificative' do
|
|
|
|
subject { dossier.types_de_piece_justificative }
|
2015-08-21 11:37:13 +02:00
|
|
|
it 'returns list of required piece justificative' do
|
2015-09-21 17:59:03 +02:00
|
|
|
expect(subject.size).to eq(2)
|
|
|
|
expect(subject).to include(TypeDePieceJustificative.find(TypeDePieceJustificative.first.id))
|
2015-08-21 11:37:13 +02:00
|
|
|
end
|
2015-08-18 14:22:16 +02:00
|
|
|
end
|
2015-08-18 15:15:34 +02:00
|
|
|
|
2015-08-21 11:37:13 +02:00
|
|
|
describe 'creation' do
|
|
|
|
it 'create default cerfa' do
|
2015-09-24 11:17:17 +02:00
|
|
|
expect { described_class.create(user: user) }.to change { Cerfa.count }.by(1)
|
2015-08-21 11:37:13 +02:00
|
|
|
end
|
2015-08-20 15:15:20 +02:00
|
|
|
|
2015-08-21 11:37:13 +02:00
|
|
|
it 'link cerfa to dossier' do
|
|
|
|
dossier = described_class.create
|
|
|
|
expect(dossier.cerfa).to eq(Cerfa.last)
|
|
|
|
end
|
2015-08-20 15:15:20 +02:00
|
|
|
end
|
|
|
|
|
2015-09-21 17:59:03 +02:00
|
|
|
describe '#retrieve_piece_justificative_by_type' do
|
|
|
|
let(:all_dossier_pj_id){dossier.procedure.types_de_piece_justificative}
|
|
|
|
subject { dossier.retrieve_piece_justificative_by_type all_dossier_pj_id.first }
|
2015-08-18 15:15:34 +02:00
|
|
|
before do
|
2015-09-21 17:59:03 +02:00
|
|
|
dossier.build_default_pieces_justificatives
|
2015-08-18 15:15:34 +02:00
|
|
|
end
|
2015-08-21 11:37:13 +02:00
|
|
|
|
2015-09-21 17:59:03 +02:00
|
|
|
it 'returns piece justificative with given type' do
|
|
|
|
expect(subject.type).to eq(all_dossier_pj_id.first.id)
|
2015-08-21 11:37:13 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-21 17:59:03 +02:00
|
|
|
describe '#build_default_pieces_justificatives' do
|
|
|
|
context 'when dossier is linked to a procedure' do
|
2015-09-24 11:17:17 +02:00
|
|
|
let(:dossier) { create(:dossier, :with_procedure, user: user) }
|
2015-09-21 17:59:03 +02:00
|
|
|
it 'build all pieces justificatives needed' do
|
|
|
|
expect(dossier.pieces_justificatives.count).to eq(2)
|
2015-08-21 11:37:13 +02:00
|
|
|
end
|
2015-08-18 15:15:34 +02:00
|
|
|
end
|
|
|
|
end
|
2015-08-24 15:23:07 +02:00
|
|
|
|
2015-11-03 15:27:49 +01:00
|
|
|
describe '#build_default_champs' do
|
|
|
|
context 'when dossier is linked to a procedure' do
|
|
|
|
let(:dossier) { create(:dossier, :with_procedure, user: user) }
|
|
|
|
it 'build all champs needed' do
|
|
|
|
expect(dossier.champs.count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-24 15:23:07 +02:00
|
|
|
describe '#save' do
|
2015-09-24 11:17:17 +02:00
|
|
|
subject { create(:dossier, procedure_id: nil, user: user) }
|
2015-11-03 15:27:49 +01:00
|
|
|
let!(:procedure) { create(:procedure) }
|
2015-09-21 17:59:03 +02:00
|
|
|
context 'when is linked to a procedure' do
|
|
|
|
it 'creates default pieces justificatives' do
|
|
|
|
expect(subject).to receive(:build_default_pieces_justificatives)
|
2015-11-03 15:27:49 +01:00
|
|
|
subject.update_attributes(procedure_id: procedure.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates default champs' do
|
|
|
|
expect(subject).to receive(:build_default_champs)
|
|
|
|
subject.update_attributes(procedure_id: procedure.id)
|
2015-08-24 15:23:07 +02:00
|
|
|
end
|
|
|
|
end
|
2015-09-21 17:59:03 +02:00
|
|
|
context 'when is not linked to a procedure' do
|
|
|
|
it 'does not create default pieces justificatives' do
|
|
|
|
expect(subject).not_to receive(:build_default_pieces_justificatives)
|
2015-08-24 15:23:07 +02:00
|
|
|
subject.update_attributes(description: 'plop')
|
|
|
|
end
|
2015-11-03 15:27:49 +01:00
|
|
|
|
|
|
|
it 'does not create default champss' do
|
|
|
|
expect(subject).not_to receive(:build_default_champs)
|
|
|
|
subject.update_attributes(description: 'plop')
|
|
|
|
end
|
2015-08-24 15:23:07 +02:00
|
|
|
end
|
|
|
|
end
|
2015-09-24 10:27:14 +02:00
|
|
|
|
|
|
|
describe '#next_step' do
|
2015-09-24 11:20:04 +02:00
|
|
|
let(:dossier) { create(:dossier, :with_user) }
|
2015-09-24 10:27:14 +02:00
|
|
|
let(:role) { 'user' }
|
2015-11-02 15:31:15 +01:00
|
|
|
let(:action) { 'initiate' }
|
2015-09-24 10:27:14 +02:00
|
|
|
|
|
|
|
subject { dossier.next_step! role, action }
|
|
|
|
|
|
|
|
context 'when action is not valid' do
|
|
|
|
let(:action) { 'test' }
|
|
|
|
it { expect{ subject }.to raise_error('action is not valid') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when role is not valid' do
|
|
|
|
let(:role) { 'test' }
|
|
|
|
it { expect{ subject }.to raise_error('role is not valid') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when dossier is at state draft' do
|
|
|
|
before do
|
|
|
|
dossier.draft!
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is connected' do
|
|
|
|
let(:role) { 'user' }
|
|
|
|
|
|
|
|
context 'when he updates dossier informations' do
|
|
|
|
let(:action) {'update'}
|
|
|
|
|
|
|
|
it { is_expected.to eq('draft') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when he posts a comment' do
|
|
|
|
let(:action) {'comment'}
|
|
|
|
|
|
|
|
it { is_expected.to eq('draft') }
|
|
|
|
end
|
|
|
|
|
2015-11-02 15:31:15 +01:00
|
|
|
context 'when he initiate a dossier' do
|
|
|
|
let(:action) { 'initiate' }
|
2015-09-24 10:27:14 +02:00
|
|
|
|
2015-11-02 15:31:15 +01:00
|
|
|
it { is_expected.to eq('initiated') }
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-02 15:31:15 +01:00
|
|
|
context 'when dossier is at state initiated' do
|
2015-09-24 10:27:14 +02:00
|
|
|
before do
|
2015-11-02 15:31:15 +01:00
|
|
|
dossier.initiated!
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is connect' do
|
|
|
|
let(:role) { 'user' }
|
|
|
|
|
|
|
|
context 'when is update dossier informations' do
|
|
|
|
let(:action) { 'update' }
|
|
|
|
|
2015-11-02 15:31:15 +01:00
|
|
|
it {is_expected.to eq('initiated')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
|
|
|
|
2015-11-02 15:31:15 +01:00
|
|
|
it {is_expected.to eq('initiated')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire is connect' do
|
|
|
|
let(:role) { 'gestionnaire' }
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
|
|
|
|
2015-11-02 11:33:00 +01:00
|
|
|
it { is_expected.to eq('replied')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
context 'when is validated the dossier' do
|
|
|
|
let(:action) { 'valid' }
|
2015-09-24 10:27:14 +02:00
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
it {is_expected.to eq('validated')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-02 11:33:00 +01:00
|
|
|
context 'when dossier is at state replied' do
|
2015-09-24 10:27:14 +02:00
|
|
|
before do
|
2015-11-02 11:33:00 +01:00
|
|
|
dossier.replied!
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is connect' do
|
|
|
|
let(:role) { 'user' }
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
|
|
|
|
|
|
|
it { is_expected.to eq('updated') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when is updated dossier informations' do
|
|
|
|
let(:action) { 'update' }
|
|
|
|
|
|
|
|
it {
|
|
|
|
|
|
|
|
is_expected.to eq('updated')
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire is connect' do
|
|
|
|
let(:role) { 'gestionnaire' }
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
|
|
|
|
2015-11-02 11:33:00 +01:00
|
|
|
it { is_expected.to eq('replied')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
context 'when is validated the dossier' do
|
|
|
|
let(:action) { 'valid' }
|
2015-09-24 10:27:14 +02:00
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
it {is_expected.to eq('validated')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when dossier is at state updated' do
|
|
|
|
before do
|
|
|
|
dossier.updated!
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is connect' do
|
|
|
|
let(:role) { 'user' }
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
|
|
|
|
|
|
|
it { is_expected.to eq('updated')}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when is updated dossier informations' do
|
|
|
|
let(:action) { 'update' }
|
|
|
|
|
|
|
|
it { is_expected.to eq('updated')}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire is connect' do
|
|
|
|
let(:role) { 'gestionnaire' }
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
|
|
|
|
2015-11-02 11:33:00 +01:00
|
|
|
it { is_expected.to eq('replied')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
context 'when is validated the dossier' do
|
|
|
|
let(:action) { 'valid' }
|
2015-09-24 10:27:14 +02:00
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
it {is_expected.to eq('validated')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
context 'when dossier is at state validated' do
|
2015-09-24 10:27:14 +02:00
|
|
|
before do
|
2015-11-02 11:45:52 +01:00
|
|
|
dossier.validated!
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is connect' do
|
|
|
|
let(:role) { 'user' }
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
2015-11-02 11:45:52 +01:00
|
|
|
it { is_expected.to eq('validated') }
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
|
2015-11-02 15:46:43 +01:00
|
|
|
context 'when is submitted the dossier' do
|
|
|
|
let(:action) { 'submit' }
|
2015-09-24 10:27:14 +02:00
|
|
|
|
2015-11-02 15:46:43 +01:00
|
|
|
it { is_expected.to eq('submitted') }
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire is connect' do
|
|
|
|
let(:role) { 'gestionnaire' }
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
|
|
|
|
2015-11-02 11:45:52 +01:00
|
|
|
it { is_expected.to eq('validated')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-02 15:46:43 +01:00
|
|
|
context 'when dossier is at state submitted' do
|
2015-09-24 10:27:14 +02:00
|
|
|
before do
|
2015-11-02 15:46:43 +01:00
|
|
|
dossier.submitted!
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is connect' do
|
|
|
|
let(:role) { 'user' }
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
|
|
|
|
2015-11-02 15:46:43 +01:00
|
|
|
it { is_expected.to eq('submitted') }
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire is connect' do
|
|
|
|
let(:role) { 'gestionnaire' }
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
|
|
|
|
2015-11-02 15:46:43 +01:00
|
|
|
it {is_expected.to eq('submitted')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
|
2015-11-02 15:00:28 +01:00
|
|
|
context 'when is closed the dossier' do
|
|
|
|
let(:action) { 'close' }
|
2015-09-24 10:27:14 +02:00
|
|
|
|
2015-11-02 15:00:28 +01:00
|
|
|
it {is_expected.to eq('closed')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-11-02 15:00:28 +01:00
|
|
|
context 'when dossier is at state closed' do
|
2015-09-24 10:27:14 +02:00
|
|
|
before do
|
2015-11-02 15:00:28 +01:00
|
|
|
dossier.closed!
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is connect' do
|
|
|
|
let(:role) { 'user' }
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
|
|
|
|
2015-11-02 15:00:28 +01:00
|
|
|
it { is_expected.to eq('closed')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire is connect' do
|
|
|
|
let(:role) { 'gestionnaire' }
|
|
|
|
|
|
|
|
context 'when is post a comment' do
|
|
|
|
let(:action) { 'comment' }
|
|
|
|
|
2015-11-02 15:00:28 +01:00
|
|
|
it { is_expected.to eq('closed')}
|
2015-09-24 10:27:14 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-09-24 18:12:08 +02:00
|
|
|
|
|
|
|
context 'gestionnaire backoffice methods' do
|
|
|
|
let!(:dossier1) { create(:dossier, :with_user, :with_procedure, state: 'draft')}
|
2015-11-02 15:31:15 +01:00
|
|
|
let!(:dossier2) { create(:dossier, :with_user, :with_procedure, state: 'initiated')}
|
|
|
|
let!(:dossier3) { create(:dossier, :with_user, :with_procedure, state: 'initiated')}
|
2015-11-02 11:33:00 +01:00
|
|
|
let!(:dossier4) { create(:dossier, :with_user, :with_procedure, state: 'replied')}
|
2015-09-24 18:12:08 +02:00
|
|
|
let!(:dossier5) { create(:dossier, :with_user, :with_procedure, state: 'updated')}
|
2015-11-02 11:45:52 +01:00
|
|
|
let!(:dossier6) { create(:dossier, :with_user, :with_procedure, state: 'validated')}
|
2015-11-02 15:46:43 +01:00
|
|
|
let!(:dossier7) { create(:dossier, :with_user, :with_procedure, state: 'submitted')}
|
2015-11-02 15:00:28 +01:00
|
|
|
let!(:dossier8) { create(:dossier, :with_user, :with_procedure, state: 'closed')}
|
2015-09-24 18:12:08 +02:00
|
|
|
|
|
|
|
describe '#a_traiter' do
|
|
|
|
subject { described_class.a_traiter }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(4) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#en_attente' do
|
|
|
|
subject { described_class.en_attente }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(2) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#termine' do
|
|
|
|
subject { described_class.termine }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq(1) }
|
|
|
|
end
|
|
|
|
end
|
2015-08-18 15:15:34 +02:00
|
|
|
end
|
2015-08-20 17:30:17 +02:00
|
|
|
end
|