Add groupe_instructeur_label to export v1
This commit is contained in:
parent
3bc20bdb06
commit
f577484aa2
2 changed files with 33 additions and 5 deletions
|
@ -51,6 +51,13 @@ class ProcedureExportService
|
|||
|
||||
def initialize(procedure, dossiers, tables: [], ids: nil, since: nil, limit: nil)
|
||||
@procedure = procedure
|
||||
|
||||
@attributes = ATTRIBUTES.dup
|
||||
|
||||
if procedure.routee?
|
||||
@attributes << :groupe_instructeur_label
|
||||
end
|
||||
|
||||
@dossiers = dossiers.downloadable_sorted
|
||||
if ids
|
||||
@dossiers = @dossiers.where(id: ids)
|
||||
|
@ -137,7 +144,7 @@ class ProcedureExportService
|
|||
end
|
||||
|
||||
def dossiers_headers
|
||||
headers = ATTRIBUTES.map(&:to_s) +
|
||||
headers = @attributes.map(&:to_s) +
|
||||
@procedure.types_de_champ.reject(&:exclude_from_export?).map(&:libelle) +
|
||||
@procedure.types_de_champ_private.reject(&:exclude_from_export?).map(&:libelle) +
|
||||
ETABLISSEMENT_ATTRIBUTES.map { |key| "etablissement.#{key}" } +
|
||||
|
@ -148,7 +155,7 @@ class ProcedureExportService
|
|||
|
||||
def dossiers_data
|
||||
@dossiers.map do |dossier|
|
||||
values = ATTRIBUTES.map do |key|
|
||||
values = @attributes.map do |key|
|
||||
case key
|
||||
when :email
|
||||
dossier.user.email
|
||||
|
@ -168,6 +175,8 @@ class ProcedureExportService
|
|||
dossier.individual&.gender
|
||||
when :emails_instructeurs
|
||||
dossier.followers_instructeurs.map(&:email).join(' ')
|
||||
when :groupe_instructeur_label
|
||||
dossier.groupe_instructeur.label
|
||||
else
|
||||
dossier.read_attribute(key)
|
||||
end
|
||||
|
|
|
@ -19,8 +19,8 @@ describe ProcedureExportService do
|
|||
end
|
||||
|
||||
context 'dossiers' do
|
||||
it 'should have headers' do
|
||||
expect(headers).to eq([
|
||||
let(:nominal_header) do
|
||||
[
|
||||
:id,
|
||||
:created_at,
|
||||
:updated_at,
|
||||
|
@ -86,7 +86,19 @@ describe ProcedureExportService do
|
|||
:entreprise_date_creation,
|
||||
:entreprise_nom,
|
||||
:entreprise_prenom
|
||||
])
|
||||
]
|
||||
end
|
||||
|
||||
it 'should have headers' do
|
||||
expect(headers).to eq(nominal_header)
|
||||
end
|
||||
|
||||
context 'with a procedure routee' do
|
||||
before { procedure.groupe_instructeurs.create(label: '2') }
|
||||
|
||||
let(:routee_header) { nominal_header.insert(nominal_header.index(:textarea), :groupe_instructeur_label) }
|
||||
|
||||
it { expect(headers).to eq(routee_header) }
|
||||
end
|
||||
|
||||
it 'should have empty values' do
|
||||
|
@ -139,6 +151,13 @@ describe ProcedureExportService do
|
|||
])
|
||||
end
|
||||
|
||||
context 'with a procedure routee' do
|
||||
before { procedure.groupe_instructeurs.create(label: '2') }
|
||||
|
||||
it { expect(data.first[15]).to eq('défaut') }
|
||||
it { expect(data.first.count).to eq(dossier_data.count + champs_data.count + etablissement_data.count + 1) }
|
||||
end
|
||||
|
||||
context 'and etablissement' do
|
||||
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_entreprise, procedure: procedure) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue