Merge commit '99248a75a02710899e7ee2ecbcb3b304620cb721' into develop

This commit is contained in:
Xavier J 2017-02-07 17:54:21 +01:00
commit 333ea9a610
3 changed files with 64 additions and 17 deletions

View file

@ -309,6 +309,10 @@ class Dossier < ActiveRecord::Base
end
end
def followers_gestionnaires_emails
follows.includes(:gestionnaire).map { |f| f.gestionnaire }.pluck(:email).join(' ')
end
def reset!
etablissement.destroy
entreprise.destroy

View file

@ -5,4 +5,6 @@ class DossierProcedureSerializer < ActiveModel::Serializer
:archived,
:mandataire_social,
:state
attribute :followers_gestionnaires_emails, key: :emails_accompagnateurs
end

View file

@ -681,9 +681,14 @@ describe Dossier do
end
end
describe '#export_headers' do
context 'when dossier is followed' do
let(:procedure) { create(:procedure, :with_type_de_champ) }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
let(:gestionnaire) { create(:gestionnaire) }
let(:follow) { create(:follow, gestionnaire: gestionnaire) }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure, follows: [follow]) }
describe '#export_headers' do
subject { dossier.export_headers }
it { expect(subject).to include(:description) }
@ -691,8 +696,6 @@ describe Dossier do
end
describe '#data_with_champs' do
let(:procedure) { create(:procedure, :with_type_de_champ) }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
subject { dossier.data_with_champs }
it { expect(subject[0]).to be_a_kind_of(Integer) }
@ -701,8 +704,10 @@ describe Dossier do
it { expect(subject[3]).to be_in([true, false]) }
it { expect(subject[4]).to be_in([true, false]) }
it { expect(subject[5]).to eq("draft") }
it { expect(subject[6]).to eq(dossier.followers_gestionnaires_emails) }
it { expect(subject.count).to eq(DossierProcedureSerializer.new(dossier).attributes.count + dossier.procedure.types_de_champ.count + dossier.export_entreprise_data.count) }
end
end
describe '#Dossier.to_csv' do
let!(:procedure) { create(:procedure) }
@ -746,6 +751,7 @@ describe Dossier do
it { expect(subject[:entreprise_prenom]).to be_nil }
end
describe '#Dossier.to_xlsx' do
let!(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
@ -930,4 +936,39 @@ describe Dossier do
it { is_expected.to be_falsey }
end
end
describe '#followers_gestionnaires_emails' do
context 'when there is no follower' do
let(:dossier) { create(:dossier, follows: []) }
subject { dossier.followers_gestionnaires_emails }
it { is_expected.to eq "" }
end
let(:gestionnaire) { create(:gestionnaire) }
let(:follow) { create(:follow, gestionnaire: gestionnaire) }
context 'when there is 1 follower' do
let(:dossier) { create(:dossier, follows: [follow]) }
subject { dossier.followers_gestionnaires_emails }
it { is_expected.to eq gestionnaire.email }
end
let(:gestionnaire2) { create :gestionnaire}
let(:follow2) { create(:follow, gestionnaire: gestionnaire2) }
context 'when there is 2 followers' do
let(:dossier) { create(:dossier, follows: [follow, follow2]) }
subject { dossier.followers_gestionnaires_emails }
it { is_expected.to eq "#{gestionnaire.email} #{gestionnaire2.email}" }
end
end
end