From a7166d306f8c344ae8e2da64671f3d6adaec5c12 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Wed, 19 Oct 2016 17:25:24 +0200 Subject: [PATCH] =?UTF-8?q?Delete=20tab=20Nouveau=20A=20traiter=20and=20En?= =?UTF-8?q?=20cours=20d'=C3=A9tude=20for=20User=20and=20replace=20this=20o?= =?UTF-8?q?nly=20one=20call=20En=20construction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/facades/dossiers_list_facades.rb | 20 ++++++-- app/models/dossier.rb | 10 ++-- .../dossiers_list_gestionnaire_service.rb | 2 +- app/services/dossiers_list_user_service.rb | 18 ++----- app/views/users/dossiers/_onglets.html.haml | 20 ++------ .../users/dossiers_controller_spec.rb | 30 +++++++++++- spec/features/users/onglets_link_spec.rb | 26 +--------- ...dossiers_list_gestionnaire_service_spec.rb | 47 +++++++++++++++++++ .../users/dossiers/index_html.haml_spec.rb | 24 ++-------- 9 files changed, 110 insertions(+), 87 deletions(-) diff --git a/app/facades/dossiers_list_facades.rb b/app/facades/dossiers_list_facades.rb index 161a86572..39b98ba1a 100644 --- a/app/facades/dossiers_list_facades.rb +++ b/app/facades/dossiers_list_facades.rb @@ -20,7 +20,7 @@ class DossiersListFacades end def gestionnaire_procedures_name_and_id_list - @current_devise_profil.procedures.order('libelle ASC').inject([]) { |acc, procedure| acc.push({id: procedure.id, libelle: procedure.libelle})} + @current_devise_profil.procedures.order('libelle ASC').inject([]) { |acc, procedure| acc.push({id: procedure.id, libelle: procedure.libelle}) } end def procedure_id @@ -53,6 +53,10 @@ class DossiersListFacades (@liste == 'a_traiter' ? 'active' : '') end + def en_construction_class + (@liste == 'a_traiter' ? 'active' : '') + end + def en_attente_class (@liste == 'en_attente' ? 'active' : '') end @@ -98,13 +102,15 @@ class DossiersListFacades end def a_traiter_total - return service.waiting_for_gestionnaire.count if gestionnaire? - service.waiting_for_user.count if user? + service.waiting_for_gestionnaire.count + end + + def en_construction_total + service.en_construction.count end def en_attente_total - return service.waiting_for_user.count if gestionnaire? - service.waiting_for_gestionnaire.count if user? + service.waiting_for_user.count end def valides_total @@ -147,6 +153,10 @@ class DossiersListFacades base_url 'a_traiter' end + def en_construction_url + base_url 'a_traiter' + end + def en_attente_url base_url 'en_attente' end diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 0a1d9611a..c952ad0f6 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -47,7 +47,7 @@ class Dossier < ActiveRecord::Base NOUVEAUX = %w(initiated) WAITING_FOR_GESTIONNAIRE = %w(updated) WAITING_FOR_USER = %w(replied validated) - WAITING_FOR_USER_WITHOUT_VALIDATED = %w(replied) + EN_CONSTRUCTION = %w(initiated updated replied) VALIDES = %w(validated) DEPOSES = %w(submitted) EN_INSTRUCTION = %w(submitted received) @@ -185,8 +185,8 @@ class Dossier < ActiveRecord::Base WAITING_FOR_USER.include?(state) end - def waiting_for_user_without_validated? - WAITING_FOR_USER_WITHOUT_VALIDATED.include?(state) + def en_construction? + EN_CONSTRUCTION.include?(state) end def deposes? @@ -225,8 +225,8 @@ class Dossier < ActiveRecord::Base where(state: WAITING_FOR_USER, archived: false).order("updated_at #{order}") end - def self.waiting_for_user_without_validated order = 'ASC' - where(state: WAITING_FOR_USER_WITHOUT_VALIDATED, archived: false).order("updated_at #{order}") + def self.en_construction order = 'ASC' + where(state: EN_CONSTRUCTION, archived: false).order("updated_at #{order}") end def self.valides order = 'ASC' diff --git a/app/services/dossiers_list_gestionnaire_service.rb b/app/services/dossiers_list_gestionnaire_service.rb index 00ace5b68..9dbb7c072 100644 --- a/app/services/dossiers_list_gestionnaire_service.rb +++ b/app/services/dossiers_list_gestionnaire_service.rb @@ -121,7 +121,7 @@ class DossiersListGestionnaireService def joins_filter filter_preference_list.inject([]) do |acc, preference| - acc.push(preference.table.to_sym) unless preference.table.blank? + acc.push(preference.table.to_sym) unless preference.table.blank? || preference.filter.blank? acc end end diff --git a/app/services/dossiers_list_user_service.rb b/app/services/dossiers_list_user_service.rb index 429497fa6..53f7902b2 100644 --- a/app/services/dossiers_list_user_service.rb +++ b/app/services/dossiers_list_user_service.rb @@ -6,9 +6,7 @@ class DossiersListUserService def dossiers_to_display {'brouillon' => brouillon, - 'nouveaux' => nouveaux, - 'a_traiter' => waiting_for_user, - 'en_attente' => waiting_for_gestionnaire, + 'a_traiter' => en_construction, 'valides' => valides, 'en_instruction' => en_instruction, 'termine' => termine, @@ -16,23 +14,15 @@ class DossiersListUserService end def self.dossiers_liste_libelle - ['brouillon', 'nouveaux', 'a_traiter', 'en_attente', 'valides', 'en_instruction', 'termine', 'invite'] + ['brouillon', 'a_traiter', 'valides', 'en_instruction', 'termine', 'invite'] end def brouillon @brouillon ||= @current_devise_profil.dossiers.brouillon end - def nouveaux - @nouveaux ||= @current_devise_profil.dossiers.nouveaux - end - - def waiting_for_gestionnaire - @waiting_for_gestionnaire ||= @current_devise_profil.dossiers.waiting_for_gestionnaire - end - - def waiting_for_user - @waiting_for_user ||= @current_devise_profil.dossiers.waiting_for_user_without_validated + def en_construction + @en_construction ||= @current_devise_profil.dossiers.en_construction end def invite diff --git a/app/views/users/dossiers/_onglets.html.haml b/app/views/users/dossiers/_onglets.html.haml index de53b9039..e4ee9a009 100644 --- a/app/views/users/dossiers/_onglets.html.haml +++ b/app/views/users/dossiers/_onglets.html.haml @@ -8,26 +8,12 @@ .badge.progress-bar-default = @dossiers_list_facade.brouillon_total - %li{ class: @dossiers_list_facade.nouveaux_class } - %a{:href => "#{url_for users_dossiers_path(liste: 'nouveaux')}", 'data-toggle' => :tooltip, title: 'Les nouveaux dossiers qui n\'ont pas encore été vus par votre accompagnateur.'} - %h5.text-info - = "Nouveaux" - .badge.progress-bar-info - = @dossiers_list_facade.nouveaux_total - - %li{ class: @dossiers_list_facade.a_traiter_class } + %li{ class: @dossiers_list_facade.en_construction_class } %a{:href => "#{url_for users_dossiers_path(liste: 'a_traiter')}", 'data-toggle' => :tooltip, title: 'Les dossiers qui requièrent une action de votre part.'} %h5.text-danger - = "Action requise" + = "En construction" .badge.progress-bar-danger - = @dossiers_list_facade.a_traiter_total - - %li{ class: @dossiers_list_facade.en_attente_class } - %a{:href => "#{url_for users_dossiers_path(liste: 'en_attente')}", 'data-toggle' => :tooltip, title: 'Les dossiers en cours de relecture par votre accompagnateur.'} - %h5.text-default - ="Etude en cours" - .badge.progress-bar-default - = @dossiers_list_facade.en_attente_total + = @dossiers_list_facade.en_construction_total %li{ class: @dossiers_list_facade.valides_class } %a{:href => "#{url_for users_dossiers_path(liste: 'valides')}", 'data-toggle' => :tooltip, title: 'Les dossiers relus par votre accompagnateur pouvant être déposés pour examen.'} diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 58ff40a4b..c4ee69493 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -418,14 +418,40 @@ describe Users::DossiersController, type: :controller do end end - describe 'GET #en_attente' do + describe 'GET #valides' do context 'when user is connected' do before do sign_in user end it 'returns http success' do - get :index, liste: :en_attente + get :index, liste: :valides + expect(response).to have_http_status(200) + end + end + end + + describe 'GET #en_instruction' do + context 'when user is connected' do + before do + sign_in user + end + + it 'returns http success' do + get :index, liste: :en_instruction + expect(response).to have_http_status(200) + end + end + end + + describe 'GET #brouillon' do + context 'when user is connected' do + before do + sign_in user + end + + it 'returns http success' do + get :index, liste: :brouillon expect(response).to have_http_status(200) end end diff --git a/spec/features/users/onglets_link_spec.rb b/spec/features/users/onglets_link_spec.rb index 3685869c1..3da3fd4b3 100644 --- a/spec/features/users/onglets_link_spec.rb +++ b/spec/features/users/onglets_link_spec.rb @@ -22,21 +22,10 @@ feature 'on click on tabs button' do end context 'when user is logged in' do - context 'when he click on tabs nouveaux' do - before do - visit users_dossiers_url(liste: :nouveaux) - page.click_on 'Nouveaux 1' - end - - scenario 'it redirect to users dossier termine' do - expect(page).to have_css('#users_index') - end - end - - context 'when he click on tabs a traite' do + context 'when he click on tabs en construction' do before do visit users_dossiers_url(liste: :a_traiter) - page.click_on 'Action requise 1' + page.click_on 'En construction 3' end scenario 'it redirect to users dossier termine' do @@ -44,17 +33,6 @@ feature 'on click on tabs button' do end end - context 'when he click on tabs en attente' do - before do - visit users_dossiers_url(liste: :en_attente) - page.click_on 'Etude en cours 1' - end - - scenario 'it redirect to users dossier en attente' do - expect(page).to have_css('#users_index') - end - end - context 'when he click on tabs a deposes' do before do visit users_dossiers_url(liste: :valides) diff --git a/spec/services/dossiers_list_gestionnaire_service_spec.rb b/spec/services/dossiers_list_gestionnaire_service_spec.rb index f3af980e7..13cbb7334 100644 --- a/spec/services/dossiers_list_gestionnaire_service_spec.rb +++ b/spec/services/dossiers_list_gestionnaire_service_spec.rb @@ -125,6 +125,43 @@ describe DossiersListGestionnaireService do end end + describe '#join_filter' do + + subject { DossiersListGestionnaireService.new(gestionnaire, liste, nil).joins_filter } + + it { is_expected.to eq []} + + context 'when a filter is fielded' do + before do + gestionnaire.preference_list_dossiers + .find_by(table: 'entreprise', attr: 'raison_sociale', procedure: nil) + .update_column :filter, 'plop' + end + + it { is_expected.to eq [:entreprise] } + end + + context 'when a filter is empty' do + before do + gestionnaire.preference_list_dossiers + .find_by(table: 'entreprise', attr: 'raison_sociale', procedure: nil) + .update_column :filter, '' + end + + it { is_expected.to eq [] } + end + + context 'when a filter is nil' do + before do + gestionnaire.preference_list_dossiers + .find_by(table: 'entreprise', attr: 'raison_sociale', procedure: nil) + .update_column :filter, nil + end + + it { is_expected.to eq [] } + end + end + describe '#where_filter' do before do gestionnaire.preference_list_dossiers @@ -181,6 +218,16 @@ describe DossiersListGestionnaireService do it { is_expected.to eq "CAST(dossiers.id as TEXT) LIKE '%23%' AND CAST(entreprises.raison_sociale as TEXT) LIKE '%MCDONALD''S FRANCE%'" } end + context "when filter is empty " do + before do + gestionnaire.preference_list_dossiers + .find_by(table: 'entreprise', attr: 'raison_sociale', procedure: nil) + .update_column :filter, "" + end + + it { is_expected.to eq "CAST(dossiers.id as TEXT) LIKE '%23%'" } + end + context 'when preference list contain a champ' do before do create :preference_list_dossier, diff --git a/spec/views/users/dossiers/index_html.haml_spec.rb b/spec/views/users/dossiers/index_html.haml_spec.rb index bb3eed747..6cc25cc27 100644 --- a/spec/views/users/dossiers/index_html.haml_spec.rb +++ b/spec/views/users/dossiers/index_html.haml_spec.rb @@ -46,33 +46,19 @@ describe 'users/dossiers/index.html.haml', type: :view do end end - describe 'on tab nouveaux' do - let(:total_dossiers) { 1 } - let(:active_class) { '.active .text-info' } - let(:dossiers_to_display) { user.dossiers.nouveaux } - let(:liste) { 'nouveaux' } + 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(:liste) { 'a_traiter' } it_behaves_like 'check_tab_content' do let(:decorate_dossier_at_check) { decorate_dossier_initiated } end - end - - describe 'on tab action requise' do - let(:total_dossiers) { 1 } - let(:active_class) { '.active .text-danger' } - let(:dossiers_to_display) { user.dossiers.waiting_for_user_without_validated } - let(:liste) { 'a_traiter' } it_behaves_like 'check_tab_content' do let(:decorate_dossier_at_check) { decorate_dossier_replied } end - end - - describe 'on tab etude en cours' do - let(:total_dossiers) { 1 } - let(:active_class) { '.active .text-default' } - let(:dossiers_to_display) { user.dossiers.waiting_for_gestionnaire } - let(:liste) { 'en_attente' } it_behaves_like 'check_tab_content' do let(:decorate_dossier_at_check) { decorate_dossier_updated }