Merge pull request #1655 from betagouv/fix-1654

[Fix #1654] Generate procedure export filename with libelle
This commit is contained in:
gregoirenovel 2018-03-19 11:29:18 +01:00 committed by GitHub
commit 452a8808ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View file

@ -175,7 +175,7 @@ module NewGestionnaire
def download_dossiers
export = procedure.generate_export
filename = "dossiers_#{procedure.procedure_path.path}_#{Time.now.strftime('%Y-%m-%d_%H-%M')}"
filename = procedure.export_filename
respond_to do |format|
format.csv { send_data(SpreadsheetArchitect.to_csv(data: export[:data], headers: export[:headers]), filename: "#{filename}.csv") }

View file

@ -157,6 +157,11 @@ class Procedure < ApplicationRecord
self.dossiers.state_not_brouillon.size
end
def export_filename
procedure_identifier = procedure_path&.path || "procedure-#{id}"
"dossiers_#{procedure_identifier}_#{Time.now.strftime('%Y-%m-%d_%H-%M')}"
end
def generate_export
exportable_dossiers = dossiers.downloadable_sorted

View file

@ -494,4 +494,22 @@ describe Procedure do
describe ".default_sort" do
it { expect(Procedure.default_sort).to eq("{\"table\":\"self\",\"column\":\"id\",\"order\":\"desc\"}") }
end
describe ".export_filename" do
before { Timecop.freeze(Time.new(2018, 1, 2, 23, 11, 14)) }
subject { procedure.export_filename }
context "with a path" do
let(:procedure) { create(:procedure, :published) }
it { is_expected.to eq("dossiers_#{procedure.procedure_path.path}_2018-01-02_23-11") }
end
context "without a path" do
let(:procedure) { create(:procedure) }
it { is_expected.to eq("dossiers_procedure-#{procedure.id}_2018-01-02_23-11") }
end
end
end