2015-09-21 17:59:03 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Procedure do
|
|
|
|
describe 'assocations' do
|
|
|
|
it { is_expected.to have_many(:types_de_piece_justificative) }
|
2015-11-05 11:21:44 +01:00
|
|
|
it { is_expected.to have_many(:types_de_champ) }
|
2015-09-21 17:59:03 +02:00
|
|
|
it { is_expected.to have_many(:dossiers) }
|
2016-08-31 16:07:11 +02:00
|
|
|
it { is_expected.to have_many(:mail_templates) }
|
|
|
|
it { is_expected.to have_one(:mail_received) }
|
2015-12-08 10:11:58 +01:00
|
|
|
it { is_expected.to have_one(:module_api_carto) }
|
2015-11-10 10:23:15 +01:00
|
|
|
it { is_expected.to belong_to(:administrateur) }
|
2016-09-08 16:21:54 +02:00
|
|
|
it { is_expected.to have_many(:preference_list_dossiers) }
|
2015-09-21 17:59:03 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'attributes' do
|
|
|
|
it { is_expected.to have_db_column(:libelle) }
|
|
|
|
it { is_expected.to have_db_column(:description) }
|
|
|
|
it { is_expected.to have_db_column(:organisation) }
|
|
|
|
it { is_expected.to have_db_column(:direction) }
|
|
|
|
it { is_expected.to have_db_column(:test) }
|
2015-12-10 17:13:39 +01:00
|
|
|
it { is_expected.to have_db_column(:euro_flag) }
|
|
|
|
it { is_expected.to have_db_column(:logo) }
|
2016-05-18 11:43:32 +02:00
|
|
|
it { is_expected.to have_db_column(:logo_secure_token) }
|
2016-02-02 18:37:38 +01:00
|
|
|
it { is_expected.to have_db_column(:cerfa_flag) }
|
2016-06-24 16:41:44 +02:00
|
|
|
it { is_expected.to have_db_column(:published) }
|
2016-08-31 16:07:11 +02:00
|
|
|
|
|
|
|
describe 'mail_received' do
|
|
|
|
let(:procedure) { create :procedure }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create :mail_received, procedure: procedure
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure.mail_received).not_to be_nil }
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#build_default_mails' do
|
|
|
|
subject { build :procedure }
|
|
|
|
|
|
|
|
it 'call the fonction build_default_mails' do
|
|
|
|
expect(subject).to receive(:build_default_mails)
|
|
|
|
subject.save
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'accessible values' do
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject.save
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.mail_templates.size).to eq 1 }
|
|
|
|
it { expect(subject.mail_received).not_to be_nil }
|
|
|
|
end
|
2015-09-21 17:59:03 +02:00
|
|
|
end
|
2015-09-22 11:21:52 +02:00
|
|
|
|
|
|
|
describe 'validation' do
|
|
|
|
context 'libelle' do
|
|
|
|
it { is_expected.not_to allow_value(nil).for(:libelle) }
|
|
|
|
it { is_expected.not_to allow_value('').for(:libelle) }
|
|
|
|
it { is_expected.to allow_value('Demande de subvention').for(:libelle) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'description' do
|
|
|
|
it { is_expected.not_to allow_value(nil).for(:description) }
|
|
|
|
it { is_expected.not_to allow_value('').for(:description) }
|
|
|
|
it { is_expected.to allow_value('Description Demande de subvention').for(:description) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'lien_demarche' do
|
2015-10-26 18:08:41 +01:00
|
|
|
it { is_expected.to allow_value(nil).for(:lien_demarche) }
|
|
|
|
it { is_expected.to allow_value('').for(:lien_demarche) }
|
2015-09-22 11:21:52 +02:00
|
|
|
it { is_expected.to allow_value('http://localhost').for(:lien_demarche) }
|
|
|
|
end
|
|
|
|
end
|
2015-11-17 15:30:03 +01:00
|
|
|
|
|
|
|
describe '#types_de_champ_ordered' do
|
|
|
|
let(:procedure) { create(:procedure) }
|
2016-08-03 18:19:56 +02:00
|
|
|
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
|
|
|
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
2015-11-17 15:30:03 +01:00
|
|
|
subject { procedure.types_de_champ_ordered }
|
|
|
|
it { expect(subject.first).to eq(type_de_champ_1) }
|
|
|
|
it { expect(subject.last).to eq(type_de_champ_0) }
|
|
|
|
end
|
2015-11-19 11:37:01 +01:00
|
|
|
|
|
|
|
describe '#switch_types_de_champ' do
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
let(:index) { 0 }
|
2015-12-21 14:40:28 +01:00
|
|
|
subject { procedure.switch_types_de_champ index }
|
2015-11-19 11:37:01 +01:00
|
|
|
|
|
|
|
context 'when procedure have no types_de_champ' do
|
|
|
|
it { expect(subject).to eq(false) }
|
|
|
|
end
|
|
|
|
context 'when procedure have 2 types de champ' do
|
2016-08-03 18:19:56 +02:00
|
|
|
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
|
|
|
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
2015-11-19 11:37:01 +01:00
|
|
|
context 'when index is not the last element' do
|
|
|
|
it { expect(subject).to eq(true) }
|
|
|
|
it 'switch order place' do
|
|
|
|
procedure.switch_types_de_champ index
|
|
|
|
type_de_champ_0.reload
|
|
|
|
type_de_champ_1.reload
|
|
|
|
expect(type_de_champ_0.order_place).to eq(1)
|
|
|
|
expect(type_de_champ_1.order_place).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
context 'when index is the last element' do
|
|
|
|
let(:index) { 1 }
|
|
|
|
it { expect(subject).to eq(false) }
|
|
|
|
end
|
|
|
|
end
|
2015-12-21 14:40:28 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'locked?' do
|
2016-06-09 17:49:38 +02:00
|
|
|
let(:procedure) { create(:procedure, published: published) }
|
2015-12-21 14:40:28 +01:00
|
|
|
|
|
|
|
subject { procedure.locked? }
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
context 'when procedure is in draft status' do
|
|
|
|
let(:published) { false }
|
2015-12-21 14:40:28 +01:00
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
context 'when procedure is in draft status' do
|
|
|
|
let(:published) { true }
|
|
|
|
it { is_expected.to be_truthy }
|
2015-12-21 14:40:28 +01:00
|
|
|
end
|
2016-06-09 17:49:38 +02:00
|
|
|
end
|
2015-12-21 14:40:28 +01:00
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
describe 'active' do
|
|
|
|
let(:procedure) { create(:procedure, published: published, archived: archived) }
|
|
|
|
subject { Procedure.active(procedure.id) }
|
2015-12-21 14:40:28 +01:00
|
|
|
|
2016-06-09 17:49:38 +02:00
|
|
|
context 'when procedure is in draft status and not archived' do
|
|
|
|
let(:published) { false }
|
|
|
|
let(:archived) { false }
|
|
|
|
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure is published and not archived' do
|
|
|
|
let(:published) { true }
|
|
|
|
let(:archived) { false }
|
2015-12-21 14:40:28 +01:00
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
2016-06-09 17:49:38 +02:00
|
|
|
|
|
|
|
context 'when procedure is published and archived' do
|
|
|
|
let(:published) { true }
|
|
|
|
let(:archived) { true }
|
|
|
|
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure is in draft status and archived' do
|
|
|
|
let(:published) { false }
|
|
|
|
let(:archived) { true }
|
|
|
|
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
2015-12-21 14:40:28 +01:00
|
|
|
end
|
2016-06-15 11:34:05 +02:00
|
|
|
|
|
|
|
describe 'clone' do
|
|
|
|
let(:archived) { false }
|
|
|
|
let(:published) { false }
|
|
|
|
let(:procedure) { create(:procedure, archived: archived, published: published) }
|
2016-08-03 18:19:56 +02:00
|
|
|
let!(:type_de_champ_0) { create(:type_de_champ_public, procedure: procedure, order_place: 0) }
|
|
|
|
let!(:type_de_champ_1) { create(:type_de_champ_public, procedure: procedure, order_place: 1) }
|
2016-06-15 11:34:05 +02:00
|
|
|
let!(:piece_justificative_0) { create(:type_de_piece_justificative, procedure: procedure, order_place: 0) }
|
|
|
|
let!(:piece_justificative_1) { create(:type_de_piece_justificative, procedure: procedure, order_place: 1) }
|
2016-09-01 10:43:49 +02:00
|
|
|
|
|
|
|
before do
|
|
|
|
procedure.mail_received.object = "Je vais être cloné"
|
|
|
|
end
|
|
|
|
|
2016-06-15 11:34:05 +02:00
|
|
|
subject { procedure.clone }
|
|
|
|
|
|
|
|
it 'should duplicate specific objects with different id' do
|
|
|
|
expect(subject.id).not_to eq(procedure.id)
|
|
|
|
expect(subject).to have_same_attributes_as(procedure)
|
|
|
|
expect(subject.module_api_carto).to have_same_attributes_as(procedure.module_api_carto)
|
|
|
|
|
2016-09-01 10:43:49 +02:00
|
|
|
|
2016-06-15 11:34:05 +02:00
|
|
|
subject.types_de_champ.zip(procedure.types_de_champ).each do |stc, ptc|
|
|
|
|
expect(stc).to have_same_attributes_as(ptc)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject.types_de_piece_justificative.zip(procedure.types_de_piece_justificative).each do |stc, ptc|
|
|
|
|
expect(stc).to have_same_attributes_as(ptc)
|
|
|
|
end
|
2016-09-01 10:43:49 +02:00
|
|
|
|
|
|
|
subject.mail_templates.zip(procedure.mail_templates).each do |stc, ptc|
|
|
|
|
expect(stc).to have_same_attributes_as(ptc)
|
|
|
|
end
|
2016-06-15 11:34:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not duplicate specific related objects' do
|
|
|
|
expect(subject.dossiers).to eq([])
|
|
|
|
expect(subject.gestionnaires).to eq([])
|
|
|
|
expect(subject.assign_to).to eq([])
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'procedure status is reset' do
|
|
|
|
let(:archived) { true }
|
|
|
|
let(:published) { true }
|
2016-06-24 16:41:44 +02:00
|
|
|
it 'Not published nor archived' do
|
2016-06-15 11:34:05 +02:00
|
|
|
expect(subject.archived).to be_falsey
|
|
|
|
expect(subject.published).to be_falsey
|
2016-06-24 16:41:44 +02:00
|
|
|
expect(subject.path).to be_nil
|
2016-06-15 11:34:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-24 16:41:44 +02:00
|
|
|
|
|
|
|
describe 'publish' do
|
|
|
|
let(:procedure) { create(:procedure, :published) }
|
|
|
|
let(:procedure_path) { ProcedurePath.find(procedure.procedure_path.id) }
|
|
|
|
|
|
|
|
it 'is available from a valid path' do
|
|
|
|
expect(procedure.path).to match(/fake_path/)
|
|
|
|
expect(procedure.published).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is correctly set in ProcedurePath table' do
|
2016-08-22 16:10:48 +02:00
|
|
|
expect(ProcedurePath.where(path: procedure.path).count).to eq(1)
|
2016-06-24 16:41:44 +02:00
|
|
|
expect(procedure_path.procedure_id).to eq(procedure.id)
|
|
|
|
expect(procedure_path.administrateur_id).to eq(procedure.administrateur_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'archive' do
|
|
|
|
let(:procedure) { create(:procedure, :published) }
|
|
|
|
let(:procedure_path) { ProcedurePath.find(procedure.procedure_path.id) }
|
|
|
|
before do
|
|
|
|
procedure.archive
|
|
|
|
procedure.reload
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not available from a valid path anymore' do
|
|
|
|
expect(procedure.path).to be_nil
|
|
|
|
expect(procedure.published).to be_truthy
|
|
|
|
expect(procedure.archived).to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not in ProcedurePath table anymore' do
|
2016-08-18 16:06:24 +02:00
|
|
|
expect(ProcedurePath.where(path: procedure.path).count).to eq(0)
|
2016-06-24 16:41:44 +02:00
|
|
|
expect(ProcedurePath.find_by_procedure_id(procedure.id)).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2016-07-22 15:06:30 +02:00
|
|
|
|
|
|
|
describe 'total_dossier' do
|
|
|
|
|
|
|
|
let(:procedure) { create :procedure }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create :dossier, procedure: procedure, state: :initiated
|
|
|
|
create :dossier, procedure: procedure, state: :draft
|
|
|
|
create :dossier, procedure: procedure, state: :replied
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { procedure.total_dossier }
|
|
|
|
|
|
|
|
it { is_expected.to eq 2 }
|
|
|
|
end
|
2015-09-21 17:59:03 +02:00
|
|
|
end
|