REFACTOR : Change dossier state 'Proposed' To 'Submitted'

This commit is contained in:
Xavier J 2015-11-02 11:23:55 +01:00
parent 0e8919a523
commit c0733849d5
19 changed files with 54 additions and 49 deletions

View file

@ -45,7 +45,7 @@ class Users::DescriptionController < UsersController
commentaire.dossier = @dossier commentaire.dossier = @dossier
commentaire.save commentaire.save
else else
@dossier.proposed! @dossier.submitted!
end end
flash.notice = 'Félicitation, votre demande a bien été enregistrée.' flash.notice = 'Félicitation, votre demande a bien été enregistrée.'

View file

@ -16,10 +16,10 @@ class Users::RecapitulatifController < UsersController
redirect_to url_for(root_path) redirect_to url_for(root_path)
end end
def propose def submit
show show
@dossier.next_step! 'user', 'propose' @dossier.next_step! 'user', 'submit'
flash.notice = 'Dossier soumis avec succès.' flash.notice = 'Dossier soumis avec succès.'
render 'show' render 'show'

View file

@ -15,7 +15,7 @@ class DossierDecorator < Draper::Decorator
case state case state
when 'draft' when 'draft'
'Brouillon' 'Brouillon'
when 'proposed' when 'submitted'
'Soumis' 'Soumis'
when 'reply' when 'reply'
'Répondu' 'Répondu'

View file

@ -1,11 +1,11 @@
class Dossier < ActiveRecord::Base class Dossier < ActiveRecord::Base
enum state: { draft: 'draft', enum state: {draft: 'draft',
proposed: 'proposed', submitted: 'submitted', #-proposed
reply: 'reply', reply: 'reply', #replied
updated: 'updated', updated: 'updated',
confirmed: 'confirmed', confirmed: 'confirmed', #validated
deposited: 'deposited', deposited: 'deposited', #submit_confirmed
processed: 'processed' } processed: 'processed'} #closed
has_one :etablissement, dependent: :destroy has_one :etablissement, dependent: :destroy
has_one :entreprise, dependent: :destroy has_one :entreprise, dependent: :destroy
@ -49,7 +49,7 @@ class Dossier < ActiveRecord::Base
end end
def next_step! role, action def next_step! role, action
unless %w(propose reply update comment confirme depose process).include?(action) unless %w(submit reply update comment confirme depose process).include?(action)
fail 'action is not valid' fail 'action is not valid'
end end
@ -59,9 +59,9 @@ class Dossier < ActiveRecord::Base
if role == 'user' if role == 'user'
case action case action
when 'propose' when 'submit'
if draft? if draft?
proposed! submitted!
end end
when 'depose' when 'depose'
if confirmed? if confirmed?
@ -81,7 +81,7 @@ class Dossier < ActiveRecord::Base
when 'comment' when 'comment'
if updated? if updated?
reply! reply!
elsif proposed? elsif submitted?
reply! reply!
end end
when 'confirme' when 'confirme'
@ -89,7 +89,7 @@ class Dossier < ActiveRecord::Base
confirmed! confirmed!
elsif reply? elsif reply?
confirmed! confirmed!
elsif proposed? elsif submitted?
confirmed! confirmed!
end end
when 'process' when 'process'
@ -102,7 +102,7 @@ class Dossier < ActiveRecord::Base
end end
def self.a_traiter def self.a_traiter
Dossier.where("state='proposed' OR state='updated' OR state='deposited'").order('updated_at ASC') Dossier.where("state='submitted' OR state='updated' OR state='deposited'").order('updated_at ASC')
end end
def self.en_attente def self.en_attente

View file

