From f2fe06e86f47725ec9b01dfe8692b9d7c3f8e11d Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:09:19 +0200 Subject: [PATCH 1/4] Add the not_brouillon scope on Dossier --- app/models/dossier.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 71506ee9c..b38b261ca 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -54,7 +54,6 @@ class Dossier < ActiveRecord::Base EN_INSTRUCTION = %w(received) A_INSTRUIRE = %w(received) TERMINE = %w(closed refused without_continuation) - ALL_STATE = %w(initiated updated replied received closed refused without_continuation) def unreaded_notifications @unreaded_notif ||= notifications.where(already_read: false) @@ -160,7 +159,7 @@ class Dossier < ActiveRecord::Base end def self.all_state order = 'ASC' - where(state: ALL_STATE, archived: false).order("updated_at #{order}") + not_brouillon.where(archived: false).order("updated_at #{order}") end def brouillon? @@ -168,6 +167,7 @@ class Dossier < ActiveRecord::Base end scope :brouillon, -> { where(state: BROUILLON) } + scope :not_brouillon, -> { where.not(state: BROUILLON) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } From 7eed44d4302f6fab559bf59045f715c2b7353745 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:10:38 +0200 Subject: [PATCH 2/4] Use the not_archived scope in Dossier --- app/models/dossier.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index b38b261ca..a919aec27 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -159,7 +159,7 @@ class Dossier < ActiveRecord::Base end def self.all_state order = 'ASC' - not_brouillon.where(archived: false).order("updated_at #{order}") + not_brouillon.not_archived.order("updated_at #{order}") end def brouillon? @@ -172,25 +172,25 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } def self.nouveaux order = 'ASC' - where(state: NOUVEAUX, archived: false).order("updated_at #{order}") + not_archived.where(state: NOUVEAUX).order("updated_at #{order}") end def self.waiting_for_gestionnaire order = 'ASC' - where(state: WAITING_FOR_GESTIONNAIRE, archived: false).order("updated_at #{order}") + not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order("updated_at #{order}") end def self.waiting_for_user order = 'ASC' - where(state: WAITING_FOR_USER, archived: false).order("updated_at #{order}") + not_archived.where(state: WAITING_FOR_USER).order("updated_at #{order}") end scope :en_construction, -> { where(state: EN_CONSTRUCTION) } def self.ouvert order = 'ASC' - where(state: OUVERT, archived: false).order("updated_at #{order}") + not_archived.where(state: OUVERT).order("updated_at #{order}") end def self.a_instruire order = 'ASC' - where(state: A_INSTRUIRE, archived: false).order("updated_at #{order}") + not_archived.where(state: A_INSTRUIRE).order("updated_at #{order}") end scope :en_instruction, -> { where(state: EN_INSTRUCTION) } From 5253f07b69b7ee09add6ad78e4143709d6f5e0cb Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:12:25 +0200 Subject: [PATCH 3/4] Use the order_by_updated_at scope in Dossier --- app/models/dossier.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index a919aec27..607254391 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -159,7 +159,7 @@ class Dossier < ActiveRecord::Base end def self.all_state order = 'ASC' - not_brouillon.not_archived.order("updated_at #{order}") + not_brouillon.not_archived.order_by_updated_at(order) end def brouillon? @@ -172,25 +172,25 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } def self.nouveaux order = 'ASC' - not_archived.where(state: NOUVEAUX).order("updated_at #{order}") + not_archived.where(state: NOUVEAUX).order_by_updated_at(order) end def self.waiting_for_gestionnaire order = 'ASC' - not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order("updated_at #{order}") + not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order_by_updated_at(order) end def self.waiting_for_user order = 'ASC' - not_archived.where(state: WAITING_FOR_USER).order("updated_at #{order}") + not_archived.where(state: WAITING_FOR_USER).order_by_updated_at(order) end scope :en_construction, -> { where(state: EN_CONSTRUCTION) } def self.ouvert order = 'ASC' - not_archived.where(state: OUVERT).order("updated_at #{order}") + not_archived.where(state: OUVERT).order_by_updated_at(order) end def self.a_instruire order = 'ASC' - not_archived.where(state: A_INSTRUIRE).order("updated_at #{order}") + not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order) end scope :en_instruction, -> { where(state: EN_INSTRUCTION) } From 4655707eb5d28dc49329930ef7c813c04e3cdc1f Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:14:00 +0200 Subject: [PATCH 4/4] [Fix #319] Include archived dossiers in the export --- app/models/dossier.rb | 2 +- spec/models/dossier_spec.rb | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 607254391..3fd21c1c0 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -200,7 +200,7 @@ class Dossier < ActiveRecord::Base scope :archived, -> { where(archived: true) } scope :not_archived, -> { where(archived: false) } - scope :downloadable, -> { all_state } + scope :downloadable, -> { not_brouillon.order_by_updated_at("ASC") } def cerfa_available? procedure.cerfa_flag? && cerfa.size != 0 diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index e964e4b0d..8b9c8244a 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -911,11 +911,13 @@ describe Dossier do let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: :draft) } let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: :initiated) } let!(:dossier3) { create(:dossier, :with_entreprise, procedure: procedure, state: :received) } + let!(:dossier4) { create(:dossier, :with_entreprise, procedure: procedure, state: :received, archived: true) } subject { procedure.dossiers.downloadable } it { is_expected.not_to include(dossier)} it { is_expected.to include(dossier2)} it { is_expected.to include(dossier3)} + it { is_expected.to include(dossier4)} end end