Merge pull request #613 from sgmap/fix_315_export_csv_with_champs_ordered
Fix 315 export csv with champs ordered
This commit is contained in:
commit
7414190d2a
8 changed files with 49 additions and 16 deletions
|
@ -51,7 +51,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_dossiers_tps
|
def download_dossiers_tps
|
||||||
procedure = Procedure.find_by(id: params[:procedure_id])
|
procedure = current_gestionnaire.procedures.find_by(id: params[:procedure_id])
|
||||||
export = procedure.generate_export
|
export = procedure.generate_export
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -242,8 +242,8 @@ class Dossier < ActiveRecord::Base
|
||||||
def data_with_champs
|
def data_with_champs
|
||||||
serialized_dossier = DossierTableExportSerializer.new(self)
|
serialized_dossier = DossierTableExportSerializer.new(self)
|
||||||
data = serialized_dossier.attributes.values
|
data = serialized_dossier.attributes.values
|
||||||
data += self.champs.order('type_de_champ_id ASC').map(&:value)
|
data += self.ordered_champs.map(&:value)
|
||||||
data += self.champs_private.order('type_de_champ_id ASC').map(&:value)
|
data += self.ordered_champs_private.map(&:value)
|
||||||
data += self.export_entreprise_data.values
|
data += self.export_entreprise_data.values
|
||||||
return data
|
return data
|
||||||
end
|
end
|
||||||
|
@ -251,8 +251,8 @@ class Dossier < ActiveRecord::Base
|
||||||
def export_headers
|
def export_headers
|
||||||
serialized_dossier = DossierTableExportSerializer.new(self)
|
serialized_dossier = DossierTableExportSerializer.new(self)
|
||||||
headers = serialized_dossier.attributes.keys
|
headers = serialized_dossier.attributes.keys
|
||||||
headers += self.procedure.types_de_champ.order('id ASC').map { |types_de_champ| types_de_champ.libelle.parameterize.underscore.to_sym }
|
headers += self.procedure.types_de_champ.order(:order_place).map { |types_de_champ| types_de_champ.libelle.parameterize.underscore.to_sym }
|
||||||
headers += self.procedure.types_de_champ_private.order('id ASC').map { |types_de_champ| types_de_champ.libelle.parameterize.underscore.to_sym }
|
headers += self.procedure.types_de_champ_private.order(:order_place).map { |types_de_champ| types_de_champ.libelle.parameterize.underscore.to_sym }
|
||||||
headers += self.export_entreprise_data.keys
|
headers += self.export_entreprise_data.keys
|
||||||
return headers
|
return headers
|
||||||
end
|
end
|
||||||
|
|
|
@ -227,8 +227,8 @@ describe API::V1::DossiersController do
|
||||||
subject { super()[:type_de_champ] }
|
subject { super()[:type_de_champ] }
|
||||||
|
|
||||||
it { expect(subject.keys.include?(:id)).to be_truthy }
|
it { expect(subject.keys.include?(:id)).to be_truthy }
|
||||||
it { expect(subject[:libelle]).to eq('Description') }
|
it { expect(subject[:libelle]).to include('Libelle du champ') }
|
||||||
it { expect(subject[:description]).to eq('description de votre projet') }
|
it { expect(subject[:description]).to include('description du champ') }
|
||||||
it { expect(subject.keys.include?(:order_place)).to be_truthy }
|
it { expect(subject.keys.include?(:order_place)).to be_truthy }
|
||||||
it { expect(subject[:type_champ]).to eq('text') }
|
it { expect(subject[:type_champ]).to eq('text') }
|
||||||
end
|
end
|
||||||
|
@ -260,8 +260,8 @@ describe API::V1::DossiersController do
|
||||||
subject { super()[:type_de_champ] }
|
subject { super()[:type_de_champ] }
|
||||||
|
|
||||||
it { expect(subject.keys.include?(:id)).to be_truthy }
|
it { expect(subject.keys.include?(:id)).to be_truthy }
|
||||||
it { expect(subject[:libelle]).to eq('Description') }
|
it { expect(subject[:libelle]).to include('Libelle champ privé') }
|
||||||
it { expect(subject[:description]).to eq('description de votre projet') }
|
it { expect(subject[:description]).to include('description du champ privé') }
|
||||||
it { expect(subject.keys.include?(:order_place)).to be_truthy }
|
it { expect(subject.keys.include?(:order_place)).to be_truthy }
|
||||||
it { expect(subject[:type_champ]).to eq('text') }
|
it { expect(subject[:type_champ]).to eq('text') }
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :type_de_champ_private do
|
factory :type_de_champ_private do
|
||||||
libelle 'Description'
|
sequence(:libelle) { |n| "Libelle champ privé #{n}" }
|
||||||
description 'description de votre projet'
|
sequence(:description) { |n| "description du champ privé #{n}" }
|
||||||
type_champ 'text'
|
type_champ 'text'
|
||||||
order_place 1
|
order_place 1
|
||||||
mandatory false
|
mandatory false
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :type_de_champ_public do
|
factory :type_de_champ_public do
|
||||||
libelle 'Description'
|
sequence(:libelle) { |n| "Libelle du champ #{n}" }
|
||||||
description 'description de votre projet'
|
sequence(:description) { |n| "description du champ #{n}" }
|
||||||
type_champ 'text'
|
type_champ 'text'
|
||||||
order_place 1
|
order_place 1
|
||||||
mandatory false
|
mandatory false
|
||||||
|
|
|
@ -463,7 +463,7 @@ describe Dossier do
|
||||||
describe '#export_headers' do
|
describe '#export_headers' do
|
||||||
subject { dossier.export_headers }
|
subject { dossier.export_headers }
|
||||||
|
|
||||||
it { expect(subject).to include(:description) }
|
it { expect(subject).to include(dossier.champs.first.libelle.parameterize.underscore.to_sym) }
|
||||||
it { expect(subject).to include(:individual_gender) }
|
it { expect(subject).to include(:individual_gender) }
|
||||||
it { expect(subject).to include(:individual_nom) }
|
it { expect(subject).to include(:individual_nom) }
|
||||||
it { expect(subject).to include(:individual_prenom) }
|
it { expect(subject).to include(:individual_prenom) }
|
||||||
|
|
|
@ -306,7 +306,7 @@ describe PreferenceListDossier do
|
||||||
describe 'first champs' do
|
describe 'first champs' do
|
||||||
subject { super()["type_de_champ_#{procedure.types_de_champ.first.id}"] }
|
subject { super()["type_de_champ_#{procedure.types_de_champ.first.id}"] }
|
||||||
|
|
||||||
it { expect(subject[:libelle]).to eq 'Description' }
|
it { expect(subject[:libelle]).to eq procedure.types_de_champ.first.libelle }
|
||||||
it { expect(subject[:table]).to eq 'champs' }
|
it { expect(subject[:table]).to eq 'champs' }
|
||||||
it { expect(subject[:attr]).to eq procedure.types_de_champ.first.id }
|
it { expect(subject[:attr]).to eq procedure.types_de_champ.first.id }
|
||||||
it { expect(subject[:attr_decorate]).to eq 'value' }
|
it { expect(subject[:attr_decorate]).to eq 'value' }
|
||||||
|
@ -324,7 +324,7 @@ describe PreferenceListDossier do
|
||||||
describe 'first champs' do
|
describe 'first champs' do
|
||||||
subject { super()["type_de_champ_private_#{procedure.types_de_champ_private.first.id}"] }
|
subject { super()["type_de_champ_private_#{procedure.types_de_champ_private.first.id}"] }
|
||||||
|
|
||||||
it { expect(subject[:libelle]).to eq 'Description' }
|
it { expect(subject[:libelle]).to eq procedure.types_de_champ_private.first.libelle }
|
||||||
it { expect(subject[:table]).to eq 'champs_private' }
|
it { expect(subject[:table]).to eq 'champs_private' }
|
||||||
it { expect(subject[:attr]).to eq procedure.types_de_champ_private.first.id }
|
it { expect(subject[:attr]).to eq procedure.types_de_champ_private.first.id }
|
||||||
it { expect(subject[:attr_decorate]).to eq 'value' }
|
it { expect(subject[:attr_decorate]).to eq 'value' }
|
||||||
|
|
|
@ -336,6 +336,39 @@ describe Procedure do
|
||||||
|
|
||||||
it { expect(subject[:data].size).to eq(2) }
|
it { expect(subject[:data].size).to eq(2) }
|
||||||
it { expect(subject[:headers]).to eq(dossier.export_headers) }
|
it { expect(subject[:headers]).to eq(dossier.export_headers) }
|
||||||
|
|
||||||
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when there is a draft dossier' do
|
context 'when there is a draft dossier' do
|
||||||
|
|
Loading…
Reference in a new issue