From 6731f28e23fea24d4ef114e47338a7d8f26db3e4 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:22:31 +0200 Subject: [PATCH 01/13] Move the state constants below the state enum --- app/models/dossier.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 3fd21c1c0..aa40a5410 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -9,6 +9,16 @@ class Dossier < ActiveRecord::Base without_continuation: 'without_continuation' } + BROUILLON = %w(draft) + NOUVEAUX = %w(initiated) + OUVERT = %w(updated replied) + WAITING_FOR_GESTIONNAIRE = %w(updated) + WAITING_FOR_USER = %w(replied) + EN_CONSTRUCTION = %w(initiated updated replied) + EN_INSTRUCTION = %w(received) + A_INSTRUIRE = %w(received) + TERMINE = %w(closed refused without_continuation) + has_one :etablissement, dependent: :destroy has_one :entreprise, dependent: :destroy has_one :individual, dependent: :destroy @@ -45,16 +55,6 @@ class Dossier < ActiveRecord::Base validates :user, presence: true - BROUILLON = %w(draft) - NOUVEAUX = %w(initiated) - OUVERT = %w(updated replied) - WAITING_FOR_GESTIONNAIRE = %w(updated) - WAITING_FOR_USER = %w(replied) - EN_CONSTRUCTION = %w(initiated updated replied) - EN_INSTRUCTION = %w(received) - A_INSTRUIRE = %w(received) - TERMINE = %w(closed refused without_continuation) - def unreaded_notifications @unreaded_notif ||= notifications.where(already_read: false) end From 1816aef7d0280f27c902dee91506f0c654701622 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:23:16 +0200 Subject: [PATCH 02/13] Group the Dossier scopes and move them at the top --- app/models/dossier.rb | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index aa40a5410..12b46bf33 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -40,6 +40,19 @@ class Dossier < ActiveRecord::Base belongs_to :procedure belongs_to :user + scope :brouillon, -> { where(state: BROUILLON) } + scope :not_brouillon, -> { where.not(state: BROUILLON) } + scope :en_construction, -> { where(state: EN_CONSTRUCTION) } + scope :en_instruction, -> { where(state: EN_INSTRUCTION) } + scope :termine, -> { where(state: TERMINE) } + + scope :archived, -> { where(archived: true) } + scope :not_archived, -> { where(archived: false) } + + scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } + + scope :downloadable, -> { not_brouillon.order_by_updated_at("ASC") } + accepts_nested_attributes_for :individual delegate :siren, to: :entreprise @@ -166,11 +179,6 @@ class Dossier < ActiveRecord::Base BROUILLON.include?(state) end - scope :brouillon, -> { where(state: BROUILLON) } - scope :not_brouillon, -> { where.not(state: BROUILLON) } - - scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } - def self.nouveaux order = 'ASC' not_archived.where(state: NOUVEAUX).order_by_updated_at(order) end @@ -183,8 +191,6 @@ class Dossier < ActiveRecord::Base 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_by_updated_at(order) end @@ -193,15 +199,6 @@ class Dossier < ActiveRecord::Base not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order) end - scope :en_instruction, -> { where(state: EN_INSTRUCTION) } - - scope :termine, -> { where(state: TERMINE) } - - scope :archived, -> { where(archived: true) } - scope :not_archived, -> { where(archived: false) } - - scope :downloadable, -> { not_brouillon.order_by_updated_at("ASC") } - def cerfa_available? procedure.cerfa_flag? && cerfa.size != 0 end From 51dd6df1c0e99a1f217ba50573f900b9946f8ba8 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:27:51 +0200 Subject: [PATCH 03/13] Improve the formatting of the Dossier state enum --- app/models/dossier.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 12b46bf33..ab75d7608 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -1,13 +1,14 @@ class Dossier < ActiveRecord::Base - enum state: {draft: 'draft', - initiated: 'initiated', - replied: 'replied', #action utilisateur demandé - updated: 'updated', #etude par l'administration en cours - received: 'received', - closed: 'closed', - refused: 'refused', - without_continuation: 'without_continuation' - } + enum state: { + draft: 'draft', + initiated: 'initiated', + replied: 'replied', # action utilisateur demandé + updated: 'updated', # etude par l'administration en cours + received: 'received', + closed: 'closed', + refused: 'refused', + without_continuation: 'without_continuation' + } BROUILLON = %w(draft) NOUVEAUX = %w(initiated) From ab1c19c09bf1691a1e2570b25b90cb310f1f281c Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:59:21 +0200 Subject: [PATCH 04/13] Rename some Dossier scopes --- app/controllers/users/dossiers_controller.rb | 8 ++++---- app/models/dossier.rb | 14 +++++++------- app/services/dossiers_list_gestionnaire_service.rb | 2 +- ..._panel_users_dossierscontroller_index.html.haml | 8 ++++---- app/workers/auto_archive_procedure_worker.rb | 2 +- spec/models/dossier_spec.rb | 4 ++-- .../dossiers_list_gestionnaire_service_spec.rb | 2 +- spec/views/users/dossiers/index_html.haml_spec.rb | 7 +++---- 8 files changed, 23 insertions(+), 24 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 8f42f2581..1d9964d72 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -16,13 +16,13 @@ class Users::DossiersController < UsersController @dossiers_filtered = case @liste when 'brouillon' - @user_dossiers.brouillon.order_by_updated_at + @user_dossiers.state_brouillon.order_by_updated_at when 'a_traiter' - @user_dossiers.en_construction.order_by_updated_at + @user_dossiers.state_en_construction.order_by_updated_at when 'en_instruction' - @user_dossiers.en_instruction.order_by_updated_at + @user_dossiers.state_en_instruction.order_by_updated_at when 'termine' - @user_dossiers.termine.order_by_updated_at + @user_dossiers.state_termine.order_by_updated_at when 'invite' current_user.invites else diff --git a/app/models/dossier.rb b/app/models/dossier.rb index ab75d7608..91e19fced 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -41,18 +41,18 @@ class Dossier < ActiveRecord::Base belongs_to :procedure belongs_to :user - scope :brouillon, -> { where(state: BROUILLON) } - scope :not_brouillon, -> { where.not(state: BROUILLON) } - scope :en_construction, -> { where(state: EN_CONSTRUCTION) } - scope :en_instruction, -> { where(state: EN_INSTRUCTION) } - scope :termine, -> { where(state: TERMINE) } + scope :state_brouillon, -> { where(state: BROUILLON) } + scope :state_not_brouillon, -> { where.not(state: BROUILLON) } + scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) } + scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) } + scope :state_termine, -> { where(state: TERMINE) } scope :archived, -> { where(archived: true) } scope :not_archived, -> { where(archived: false) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } - scope :downloadable, -> { not_brouillon.order_by_updated_at("ASC") } + scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } accepts_nested_attributes_for :individual @@ -173,7 +173,7 @@ class Dossier < ActiveRecord::Base end def self.all_state order = 'ASC' - not_brouillon.not_archived.order_by_updated_at(order) + state_not_brouillon.not_archived.order_by_updated_at(order) end def brouillon? diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index 63a91783c..ce349258b 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -45,7 +45,7 @@ class DossiersListGestionnaireService end def termine - @termine ||= filter_dossiers.termine.not_archived + @termine ||= filter_dossiers.state_termine.not_archived end def filter_dossiers diff --git a/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml b/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml index 9a6fff7a1..9b561f312 100644 --- a/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml +++ b/app/views/layouts/left_panels/_left_panel_users_dossierscontroller_index.html.haml @@ -15,25 +15,25 @@ .procedure-list-element#brouillon{ class: ('active' if @liste == 'brouillon') } Brouillons .badge.progress-bar-default - = @user_dossiers.brouillon.count + = @user_dossiers.state_brouillon.count %a{ :href => "#{url_for users_dossiers_path(liste: 'a_traiter')}", 'data-toggle' => :tooltip, title: 'Les dossiers qui requièrent une action de votre part.' } .procedure-list-element#a_traiter{ class: ('active' if @liste == 'a_traiter') } En construction .badge.progress-bar-danger - = @user_dossiers.en_construction.count + = @user_dossiers.state_en_construction.count %a{ :href => "#{url_for users_dossiers_path(liste: 'en_instruction')}", 'data-toggle' => :tooltip, title: 'Les dossiers en cours d\'examen par l\'administration compétante.' } .procedure-list-element#en_instruction{ class: ('active' if @liste == 'en_instruction') } En instruction .badge.progress-bar-default - = @user_dossiers.en_instruction.count + = @user_dossiers.state_en_instruction.count %a{ :href => "#{url_for users_dossiers_path(liste: 'termine')}", 'data-toggle' => :tooltip, title: 'Les dossiers cloturés qui peuvent être "Accepté", "Refusé" ou "Sans suite".' } .procedure-list-element#termine{ class: ('active' if @liste == 'termine') } Terminé .badge.progress-bar-success - = @user_dossiers.termine.count + = @user_dossiers.state_termine.count %a{ :href => "#{url_for users_dossiers_path(liste: 'invite')}" } .procedure-list-element#invite{ class: ('active' if @liste == 'invite') } diff --git a/app/workers/auto_archive_procedure_worker.rb b/app/workers/auto_archive_procedure_worker.rb index 61701b4ff..71659b5a5 100644 --- a/app/workers/auto_archive_procedure_worker.rb +++ b/app/workers/auto_archive_procedure_worker.rb @@ -5,7 +5,7 @@ class AutoArchiveProcedureWorker procedures_to_archive = Procedure.not_archived.where("auto_archive_on <= ?", Date.today) procedures_to_archive.each do |p| - p.dossiers.en_construction.update_all(state: :received) + p.dossiers.state_en_construction.update_all(state: :received) end procedures_to_archive.update_all(archived: true, auto_archive_on: nil) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 8b9c8244a..d301cb42a 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -455,8 +455,8 @@ describe Dossier do it { expect(subject.size).to eq(1) } end - describe '#en_instruction' do - subject { gestionnaire.dossiers.en_instruction } + describe '#state_en_instruction' do + subject { gestionnaire.dossiers.state_en_instruction } it { expect(subject.size).to eq(2) } it { expect(subject).to include(dossier6, dossier7) } diff --git a/spec/services/dossiers_list_gestionnaire_service_spec.rb b/spec/services/dossiers_list_gestionnaire_service_spec.rb index d45293868..cabb9da38 100644 --- a/spec/services/dossiers_list_gestionnaire_service_spec.rb +++ b/spec/services/dossiers_list_gestionnaire_service_spec.rb @@ -364,7 +364,7 @@ describe DossiersListGestionnaireService do let!(:dossier14) { create(:dossier, procedure: procedure, state: 'closed', archived: true) } #termine #archived describe '#termine' do - subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).termine } + subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).state_termine } it { expect(subject.size).to eq(4) } it { expect(subject).to include(dossier8, dossier9, dossier10, dossier11) } diff --git a/spec/views/users/dossiers/index_html.haml_spec.rb b/spec/views/users/dossiers/index_html.haml_spec.rb index 09e787e99..3813456f8 100644 --- a/spec/views/users/dossiers/index_html.haml_spec.rb +++ b/spec/views/users/dossiers/index_html.haml_spec.rb @@ -43,7 +43,7 @@ describe 'users/dossiers/index.html.haml', type: :view do describe 'on tab en construction' do let(:total_dossiers) { 3 } let(:active_class) { '.active .text-danger' } - let(:dossiers_to_display) { user.dossiers.en_construction } + let(:dossiers_to_display) { user.dossiers.state_en_construction } let(:liste) { 'a_traiter' } it_behaves_like 'check_tab_content' do @@ -59,11 +59,10 @@ describe 'users/dossiers/index.html.haml', type: :view do end end - describe 'on tab etude en examen' do let(:total_dossiers) { 1 } let(:active_class) { '.active .text-default' } - let(:dossiers_to_display) { user.dossiers.en_instruction } + let(:dossiers_to_display) { user.dossiers.state_en_instruction } let(:liste) { 'en_instruction' } it_behaves_like 'check_tab_content' do @@ -74,7 +73,7 @@ describe 'users/dossiers/index.html.haml', type: :view do describe 'on tab etude termine' do let(:total_dossiers) { 3 } let(:active_class) { '.active .text-success' } - let(:dossiers_to_display) { user.dossiers.termine } + let(:dossiers_to_display) { user.dossiers.state_termine } let(:liste) { 'termine' } it_behaves_like 'check_tab_content' do From 9c2c0346b6a913c828d37c3150e9015f49cecd75 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:01:20 +0200 Subject: [PATCH 05/13] [Fix #125] Transform some Dossier class methods into scopes --- app/models/dossier.rb | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 91e19fced..d6a65ef19 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -52,6 +52,12 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } + scope :all_state, -> (order = :asc) { state_not_brouillon.not_archived.order_by_updated_at(order) } + scope :nouveaux, -> (order = :asc) { not_archived.where(state: NOUVEAUX).order_by_updated_at(order) } + scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order_by_updated_at(order) } + scope :waiting_for_user, -> (order = :asc) { not_archived.where(state: WAITING_FOR_USER).order_by_updated_at(order) } + scope :ouvert, -> (order = :asc) { not_archived.where(state: OUVERT).order_by_updated_at(order) } + scope :a_instruire, -> (order = :asc) { not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order) } scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } accepts_nested_attributes_for :individual @@ -172,34 +178,10 @@ class Dossier < ActiveRecord::Base state end - def self.all_state order = 'ASC' - state_not_brouillon.not_archived.order_by_updated_at(order) - end - def brouillon? BROUILLON.include?(state) end - def self.nouveaux order = 'ASC' - 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_by_updated_at(order) - end - - def self.waiting_for_user order = 'ASC' - not_archived.where(state: WAITING_FOR_USER).order_by_updated_at(order) - end - - def self.ouvert order = 'ASC' - not_archived.where(state: OUVERT).order_by_updated_at(order) - end - - def self.a_instruire order = 'ASC' - not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order) - end - def cerfa_available? procedure.cerfa_flag? && cerfa.size != 0 end From 7055aec634993cbe38102b34789d51e598f396e7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:32:56 +0200 Subject: [PATCH 06/13] Add some more state scopes and use them --- app/models/dossier.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index d6a65ef19..0ceef148c 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -43,8 +43,13 @@ class Dossier < ActiveRecord::Base scope :state_brouillon, -> { where(state: BROUILLON) } scope :state_not_brouillon, -> { where.not(state: BROUILLON) } + scope :state_nouveaux, -> { where(state: NOUVEAUX) } + scope :state_ouvert, -> { where(state: OUVERT) } + scope :state_waiting_for_gestionnaire, -> { where(state: WAITING_FOR_GESTIONNAIRE) } + scope :state_waiting_for_user, -> { where(state: WAITING_FOR_USER) } scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) } scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) } + scope :state_a_instruire, -> { where(state: A_INSTRUIRE) } scope :state_termine, -> { where(state: TERMINE) } scope :archived, -> { where(archived: true) } @@ -53,11 +58,11 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } scope :all_state, -> (order = :asc) { state_not_brouillon.not_archived.order_by_updated_at(order) } - scope :nouveaux, -> (order = :asc) { not_archived.where(state: NOUVEAUX).order_by_updated_at(order) } - scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.where(state: WAITING_FOR_GESTIONNAIRE).order_by_updated_at(order) } - scope :waiting_for_user, -> (order = :asc) { not_archived.where(state: WAITING_FOR_USER).order_by_updated_at(order) } - scope :ouvert, -> (order = :asc) { not_archived.where(state: OUVERT).order_by_updated_at(order) } - scope :a_instruire, -> (order = :asc) { not_archived.where(state: A_INSTRUIRE).order_by_updated_at(order) } + scope :nouveaux, -> (order = :asc) { not_archived.state_nouveaux.order_by_updated_at(order) } + scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(order) } + scope :waiting_for_user, -> (order = :asc) { not_archived.state_waiting_for_user.order_by_updated_at(order) } + scope :ouvert, -> (order = :asc) { not_archived.state_ouvert.order_by_updated_at(order) } + scope :a_instruire, -> (order = :asc) { not_archived.state_a_instruire.order_by_updated_at(order) } scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } accepts_nested_attributes_for :individual From ddac4bbfdb95d5a59eb4b9876c79f44de22526c5 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:33:30 +0200 Subject: [PATCH 07/13] Change the order in the all_state scope for consistency --- app/models/dossier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 0ceef148c..bdf28fe36 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -57,7 +57,7 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } - scope :all_state, -> (order = :asc) { state_not_brouillon.not_archived.order_by_updated_at(order) } + scope :all_state, -> (order = :asc) { not_archived.state_not_brouillon.order_by_updated_at(order) } scope :nouveaux, -> (order = :asc) { not_archived.state_nouveaux.order_by_updated_at(order) } scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(order) } scope :waiting_for_user, -> (order = :asc) { not_archived.state_waiting_for_user.order_by_updated_at(order) } From e0a3a48f762bd87db58bddc4cbc76c0374f134fe Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Thu, 1 Jun 2017 11:05:51 +0200 Subject: [PATCH 08/13] Improve the formatting of Dossier scopes --- app/models/dossier.rb | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index bdf28fe36..eaf4486b0 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -41,29 +41,29 @@ class Dossier < ActiveRecord::Base belongs_to :procedure belongs_to :user - scope :state_brouillon, -> { where(state: BROUILLON) } - scope :state_not_brouillon, -> { where.not(state: BROUILLON) } - scope :state_nouveaux, -> { where(state: NOUVEAUX) } - scope :state_ouvert, -> { where(state: OUVERT) } - scope :state_waiting_for_gestionnaire, -> { where(state: WAITING_FOR_GESTIONNAIRE) } - scope :state_waiting_for_user, -> { where(state: WAITING_FOR_USER) } - scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) } - scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) } - scope :state_a_instruire, -> { where(state: A_INSTRUIRE) } - scope :state_termine, -> { where(state: TERMINE) } + scope :state_brouillon, -> { where(state: BROUILLON) } + scope :state_not_brouillon, -> { where.not(state: BROUILLON) } + scope :state_nouveaux, -> { where(state: NOUVEAUX) } + scope :state_ouvert, -> { where(state: OUVERT) } + scope :state_waiting_for_gestionnaire, -> { where(state: WAITING_FOR_GESTIONNAIRE) } + scope :state_waiting_for_user, -> { where(state: WAITING_FOR_USER) } + scope :state_en_construction, -> { where(state: EN_CONSTRUCTION) } + scope :state_en_instruction, -> { where(state: EN_INSTRUCTION) } + scope :state_a_instruire, -> { where(state: A_INSTRUIRE) } + scope :state_termine, -> { where(state: TERMINE) } - scope :archived, -> { where(archived: true) } - scope :not_archived, -> { where(archived: false) } + scope :archived, -> { where(archived: true) } + scope :not_archived, -> { where(archived: false) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } - scope :all_state, -> (order = :asc) { not_archived.state_not_brouillon.order_by_updated_at(order) } - scope :nouveaux, -> (order = :asc) { not_archived.state_nouveaux.order_by_updated_at(order) } - scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(order) } - scope :waiting_for_user, -> (order = :asc) { not_archived.state_waiting_for_user.order_by_updated_at(order) } - scope :ouvert, -> (order = :asc) { not_archived.state_ouvert.order_by_updated_at(order) } - scope :a_instruire, -> (order = :asc) { not_archived.state_a_instruire.order_by_updated_at(order) } - scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } + scope :all_state, -> (order = :asc) { not_archived.state_not_brouillon.order_by_updated_at(order) } + scope :nouveaux, -> (order = :asc) { not_archived.state_nouveaux.order_by_updated_at(order) } + scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(order) } + scope :waiting_for_user, -> (order = :asc) { not_archived.state_waiting_for_user.order_by_updated_at(order) } + scope :ouvert, -> (order = :asc) { not_archived.state_ouvert.order_by_updated_at(order) } + scope :a_instruire, -> (order = :asc) { not_archived.state_a_instruire.order_by_updated_at(order) } + scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } accepts_nested_attributes_for :individual From 8fb6a41386732672994f67bad5118a823f191fcd Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:41:22 +0200 Subject: [PATCH 09/13] Remove an unused argument in some Dossier scopes --- 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 eaf4486b0..66a8a0d51 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -57,12 +57,12 @@ class Dossier < ActiveRecord::Base scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } - scope :all_state, -> (order = :asc) { not_archived.state_not_brouillon.order_by_updated_at(order) } - scope :nouveaux, -> (order = :asc) { not_archived.state_nouveaux.order_by_updated_at(order) } - scope :waiting_for_gestionnaire, -> (order = :asc) { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(order) } - scope :waiting_for_user, -> (order = :asc) { not_archived.state_waiting_for_user.order_by_updated_at(order) } - scope :ouvert, -> (order = :asc) { not_archived.state_ouvert.order_by_updated_at(order) } - scope :a_instruire, -> (order = :asc) { not_archived.state_a_instruire.order_by_updated_at(order) } + scope :all_state, -> { not_archived.state_not_brouillon.order_by_updated_at(:asc) } + scope :nouveaux, -> { not_archived.state_nouveaux.order_by_updated_at(:asc) } + scope :waiting_for_gestionnaire, -> { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(:asc) } + scope :waiting_for_user, -> { not_archived.state_waiting_for_user.order_by_updated_at(:asc) } + scope :ouvert, -> { not_archived.state_ouvert.order_by_updated_at(:asc) } + scope :a_instruire, -> { not_archived.state_a_instruire.order_by_updated_at(:asc) } scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } accepts_nested_attributes_for :individual From 68da2ecbae79da5332232f3711de248a3fce0be4 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 18:45:08 +0200 Subject: [PATCH 10/13] Use symbols instead of strings in for the order arg in scopes --- app/models/dossier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 66a8a0d51..27e44af56 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -63,7 +63,7 @@ class Dossier < ActiveRecord::Base scope :waiting_for_user, -> { not_archived.state_waiting_for_user.order_by_updated_at(:asc) } scope :ouvert, -> { not_archived.state_ouvert.order_by_updated_at(:asc) } scope :a_instruire, -> { not_archived.state_a_instruire.order_by_updated_at(:asc) } - scope :downloadable, -> { state_not_brouillon.order_by_updated_at("ASC") } + scope :downloadable, -> { state_not_brouillon.order_by_updated_at(:asc) } accepts_nested_attributes_for :individual From 5e5a01cdc80a024c1c5c9f26be7b50ab1be96a02 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:19:44 +0200 Subject: [PATCH 11/13] Do not test scopes --- spec/models/dossier_spec.rb | 53 ------------------------------------- 1 file changed, 53 deletions(-) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index d301cb42a..b682281b7 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -409,59 +409,6 @@ describe Dossier do end end end - - describe 'gestionnaire backoffice methods' do - let(:admin) { create(:administrateur) } - let(:admin_2) { create(:administrateur) } - - let(:gestionnaire) { create(:gestionnaire, administrateurs: [admin]) } - let(:procedure_admin) { create(:procedure, administrateur: admin) } - let(:procedure_admin_2) { create(:procedure, administrateur: admin_2) } - - let!(:dossier) { create(:dossier, procedure: procedure_admin, state: 'draft') } - let!(:dossier2) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #nouveaux - let!(:dossier3) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #nouveaux - let!(:dossier4) { create(:dossier, procedure: procedure_admin, state: 'replied') } #en_attente - let!(:dossier5) { create(:dossier, procedure: procedure_admin, state: 'updated') } #a_traiter - let!(:dossier6) { create(:dossier, procedure: procedure_admin, state: 'received') } #a_instruire - let!(:dossier7) { create(:dossier, procedure: procedure_admin, state: 'received') } #a_instruire - let!(:dossier8) { create(:dossier, procedure: procedure_admin, state: 'closed') } #termine - let!(:dossier9) { create(:dossier, procedure: procedure_admin, state: 'refused') } #termine - let!(:dossier10) { create(:dossier, procedure: procedure_admin, state: 'without_continuation') } #termine - let!(:dossier11) { create(:dossier, procedure: procedure_admin_2, state: 'closed') } #termine - let!(:dossier12) { create(:dossier, procedure: procedure_admin, state: 'initiated', archived: true) } #a_traiter #archived - let!(:dossier13) { create(:dossier, procedure: procedure_admin, state: 'replied', archived: true) } #en_attente #archived - let!(:dossier14) { create(:dossier, procedure: procedure_admin, state: 'closed', archived: true) } #termine #archived - - before do - create :assign_to, gestionnaire: gestionnaire, procedure: procedure_admin - end - - describe '#nouveaux' do - subject { gestionnaire.dossiers.nouveaux } - - it { expect(subject.size).to eq(2) } - end - - describe '#waiting_for_gestionnaire' do - subject { gestionnaire.dossiers.waiting_for_gestionnaire } - - it { expect(subject.size).to eq(1) } - end - - describe '#waiting_for_user' do - subject { gestionnaire.dossiers.waiting_for_user } - - it { expect(subject.size).to eq(1) } - end - - describe '#state_en_instruction' do - subject { gestionnaire.dossiers.state_en_instruction } - - it { expect(subject.size).to eq(2) } - it { expect(subject).to include(dossier6, dossier7) } - end - end end describe '#cerfa_available?' do From 0971ede57e34d794b6f1a44c3185fa080ed6dfad Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:21:42 +0200 Subject: [PATCH 12/13] Add a termine scope to Dossier --- app/models/dossier.rb | 1 + app/services/dossiers_list_gestionnaire_service.rb | 2 +- spec/services/dossiers_list_gestionnaire_service_spec.rb | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 27e44af56..b37609be4 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -63,6 +63,7 @@ class Dossier < ActiveRecord::Base scope :waiting_for_user, -> { not_archived.state_waiting_for_user.order_by_updated_at(:asc) } scope :ouvert, -> { not_archived.state_ouvert.order_by_updated_at(:asc) } scope :a_instruire, -> { not_archived.state_a_instruire.order_by_updated_at(:asc) } + scope :termine, -> { not_archived.state_termine.order_by_updated_at(:asc) } scope :downloadable, -> { state_not_brouillon.order_by_updated_at(:asc) } accepts_nested_attributes_for :individual diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index ce349258b..b110fde11 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -45,7 +45,7 @@ class DossiersListGestionnaireService end def termine - @termine ||= filter_dossiers.state_termine.not_archived + @termine ||= filter_dossiers.termine end def filter_dossiers diff --git a/spec/services/dossiers_list_gestionnaire_service_spec.rb b/spec/services/dossiers_list_gestionnaire_service_spec.rb index cabb9da38..d45293868 100644 --- a/spec/services/dossiers_list_gestionnaire_service_spec.rb +++ b/spec/services/dossiers_list_gestionnaire_service_spec.rb @@ -364,7 +364,7 @@ describe DossiersListGestionnaireService do let!(:dossier14) { create(:dossier, procedure: procedure, state: 'closed', archived: true) } #termine #archived describe '#termine' do - subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).state_termine } + subject { DossiersListGestionnaireService.new(gestionnaire, liste, procedure).termine } it { expect(subject.size).to eq(4) } it { expect(subject).to include(dossier8, dossier9, dossier10, dossier11) } From d5023a3d3886816affa4e57e402c0a807c5c2cc4 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 26 May 2017 19:24:28 +0200 Subject: [PATCH 13/13] Use the same order for constants and scopes in Dossier --- app/models/dossier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index b37609be4..c2b641644 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -59,9 +59,9 @@ class Dossier < ActiveRecord::Base scope :all_state, -> { not_archived.state_not_brouillon.order_by_updated_at(:asc) } scope :nouveaux, -> { not_archived.state_nouveaux.order_by_updated_at(:asc) } + scope :ouvert, -> { not_archived.state_ouvert.order_by_updated_at(:asc) } scope :waiting_for_gestionnaire, -> { not_archived.state_waiting_for_gestionnaire.order_by_updated_at(:asc) } scope :waiting_for_user, -> { not_archived.state_waiting_for_user.order_by_updated_at(:asc) } - scope :ouvert, -> { not_archived.state_ouvert.order_by_updated_at(:asc) } scope :a_instruire, -> { not_archived.state_a_instruire.order_by_updated_at(:asc) } scope :termine, -> { not_archived.state_termine.order_by_updated_at(:asc) } scope :downloadable, -> { state_not_brouillon.order_by_updated_at(:asc) }