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

This commit is contained in:
Xavier J 2015-11-02 15:31:15 +01:00
parent c09fe8e7f6
commit 285cee939a
19 changed files with 49 additions and 44 deletions

View file

@ -45,7 +45,7 @@ class Users::DescriptionController < UsersController
commentaire.dossier = @dossier
commentaire.save
else
@dossier.submitted!
@dossier.initiated!
end
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)
end
def submit
def initiate
show
@dossier.next_step! 'user', 'submit'
@dossier.next_step! 'user', 'initiate'
flash.notice = 'Dossier soumis avec succès.'
render 'show'

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -65,14 +65,14 @@ describe Users::DescriptionController, type: :controller do
end
it 'etat du dossier est soumis' do
expect(dossier.state).to eq('submitted')
expect(dossier.state).to eq('initiated')
end
end
# TODO changer les valeurs des champs et check in bdd
context 'En train de manipuler un dossier non brouillon' do
before do
dossier.submitted!
dossier.initiated!
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
end

View file

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

View file

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

View file

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

View file

@ -47,9 +47,9 @@ describe 'backoffice/dossiers/show.html.haml', type: :view do
end
context 'gestion des etats du dossier' do
context 'when dossier have state submitted' do
context 'when dossier have state initiated' do
before do
dossier.submitted!
dossier.initiated!
render
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_termine, Dossier.termine.decorate)
decorate_dossier.submitted!
decorate_dossier.initiated!
render
end
subject { rendered }

View file

@ -46,7 +46,7 @@ describe 'users/carte/show.html.haml', type: :view do
end
context 'si la page précédente est recapitularif' do
let(:state) { 'submitted' }
let(:state) { 'initiated' }
it 'le bouton "Etape suivante" n\'est pas présent' do
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
before do
dossier.submitted!
dossier.initiated!
dossier.reload
render
end

View file

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