@ -11,7 +11,7 @@
- unless gestionnaire_signed_in? - unless gestionnaire_signed_in?
-if @dossier.draft? -if @dossier.draft?
= form_tag(url_for({controller: :recapitulatif, action: :propose, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do = form_tag(url_for({controller: :recapitulatif, action: :submit, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
%button#action_button.btn.btn-success %button#action_button.btn.btn-success
= 'Soumettre mon dossier' = 'Soumettre mon dossier'
-elsif @dossier.confirmed? -elsif @dossier.confirmed?

View file

@ -26,7 +26,7 @@ Rails.application.routes.draw do
get '/description/error' => 'description#error' get '/description/error' => 'description#error'
post 'description' => 'description#create' post 'description' => 'description#create'
get '/recapitulatif' => 'recapitulatif#show' get '/recapitulatif' => 'recapitulatif#show'
post '/recapitulatif/propose' => 'recapitulatif#propose' post '/recapitulatif/submit' => 'recapitulatif#submit'
post '/recapitulatif/depose' => 'recapitulatif#depose' post '/recapitulatif/depose' => 'recapitulatif#depose'
# get '/demande' => 'demandes#show' # get '/demande' => 'demandes#show'
# post '/demande' => 'demandes#update' # post '/demande' => 'demandes#update'

View file

@ -0,0 +1,5 @@
class ChangeStateProposedToSubmitted < ActiveRecord::Migration
def change
Dossier.where(state: 'proposed').update_all(state: 'submitted')
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20151027150850) do ActiveRecord::Schema.define(version: 20151102101616) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"

View file

@ -32,7 +32,7 @@ describe Backoffice::DossiersController, type: :controller do
describe 'POST #confirme' do describe 'POST #confirme' do
context 'le gestionnaire valide un dossier' do context 'le gestionnaire valide un dossier' do
before do before do
dossier.proposed! dossier.submitted!
sign_in gestionnaire sign_in gestionnaire
end end

View file

@ -49,7 +49,7 @@ RSpec.describe Users::CarteController, type: :controller do
end end
context 'En train de modifier la localisation' do context 'En train de modifier la localisation' do
let(:dossier) { create(:dossier, :with_procedure, :with_user, ref_dossier_carto: ref_dossier_carto, state: 'proposed') } let(:dossier) { create(:dossier, :with_procedure, :with_user, ref_dossier_carto: ref_dossier_carto, state: 'submitted') }
before do before do
post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier_carto: ref_dossier_carto post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier_carto: ref_dossier_carto
end end

View file

@ -65,14 +65,14 @@ describe Users::DescriptionController, type: :controller do
end end
it 'etat du dossier est soumis' do it 'etat du dossier est soumis' do
expect(dossier.state).to eq('proposed') expect(dossier.state).to eq('submitted')
end end
end end
# TODO changer les valeurs des champs et check in bdd # TODO changer les valeurs des champs et check in bdd
context 'En train de manipuler un dossier non brouillon' do context 'En train de manipuler un dossier non brouillon' do
before do before do
dossier.proposed! dossier.submitted!
post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle post :create, dossier_id: dossier_id, nom_projet: nom_projet, description: description, montant_projet: montant_projet, montant_aide_demande: montant_aide_demande, date_previsionnelle: date_previsionnelle
dossier.reload dossier.reload
end end

View file

@ -23,18 +23,18 @@ describe Users::RecapitulatifController, type: :controller do
end end
describe 'POST #propose' do describe 'POST #submit' do
context 'when an user propose his dossier' do context 'when an user submit his dossier' do
before do before do
post :propose, dossier_id: dossier.id post :submit, dossier_id: dossier.id
end end
it 'dossier change his state for processed' do it 'dossier change his state for processed' do
dossier.reload dossier.reload
expect(dossier.state).to eq('proposed') expect(dossier.state).to eq('submitted')
end end
it 'a message informe user what his dossier is proposed' do it 'a message informe user what his dossier is submitted' do
expect(flash[:notice]).to include('Dossier soumis avec succès.') expect(flash[:notice]).to include('Dossier soumis avec succès.')
end end
end end
@ -52,7 +52,7 @@ describe Users::RecapitulatifController, type: :controller do
expect(dossier.state).to eq('deposited') expect(dossier.state).to eq('deposited')
end end
it 'a message informe user what his dossier is proposed' do it 'a message informe user what his dossier is submitted' do
expect(flash[:notice]).to include('Dossier déposé avec succès.') expect(flash[:notice]).to include('Dossier déposé avec succès.')
end end
end end

View file

@ -17,8 +17,8 @@ describe DossierDecorator do
expect(subject).to eq('Brouillon') expect(subject).to eq('Brouillon')
end end
it 'proposed is propose' do it 'submitted is submit' do
dossier.proposed! dossier.submitted!
expect(subject).to eq('Soumis') expect(subject).to eq('Soumis')
end end

View file

@ -122,7 +122,7 @@ describe Dossier do
describe '#next_step' do describe '#next_step' do
let(:dossier) { create(:dossier, :with_user) } let(:dossier) { create(:dossier, :with_user) }
let(:role) { 'user' } let(:role) { 'user' }
let(:action) { 'propose' } let(:action) { 'submit' }
subject { dossier.next_step! role, action } subject { dossier.next_step! role, action }
@ -156,17 +156,17 @@ describe Dossier do
it { is_expected.to eq('draft') } it { is_expected.to eq('draft') }
end end
context 'when he proposes a dossier' do context 'when he submit a dossier' do
let(:action) { 'propose' } let(:action) { 'submit' }
it { is_expected.to eq('proposed') } it { is_expected.to eq('submitted') }
end end
end end
end end
context 'when dossier is at state proposed' do context 'when dossier is at state submitted' do
before do before do
dossier.proposed! dossier.submitted!
end end
context 'when user is connect' do context 'when user is connect' do
@ -175,13 +175,13 @@ describe Dossier do
context 'when is update dossier informations' do context 'when is update dossier informations' do
let(:action) { 'update' } let(:action) { 'update' }
it {is_expected.to eq('proposed')} it {is_expected.to eq('submitted')}
end end
context 'when is post a comment' do context 'when is post a comment' do
let(:action) { 'comment' } let(:action) { 'comment' }
it {is_expected.to eq('proposed')} it {is_expected.to eq('submitted')}
end end
end end
@ -373,8 +373,8 @@ describe Dossier do
context 'gestionnaire backoffice methods' do context 'gestionnaire backoffice methods' do
let!(:dossier1) { create(:dossier, :with_user, :with_procedure, state: 'draft')} let!(:dossier1) { create(:dossier, :with_user, :with_procedure, state: 'draft')}
let!(:dossier2) { create(:dossier, :with_user, :with_procedure, state: 'proposed')} let!(:dossier2) { create(:dossier, :with_user, :with_procedure, state: 'submitted')}
let!(:dossier3) { create(:dossier, :with_user, :with_procedure, state: 'proposed')} let!(:dossier3) { create(:dossier, :with_user, :with_procedure, state: 'submitted')}
let!(:dossier4) { create(:dossier, :with_user, :with_procedure, state: 'reply')} let!(:dossier4) { create(:dossier, :with_user, :with_procedure, state: 'reply')}
let!(:dossier5) { create(:dossier, :with_user, :with_procedure, state: 'updated')} let!(:dossier5) { create(:dossier, :with_user, :with_procedure, state: 'updated')}
let!(:dossier6) { create(:dossier, :with_user, :with_procedure, state: 'confirmed')} let!(:dossier6) { create(:dossier, :with_user, :with_procedure, state: 'confirmed')}

View file

@ -47,9 +47,9 @@ describe 'backoffice/dossiers/show.html.haml', type: :view do
end end
context 'gestion des etats du dossier' do context 'gestion des etats du dossier' do
context 'when dossier have state proposed' do context 'when dossier have state submitted' do
before do before do
dossier.proposed! dossier.submitted!
render render
end end

View file

@ -8,7 +8,7 @@ describe 'backoffice/index.html.haml', type: :view do
assign(:dossiers_en_attente, Dossier.en_attente.decorate) assign(:dossiers_en_attente, Dossier.en_attente.decorate)
assign(:dossiers_termine, Dossier.termine.decorate) assign(:dossiers_termine, Dossier.termine.decorate)
decorate_dossier.proposed! decorate_dossier.submitted!
render render
end end
subject { rendered } subject { rendered }

View file

@ -46,7 +46,7 @@ describe 'users/carte/show.html.haml', type: :view do
end end
context 'si la page précédente est recapitularif' do context 'si la page précédente est recapitularif' do
let(:state) { 'proposed' } let(:state) { 'submitted' }
it 'le bouton "Etape suivante" n\'est pas présent' do it 'le bouton "Etape suivante" n\'est pas présent' do
expect(rendered).to_not have_selector('#etape_suivante') expect(rendered).to_not have_selector('#etape_suivante')

View file

@ -70,7 +70,7 @@ describe 'users/description/show.html.haml', type: :view do
context 'si la page précédente est recapitularif' do context 'si la page précédente est recapitularif' do
before do before do
dossier.proposed! dossier.submitted!
dossier.reload dossier.reload
render render
end end

View file

@ -55,9 +55,9 @@ describe 'users/recapitulatif/show.html.haml', type: :view do
end end
end end
context 'when dossier state is proposed' do context 'when dossier state is submitted' do
before do before do
dossier.proposed! dossier.submitted!
render render
end end