2015-09-21 17:59:03 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Procedure do
|
2017-05-29 14:44:38 +02:00
|
|
|
describe 'mail templates' do
|
2017-05-27 01:08:01 +02:00
|
|
|
subject { create(:procedure) }
|
|
|
|
|
|
|
|
it { expect(subject.initiated_mail_template).to be_a(Mails::InitiatedMail) }
|
|
|
|
it { expect(subject.received_mail_template).to be_a(Mails::ReceivedMail) }
|
|
|
|
it { expect(subject.closed_mail_template).to be_a(Mails::ClosedMail) }
|
|
|
|
it { expect(subject.refused_mail_template).to be_a(Mails::RefusedMail) }
|
|
|
|
it { expect(subject.without_continuation_mail_template).to be_a(Mails::WithoutContinuationMail) }
|
2017-03-06 15:00:05 +01:00
|
|
|
end
|
|
|
|
|
2017-03-04 09:56:09 +01:00
|
|
|
describe 'initiated_mail' do
|
|
|
|
subject { create(:procedure) }
|
|
|
|
|
|
|
|
context 'when initiated_mail is not customize' do
|
2017-05-27 01:08:01 +02:00
|
|
|
it { expect(subject.initiated_mail_template.body).to eq(Mails::InitiatedMail.default.body) }
|
2017-03-04 09:56:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when initiated_mail is customize' do
|
|
|
|
before :each do
|
2017-03-06 22:37:37 +01:00
|
|
|
subject.initiated_mail = Mails::InitiatedMail.new(body: 'sisi')
|
2017-03-04 09:56:09 +01:00
|
|
|
subject.save
|
|
|
|
subject.reload
|
|
|
|
end
|
2017-05-27 01:08:01 +02:00
|
|
|
it { expect(subject.initiated_mail_template.body).to eq('sisi') }
|
2017-03-04 09:56:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when initiated_mail is customize ... again' do
|
|
|
|
before :each do
|
2017-03-06 22:37:37 +01:00
|
|
|
subject.initiated_mail = Mails::InitiatedMail.new(body: 'toto')
|
2017-03-04 09:56:09 +01:00
|
|
|
subject.save
|
|
|
|
subject.reload
|
|
|
|
end
|
2017-05-27 01:08:01 +02:00
|
|
|
it { expect(subject.initiated_mail_template.body).to eq('toto') }
|
2017-03-04 09:56:09 +01:00
|
|
|
|
2017-03-06 22:37:37 +01:00
|
|
|
it { expect(Mails::InitiatedMail.count).to eq(1) }
|
2017-03-04 09:56:09 +01:00
|
|
|
end
|
|
|
|
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
|
2017-11-23 11:37:41 +01:00
|
|
|
|
|
|
|
context 'organisation' do
|
|
|
|
it { is_expected.not_to allow_value(nil).for(:organisation) }
|
|
|
|
it { is_expected.not_to allow_value('').for(:organisation) }
|
|
|
|
it { is_expected.to allow_value('URRSAF').for(:organisation) }
|
|
|
|
end
|
2015-09-22 11:21:52 +02:00
|
|
|
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
|
2017-07-11 14:21:10 +02:00
|
|
|
let(:procedure) { create(:procedure, published_at: published_at) }
|
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
|
2017-07-11 14:21:10 +02:00
|
|
|
let(:published_at) { nil }
|
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
|
2017-07-11 14:21:10 +02:00
|
|
|
let(:published_at) { Time.now }
|
2016-06-09 17:49:38 +02:00
|
|
|
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
|
2017-07-10 23:42:33 +02:00
|
|
|
let(:procedure) { create(:procedure, published_at: published_at, archived_at: archived_at) }
|
2016-06-09 17:49:38 +02:00
|
|
|
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
|
2017-07-11 14:21:10 +02:00
|
|
|
let(:published_at) { nil }
|
2017-07-10 23:42:33 +02:00
|
|
|
let(:archived_at) { nil }
|
2016-06-09 17:49:38 +02:00
|
|
|
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure is published and not archived' do
|
2017-07-11 14:21:10 +02:00
|
|
|
let(:published_at) { Time.now }
|
2017-07-10 23:42:33 +02:00
|
|
|
let(:archived_at) { nil }
|
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
|
2017-07-11 14:21:10 +02:00
|
|
|
let(:published_at) { Time.now }
|
2017-07-10 23:42:33 +02:00
|
|
|
let(:archived_at) { Time.now }
|
2016-06-09 17:49:38 +02:00
|
|
|
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure is in draft status and archived' do
|
2017-07-11 14:21:10 +02:00
|
|
|
let(:published_at) { nil }
|
2017-07-10 23:42:33 +02:00
|
|
|
let(:archived_at) { Time.now }
|
2016-06-09 17:49:38 +02:00
|
|
|
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
|
2017-07-10 23:42:33 +02:00
|
|
|
let(:archived_at) { nil }
|
2017-07-11 14:21:10 +02:00
|
|
|
let(:published_at) { nil }
|
2017-07-10 23:42:33 +02:00
|
|
|
let(:procedure) { create(:procedure, archived_at: archived_at, published_at: published_at, received_mail: received_mail) }
|
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) }
|
2017-06-26 17:18:47 +02:00
|
|
|
let!(:type_de_champ_2) { create(:type_de_champ_public, :type_drop_down_list, procedure: procedure, order_place: 2) }
|
2016-09-09 17:39:56 +02:00
|
|
|
let!(:type_de_champ_private_0) { create(:type_de_champ_private, procedure: procedure, order_place: 0) }
|
|
|
|
let!(:type_de_champ_private_1) { create(:type_de_champ_private, procedure: procedure, order_place: 1) }
|
2017-06-26 17:18:47 +02:00
|
|
|
let!(:type_de_champ_private_2) { create(:type_de_champ_private, :type_drop_down_list, procedure: procedure, order_place: 2) }
|
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) }
|
2017-03-07 18:19:48 +01:00
|
|
|
let(:received_mail){ create(:received_mail) }
|
2016-09-01 10:43:49 +02:00
|
|
|
|
2017-06-08 14:16:48 +02:00
|
|
|
before do
|
|
|
|
@logo = File.open('spec/fixtures/white.png')
|
|
|
|
@signature = File.open('spec/fixtures/black.png')
|
|
|
|
@attestation_template = create(:attestation_template, procedure: procedure, logo: @logo, signature: @signature)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
@logo.close
|
|
|
|
@signature.close
|
|
|
|
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-09 17:39:56 +02:00
|
|
|
expect(subject.types_de_piece_justificative.size).to eq procedure.types_de_piece_justificative.size
|
|
|
|
expect(subject.types_de_champ.size).to eq procedure.types_de_champ.size
|
|
|
|
expect(subject.types_de_champ_private.size).to eq procedure.types_de_champ_private.size
|
2017-06-26 17:18:47 +02:00
|
|
|
expect(subject.types_de_champ.map(&:drop_down_list).compact.size).to eq procedure.types_de_champ.map(&:drop_down_list).compact.size
|
|
|
|
expect(subject.types_de_champ_private.map(&:drop_down_list).compact.size).to eq procedure.types_de_champ_private.map(&:drop_down_list).compact.size
|
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
|
|
|
|
|
2016-09-09 17:39:56 +02:00
|
|
|
subject.types_de_champ_private.zip(procedure.types_de_champ_private).each do |stc, ptc|
|
|
|
|
expect(stc).to have_same_attributes_as(ptc)
|
|
|
|
end
|
|
|
|
|
2016-06-15 11:34:05 +02:00
|
|
|
subject.types_de_piece_justificative.zip(procedure.types_de_piece_justificative).each do |stc, ptc|
|
|
|
|
expect(stc).to have_same_attributes_as(ptc)
|
|
|
|
end
|
2017-06-08 14:16:48 +02:00
|
|
|
|
|
|
|
expect(subject.attestation_template.title).to eq(procedure.attestation_template.title)
|
2017-03-07 18:19:48 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'should duplicate existing mail_templates' do
|
|
|
|
expect(subject.received_mail.attributes.except("id", "procedure_id", "created_at", "updated_at")).to eq procedure.received_mail.attributes.except("id", "procedure_id", "created_at", "updated_at")
|
|
|
|
expect(subject.received_mail.id).not_to eq procedure.received_mail.id
|
|
|
|
expect(subject.received_mail.id).not_to be nil
|
|
|
|
expect(subject.received_mail.procedure_id).not_to eq procedure.received_mail.procedure_id
|
|
|
|
expect(subject.received_mail.procedure_id).not_to be nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not duplicate default mail_template' do
|
2017-05-27 01:08:01 +02:00
|
|
|
expect(subject.initiated_mail_template.attributes).to eq Mails::InitiatedMail.default.attributes
|
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
|
2017-07-10 23:42:33 +02:00
|
|
|
let(:archived_at) { Time.now }
|
2017-07-11 14:21:10 +02:00
|
|
|
let(:published_at) { Time.now }
|
2016-06-24 16:41:44 +02:00
|
|
|
it 'Not published nor archived' do
|
2017-07-10 23:42:33 +02:00
|
|
|
expect(subject.archived_at).to be_nil
|
2017-07-11 14:21:10 +02:00
|
|
|
expect(subject.published_at).to be_nil
|
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
|
|
|
|
2017-06-27 13:48:27 +02:00
|
|
|
describe '#publish!' do
|
|
|
|
let(:procedure) { create(:procedure) }
|
2017-07-04 15:36:35 +02:00
|
|
|
let(:now) { Time.now.beginning_of_minute }
|
2017-06-27 13:48:27 +02:00
|
|
|
|
|
|
|
before do
|
2017-07-04 15:36:35 +02:00
|
|
|
Timecop.freeze(now)
|
2017-06-27 17:05:49 +02:00
|
|
|
procedure.publish!("example-path")
|
2017-06-27 13:48:27 +02:00
|
|
|
end
|
2017-11-29 16:07:39 +01:00
|
|
|
after { Timecop.return }
|
2017-06-27 13:48:27 +02:00
|
|
|
|
2017-07-10 23:42:33 +02:00
|
|
|
it { expect(procedure.archived_at).to eq(nil) }
|
2017-07-04 15:36:35 +02:00
|
|
|
it { expect(procedure.published_at).to eq(now) }
|
2017-06-27 13:48:27 +02:00
|
|
|
it { expect(ProcedurePath.find_by_path("example-path")).to be }
|
|
|
|
it { expect(ProcedurePath.find_by_path("example-path").procedure).to eq(procedure) }
|
|
|
|
it { expect(ProcedurePath.find_by_path("example-path").administrateur).to eq(procedure.administrateur) }
|
|
|
|
end
|
|
|
|
|
2017-07-13 15:21:52 +02:00
|
|
|
describe "#brouillon?" do
|
|
|
|
let(:procedure_brouillon) { Procedure.new() }
|
|
|
|
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
|
|
|
|
let(:procedure_archivee) { Procedure.new(published_at: Time.now, archived_at: Time.now) }
|
|
|
|
|
|
|
|
it { expect(procedure_brouillon.brouillon?).to be_truthy }
|
|
|
|
it { expect(procedure_publiee.brouillon?).to be_falsey }
|
|
|
|
it { expect(procedure_archivee.brouillon?).to be_falsey }
|
|
|
|
end
|
|
|
|
|
2017-07-13 15:14:28 +02:00
|
|
|
describe "#publiee?" do
|
|
|
|
let(:procedure_brouillon) { Procedure.new() }
|
|
|
|
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
|
|
|
|
let(:procedure_archivee) { Procedure.new(published_at: Time.now, archived_at: Time.now) }
|
|
|
|
|
|
|
|
it { expect(procedure_brouillon.publiee?).to be_falsey }
|
|
|
|
it { expect(procedure_publiee.publiee?).to be_truthy }
|
|
|
|
it { expect(procedure_archivee.publiee?).to be_falsey }
|
|
|
|
end
|
|
|
|
|
2017-07-13 15:09:25 +02:00
|
|
|
describe "#archivee?" do
|
|
|
|
let(:procedure_brouillon) { Procedure.new() }
|
|
|
|
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
|
|
|
|
let(:procedure_archivee) { Procedure.new(published_at: Time.now, archived_at: Time.now) }
|
2017-07-13 15:20:24 +02:00
|
|
|
let(:procedure_batarde) { Procedure.new(published_at: nil, archived_at: Time.now) }
|
2017-07-13 15:09:25 +02:00
|
|
|
|
|
|
|
it { expect(procedure_brouillon.archivee?).to be_falsey }
|
|
|
|
it { expect(procedure_publiee.archivee?).to be_falsey }
|
|
|
|
it { expect(procedure_archivee.archivee?).to be_truthy }
|
2017-07-13 15:20:24 +02:00
|
|
|
it { expect(procedure_batarde.archivee?).to be_falsey }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#publiee_ou_archivee?" do
|
|
|
|
let(:procedure_brouillon) { Procedure.new() }
|
|
|
|
let(:procedure_publiee) { Procedure.new(published_at: Time.now) }
|
|
|
|
let(:procedure_archivee) { Procedure.new(published_at: Time.now, archived_at: Time.now) }
|
|
|
|
|
|
|
|
it { expect(procedure_brouillon.publiee_ou_archivee?).to be_falsey }
|
|
|
|
it { expect(procedure_publiee.publiee_ou_archivee?).to be_truthy }
|
|
|
|
it { expect(procedure_archivee.publiee_ou_archivee?).to be_truthy }
|
2017-07-13 15:09:25 +02:00
|
|
|
end
|
|
|
|
|
2016-06-24 16:41:44 +02:00
|
|
|
describe 'archive' do
|
|
|
|
let(:procedure) { create(:procedure, :published) }
|
|
|
|
let(:procedure_path) { ProcedurePath.find(procedure.procedure_path.id) }
|
2017-07-04 15:36:35 +02:00
|
|
|
let(:now) { Time.now.beginning_of_minute }
|
2016-06-24 16:41:44 +02:00
|
|
|
before do
|
2017-07-04 15:36:35 +02:00
|
|
|
Timecop.freeze(now)
|
2016-06-24 16:41:44 +02:00
|
|
|
procedure.archive
|
|
|
|
procedure.reload
|
|
|
|
end
|
2017-11-29 16:07:39 +01:00
|
|
|
after { Timecop.return }
|
2016-06-24 16:41:44 +02:00
|
|
|
|
2017-07-13 15:09:25 +02:00
|
|
|
it { expect(procedure.archivee?).to be_truthy }
|
2017-07-04 15:36:35 +02:00
|
|
|
it { expect(procedure.archived_at).to eq(now) }
|
2016-06-24 16:41:44 +02:00
|
|
|
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
|
2017-09-21 17:12:21 +02:00
|
|
|
create :dossier, procedure: procedure, state: :initiated
|
2016-07-22 15:06:30 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { procedure.total_dossier }
|
|
|
|
|
|
|
|
it { is_expected.to eq 2 }
|
|
|
|
end
|
2017-04-05 11:34:16 +02:00
|
|
|
|
|
|
|
describe '#generate_export' do
|
|
|
|
let(:procedure) { create :procedure }
|
|
|
|
subject { procedure.generate_export }
|
|
|
|
|
2017-04-12 17:59:12 +02:00
|
|
|
shared_examples "export is empty" do
|
|
|
|
it { expect(subject[:data]).to eq([[]]) }
|
2017-04-05 11:34:16 +02:00
|
|
|
it { expect(subject[:headers]).to eq([]) }
|
|
|
|
end
|
|
|
|
|
2017-04-12 17:59:12 +02:00
|
|
|
context 'when there are no dossiers' do
|
|
|
|
it_behaves_like "export is empty"
|
|
|
|
end
|
|
|
|
|
2017-04-05 11:34:16 +02:00
|
|
|
context 'when there are some dossiers' do
|
|
|
|
let!(:dossier){ create(:dossier, procedure: procedure, state: 'initiated') }
|
|
|
|
let!(:dossier2){ create(:dossier, procedure: procedure, state: 'closed') }
|
|
|
|
|
|
|
|
it { expect(subject[:data].size).to eq(2) }
|
|
|
|
it { expect(subject[:headers]).to eq(dossier.export_headers) }
|
2017-07-19 15:40:26 +02:00
|
|
|
|
|
|
|
context 'with ordered champs' do
|
|
|
|
let(:tc_2) { create(:type_de_champ_public, order_place: 2) }
|
|
|
|
let(:tc_1) { create(:type_de_champ_public, order_place: 1) }
|
|
|
|
let(:tcp_2) { create(:type_de_champ_private, order_place: 2) }
|
|
|
|
let(:tcp_1) { create(:type_de_champ_private, order_place: 1) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
procedure.types_de_champ << tc_2 << tc_1
|
|
|
|
procedure.types_de_champ_private << tcp_2 << tcp_1
|
|
|
|
|
|
|
|
dossier.build_default_champs
|
|
|
|
dossier.champs.find_by(type_de_champ: tc_1).update_attributes(value: "value 1")
|
|
|
|
dossier.champs.find_by(type_de_champ: tc_2).update_attributes(value: "value 2")
|
|
|
|
dossier.champs_private.find_by(type_de_champ: tcp_1).update_attributes(value: "private value 1")
|
|
|
|
dossier.champs_private.find_by(type_de_champ: tcp_2).update_attributes(value: "private value 2")
|
|
|
|
|
|
|
|
dossier2.build_default_champs
|
|
|
|
dossier2.champs.find_by(type_de_champ: tc_1).update_attributes(value: "value 1")
|
|
|
|
dossier2.champs.find_by(type_de_champ: tc_2).update_attributes(value: "value 2")
|
|
|
|
dossier2.champs_private.find_by(type_de_champ: tcp_1).update_attributes(value: "private value 1")
|
|
|
|
dossier2.champs_private.find_by(type_de_champ: tcp_2).update_attributes(value: "private value 2")
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject[:headers].index(tc_1.libelle.parameterize.underscore.to_sym)).to be < subject[:headers].index(tc_2.libelle.parameterize.underscore.to_sym) }
|
|
|
|
it { expect(subject[:headers].index(tcp_1.libelle.parameterize.underscore.to_sym)).to be < subject[:headers].index(tcp_2.libelle.parameterize.underscore.to_sym) }
|
|
|
|
|
|
|
|
it { expect(subject[:data][0].index("value 1")).to be < subject[:data].first.index("value 2") }
|
|
|
|
it { expect(subject[:data][0].index("private value 1")).to be < subject[:data].first.index("private value 2") }
|
|
|
|
|
|
|
|
it { expect(subject[:data][1].index("value 1")).to be < subject[:data].first.index("value 2") }
|
|
|
|
it { expect(subject[:data][1].index("private value 1")).to be < subject[:data].first.index("private value 2") }
|
|
|
|
end
|
2017-04-05 11:34:16 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when there is a draft dossier' do
|
|
|
|
let!(:dossier_not_exportable){ create(:dossier, procedure: procedure, state: 'draft') }
|
|
|
|
|
2017-04-12 17:59:12 +02:00
|
|
|
it_behaves_like "export is empty"
|
2017-04-05 11:34:16 +02:00
|
|
|
end
|
|
|
|
end
|
2017-04-14 11:34:53 +02:00
|
|
|
|
|
|
|
describe '#default_path' do
|
|
|
|
let(:procedure){ create(:procedure, libelle: 'A long libelle with àccênts, blabla coucou hello un deux trois voila') }
|
|
|
|
|
|
|
|
subject { procedure.default_path }
|
|
|
|
|
|
|
|
it { is_expected.to eq('a-long-libelle-with-accents-blabla-coucou-hello-un') }
|
|
|
|
end
|
2017-06-27 14:22:43 +02:00
|
|
|
|
|
|
|
describe ".default_scope" do
|
|
|
|
let!(:procedure) { create(:procedure, hidden_at: hidden_at) }
|
|
|
|
|
|
|
|
context "when hidden_at is nil" do
|
|
|
|
let(:hidden_at) { nil }
|
|
|
|
|
|
|
|
it { expect(Procedure.count).to eq(1) }
|
|
|
|
it { expect(Procedure.all).to include(procedure) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when hidden_at is not nil" do
|
|
|
|
let(:hidden_at) { 2.days.ago }
|
|
|
|
|
|
|
|
it { expect(Procedure.count).to eq(0) }
|
|
|
|
it { expect { Procedure.find(procedure.id) }.to raise_error(ActiveRecord::RecordNotFound) }
|
|
|
|
end
|
|
|
|
end
|
2017-06-27 15:26:40 +02:00
|
|
|
|
|
|
|
describe "#hide!" do
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
let!(:dossier) { create(:dossier, procedure: procedure) }
|
|
|
|
let!(:dossier2) { create(:dossier, procedure: procedure) }
|
2017-09-25 18:36:14 +02:00
|
|
|
let(:gestionnaire) { create(:gestionnaire) }
|
2017-06-27 15:26:40 +02:00
|
|
|
|
|
|
|
it { expect(Dossier.count).to eq(2) }
|
|
|
|
it { expect(Dossier.all).to include(dossier, dossier2) }
|
|
|
|
|
|
|
|
context "when hidding procedure" do
|
|
|
|
before do
|
2017-09-25 18:36:14 +02:00
|
|
|
gestionnaire.followed_dossiers << dossier
|
2017-06-27 15:26:40 +02:00
|
|
|
procedure.hide!
|
2017-09-25 18:36:14 +02:00
|
|
|
gestionnaire.reload
|
2017-06-27 15:26:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure.dossiers.count).to eq(0) }
|
|
|
|
it { expect(Dossier.count).to eq(0) }
|
2017-09-25 18:36:14 +02:00
|
|
|
it { expect(gestionnaire.followed_dossiers).not_to include(dossier) }
|
2017-06-27 15:26:40 +02:00
|
|
|
end
|
|
|
|
end
|
2017-10-02 17:03:38 +02:00
|
|
|
|
|
|
|
describe "#fields" do
|
2017-10-03 15:08:51 +02:00
|
|
|
subject { create(:procedure, :with_type_de_champ, :with_type_de_champ_private, :types_de_champ_count => 4, :types_de_champ_private_count => 4) }
|
|
|
|
let(:tdc_1) { subject.types_de_champ[0] }
|
|
|
|
let(:tdc_2) { subject.types_de_champ[1] }
|
|
|
|
let(:tdc_private_1) { subject.types_de_champ_private[0] }
|
|
|
|
let(:tdc_private_2) { subject.types_de_champ_private[1] }
|
2017-10-02 17:03:38 +02:00
|
|
|
let(:expected) {
|
|
|
|
[
|
|
|
|
{ "label" => 'Créé le', "table" => 'self', "column" => 'created_at' },
|
|
|
|
{ "label" => 'Mis à jour le', "table" => 'self', "column" => 'updated_at' },
|
|
|
|
{ "label" => 'Demandeur', "table" => 'user', "column" => 'email' },
|
|
|
|
{ "label" => 'Civilité (FC)', "table" => 'france_connect_information', "column" => 'gender' },
|
|
|
|
{ "label" => 'Prénom (FC)', "table" => 'france_connect_information', "column" => 'given_name' },
|
|
|
|
{ "label" => 'Nom (FC)', "table" => 'france_connect_information', "column" => 'family_name' },
|
|
|
|
{ "label" => 'SIREN', "table" => 'entreprise', "column" => 'siren' },
|
|
|
|
{ "label" => 'Forme juridique', "table" => 'entreprise', "column" => 'forme_juridique' },
|
|
|
|
{ "label" => 'Nom commercial', "table" => 'entreprise', "column" => 'nom_commercial' },
|
|
|
|
{ "label" => 'Raison sociale', "table" => 'entreprise', "column" => 'raison_sociale' },
|
|
|
|
{ "label" => 'SIRET siège social', "table" => 'entreprise', "column" => 'siret_siege_social' },
|
|
|
|
{ "label" => 'Date de création', "table" => 'entreprise', "column" => 'date_creation' },
|
|
|
|
{ "label" => 'SIRET', "table" => 'etablissement', "column" => 'siret' },
|
|
|
|
{ "label" => 'Nom établissement', "table" => 'etablissement', "column" => 'libelle_naf' },
|
|
|
|
{ "label" => 'Code postal', "table" => 'etablissement', "column" => 'code_postal' },
|
|
|
|
{ "label" => tdc_1.libelle, "table" => 'type_de_champ', "column" => tdc_1.id.to_s },
|
|
|
|
{ "label" => tdc_2.libelle, "table" => 'type_de_champ', "column" => tdc_2.id.to_s },
|
|
|
|
{ "label" => tdc_private_1.libelle, "table" => 'type_de_champ_private', "column" => tdc_private_1.id.to_s },
|
|
|
|
{ "label" => tdc_private_2.libelle, "table" => 'type_de_champ_private', "column" => tdc_private_2.id.to_s }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
2017-10-03 15:08:51 +02:00
|
|
|
before do
|
|
|
|
subject.types_de_champ[2].update_attribute(:type_champ, 'header_section')
|
|
|
|
subject.types_de_champ[3].update_attribute(:type_champ, 'explication')
|
|
|
|
subject.types_de_champ_private[2].update_attribute(:type_champ, 'header_section')
|
|
|
|
subject.types_de_champ_private[3].update_attribute(:type_champ, 'explication')
|
|
|
|
end
|
|
|
|
|
2017-10-02 17:03:38 +02:00
|
|
|
it { expect(subject.fields).to eq(expected) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#fields_for_select" do
|
|
|
|
subject { create(:procedure) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(subject).to receive(:fields).and_return([{
|
|
|
|
"label" => "label1",
|
|
|
|
"table" => "table1",
|
|
|
|
"column" => "column1"
|
|
|
|
}, {
|
|
|
|
"label" => "label2",
|
|
|
|
"table" => "table2",
|
|
|
|
"column" => "column2"
|
|
|
|
}])
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.fields_for_select).to eq([["label1", "table1/column1"], ["label2", "table2/column2"]]) }
|
|
|
|
end
|
2017-09-27 15:16:07 +02:00
|
|
|
|
|
|
|
describe ".default_sort" do
|
|
|
|
it { expect(Procedure.default_sort).to eq("{\"table\":\"self\",\"column\":\"id\",\"order\":\"desc\"}") }
|
|
|
|
end
|
2015-09-21 17:59:03 +02:00
|
|
|
end
|