Merge pull request #1027 from sgmap/fix_#992_dossier_order_in_excel

[fix #992] export: dossiers are order by initiated_at
This commit is contained in:
LeSim 2017-12-01 13:50:12 +01:00 committed by GitHub
commit 57328eadaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 11 deletions

View file

@ -58,7 +58,7 @@ class Dossier < ActiveRecord::Base
scope :nouveaux, -> { not_archived.state_nouveaux } scope :nouveaux, -> { not_archived.state_nouveaux }
scope :en_instruction, -> { not_archived.state_en_instruction } scope :en_instruction, -> { not_archived.state_en_instruction }
scope :termine, -> { not_archived.state_termine } scope :termine, -> { not_archived.state_termine }
scope :downloadable, -> { state_not_brouillon.includes(:entreprise, :etablissement, :champs, :champs_private) } scope :downloadable_sorted, -> { state_not_brouillon.includes(:entreprise, :etablissement, :champs, :champs_private).order(initiated_at: 'asc') }
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction } scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) } scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
scope :with_unread_notifications, -> { where(notifications: { already_read: false }) } scope :with_unread_notifications, -> { where(notifications: { already_read: false }) }

View file

@ -151,7 +151,7 @@ class Procedure < ActiveRecord::Base
end end
def generate_export def generate_export
exportable_dossiers = dossiers.downloadable exportable_dossiers = dossiers.downloadable_sorted
headers = exportable_dossiers.any? ? exportable_dossiers.first.export_headers : [] headers = exportable_dossiers.any? ? exportable_dossiers.first.export_headers : []
data = exportable_dossiers.any? ? exportable_dossiers.map { |d| d.full_data_strings_array } : [[]] data = exportable_dossiers.any? ? exportable_dossiers.map { |d| d.full_data_strings_array } : [[]]

View file

@ -758,19 +758,16 @@ describe Dossier do
end end
end end
describe '.downloadable' do describe '.downloadable_sorted' do
let(:procedure) { create(:procedure) } let(:procedure) { create(:procedure) }
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: :draft) } let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: :draft) }
let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: :initiated) } let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: :initiated, initiated_at: DateTime.parse('03/01/2010')) }
let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: :received) } let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: :received, initiated_at: DateTime.parse('01/01/2010')) }
let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: :received, archived: true) } let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: :received, archived: true, initiated_at: DateTime.parse('02/01/2010')) }
subject { procedure.dossiers.downloadable } subject { procedure.dossiers.downloadable_sorted }
it { is_expected.not_to include(dossier)} it { is_expected.to match([dossier3, dossier4, dossier2])}
it { is_expected.to include(dossier2)}
it { is_expected.to include(dossier3)}
it { is_expected.to include(dossier4)}
end end
describe "#send_dossier_received" do describe "#send_dossier_received" do