From 7a9fd77af077088d0815626af1770a40264a5922 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Wed, 12 Apr 2017 11:18:28 +0200 Subject: [PATCH] Remove archived=false filter from en_construction scope (Fix : archived dossier is not shown to user) --- app/controllers/users/dossiers_controller.rb | 2 +- app/models/dossier.rb | 2 +- ...el_users_dossierscontroller_index.html.haml | 8 ++++---- spec/factories/dossier.rb | 8 ++++++++ spec/factories/procedure.rb | 2 +- spec/features/users/list_dossiers_spec.rb | 18 +++++++++++------- .../concern/mail_template_concern_spec.rb | 2 +- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 73e856c00..9db4e35c1 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -18,7 +18,7 @@ class Users::DossiersController < UsersController when 'brouillon' @user_dossiers.brouillon.order_by_updated_at when 'a_traiter' - @user_dossiers.en_construction + @user_dossiers.en_construction.order_by_updated_at when 'en_instruction' @user_dossiers.en_instruction when 'termine' diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 80d067cef..f563ffcac 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -181,7 +181,7 @@ class Dossier < ActiveRecord::Base where(state: WAITING_FOR_USER, archived: false).order("updated_at #{order}") end - scope :en_construction, -> { where(state: EN_CONSTRUCTION, archived: false).order(updated_at: :asc) } + scope :en_construction, -> { where(state: EN_CONSTRUCTION) } def self.ouvert order = 'ASC' where(state: OUVERT, archived: false).order("updated_at #{order}") 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 0b95d9465..70c8fb208 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 @@ -12,7 +12,7 @@ #procedure-list - unless current_user.dossiers.count == 0 %a{ :href => "#{url_for users_dossiers_path(liste: 'brouillon')}", 'data-toggle' => :tooltip, title: 'Les dossiers jamais proposés à la relecture.' } - .procedure_list_element{ class: ('active' if @liste == 'brouillon'), id: 'brouillon' } + .procedure-list-element{ class: ('active' if @liste == 'brouillon'), id: 'brouillon' } Brouillons .badge.progress-bar-default = @user_dossiers.brouillon.count @@ -24,19 +24,19 @@ = @user_dossiers.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{ class: ('active' if @liste == 'en_instruction'), id: 'en_instruction' } + .procedure-list-element{ class: ('active' if @liste == 'en_instruction'), id: 'en_instruction' } En instruction .badge.progress-bar-default = @user_dossiers.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{ class: ('active' if @liste == 'termine'), id: 'termine' } + .procedure-list-element{ class: ('active' if @liste == 'termine'), id: 'termine' } Terminé .badge.progress-bar-success = @user_dossiers.termine.count %a{ :href => "#{url_for users_dossiers_path(liste: 'invite')}" } - .procedure_list_element{ class: ('active' if @liste == 'invite'), id: 'invite' } + .procedure-list-element{ class: ('active' if @liste == 'invite'), id: 'invite' } Invitation .badge.progress-bar-warning = current_user.invites.count diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 05e70525c..a58e28bb0 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -47,6 +47,14 @@ FactoryGirl.define do end end + trait :archived do + archived true + end + + trait :not_archived do + archived false + end + trait :replied do state 'replied' end diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 30da5d76d..b8e4d5e15 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -2,7 +2,7 @@ FactoryGirl.define do sequence(:published_path) { |n| "fake_path#{n}" } factory :procedure do lien_demarche 'http://localhost' - libelle 'Demande de subvention' + sequence(:libelle) { |n| "Procedure #{n}" } description "Demande de subvention à l'intention des associations" organisation "Orga SGMAP" direction "direction SGMAP" diff --git a/spec/features/users/list_dossiers_spec.rb b/spec/features/users/list_dossiers_spec.rb index 7419a03d4..7a5236f12 100644 --- a/spec/features/users/list_dossiers_spec.rb +++ b/spec/features/users/list_dossiers_spec.rb @@ -1,15 +1,14 @@ require 'spec_helper' -feature 'user access to the list of his dossier' do +describe 'user access to the list of his dossier' do let(:user) { create(:user) } let!(:last_updated_dossier) { create(:dossier, :with_entreprise, user: user, state: 'replied')} let!(:dossier1) { create(:dossier, :with_entreprise, user: user, state: 'replied') } let!(:dossier2) { create(:dossier, :with_entreprise) } + let!(:dossier_archived) { create(:dossier, :with_entreprise, user: user, state: 'replied') } before do - dossier1.update_column(:updated_at, "19/07/2052 15:35".to_time) - dossier1.procedure.update_column(:libelle, 'PLOP') - last_updated_dossier.procedure.update_column(:libelle, 'PLIP') + last_updated_dossier.update_column(:updated_at, "19/07/2052 15:35".to_time) visit new_user_session_path within('#new-user') do @@ -18,16 +17,21 @@ feature 'user access to the list of his dossier' do page.click_on 'Se connecter' end end - scenario 'the list of dossier is displayed' do + + it 'the list of dossier is displayed' do expect(page).to have_content(dossier1.procedure.libelle) expect(page).not_to have_content(dossier2.procedure.libelle) end - scenario 'the list must be order by last updated' do + it 'the list must be order by last updated' do expect(page.body).to match(/#{last_updated_dossier.procedure.libelle}.*#{dossier1.procedure.libelle}/m) end - scenario 'the state of dossier is displayed' do + it 'should list archived dossier' do + expect(page).to have_content(dossier_archived.procedure.libelle) + end + + it 'the state of dossier is displayed' do expect(page).to have_css("#dossier_#{dossier1.id}_state") end diff --git a/spec/models/concern/mail_template_concern_spec.rb b/spec/models/concern/mail_template_concern_spec.rb index b82d78117..96f997ff4 100644 --- a/spec/models/concern/mail_template_concern_spec.rb +++ b/spec/models/concern/mail_template_concern_spec.rb @@ -8,7 +8,7 @@ describe MailTemplateConcern do it 'works' do initiated_mail.object = '[TPS] --numero_dossier-- --libelle_procedure-- --lien_dossier--' expected = - "[TPS] #{dossier.id} Demande de subvention " + + "[TPS] #{dossier.id} #{dossier.procedure.libelle} " + "http://localhost:3000/users/dossiers/#{dossier.id}/recapitulatif" expect(initiated_mail.object_for_dossier(dossier)).to eq(expected)