From 212f431862dcef63ff4533b5b57af9ebf66e5ff3 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 24 Sep 2015 10:18:47 +0200 Subject: [PATCH] Revert "add function "next_step" into dossier model" This reverts commit 4b25696e4808df7e984cd855022d308aed3a1ac5. --- app/models/dossier.rb | 57 +------- spec/models/dossier_spec.rb | 253 ------------------------------------ 2 files changed, 2 insertions(+), 308 deletions(-) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 4c6fb497d..7c4e1ee1a 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -1,10 +1,10 @@ class Dossier < ActiveRecord::Base enum state: { draft: 'draft', - proposed: 'proposed', + submitted: 'submitted', reply: 'reply', updated: 'updated', confirmed: 'confirmed', - deposited: 'deposited', + filed: 'filed', processed: 'processed' } has_one :etablissement @@ -47,59 +47,6 @@ class Dossier < ActiveRecord::Base end end - def next_step! role, action - unless ['propose', 'reply', 'update', 'comment', 'confirme', 'depose', 'process'].include?(action) - fail 'action is not valid' - end - - unless ['user', 'gestionnaire'].include?(role) - fail 'role is not valid' - end - - if role == 'user' - case action - when 'propose' - if draft? - proposed! - end - when 'depose' - if confirmed? - deposited! - end - when 'update' - if reply? - updated! - end - when 'comment' - if reply? - updated! - end - end - elsif role == 'gestionnaire' - case action - when 'comment' - if updated? - reply! - elsif proposed? - reply! - end - when 'confirme' - if updated? - confirmed! - elsif reply? - confirmed! - elsif proposed? - confirmed! - end - when 'process' - if deposited? - processed! - end - end - end - state - end - private def build_default_cerfa diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index eda807c07..7814c87ff 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -115,258 +115,5 @@ describe Dossier do end end end - - #TODO revoir le nommage - describe '#next_step' do - let(:dossier) { create(:dossier) } - let(:role) { 'user' } - let(:action) { 'propose' } - - subject { dossier.next_step! role, action } - - context 'when action is not valid' do - let(:action) { 'test' } - it { expect{ subject }.to raise_error('action is not valid') } - end - - context 'when role is not valid' do - let(:role) { 'test' } - it { expect{ subject }.to raise_error('role is not valid') } - end - - context 'when dossier is at state draft' do - before do - dossier.draft! - end - - context 'when user is connected' do - let(:role) { 'user' } - - context 'when he updates dossier informations' do - let(:action) {'update'} - - it { is_expected.to eq('draft') } - end - - context 'when he posts a comment' do - let(:action) {'comment'} - - it { is_expected.to eq('draft') } - end - - context 'when he proposes a dossier' do - let(:action) { 'propose' } - - it { is_expected.to eq('proposed') } - end - end - end - - context 'when dossier is at state proposed' do - before do - dossier.proposed! - end - - context 'when user is connect' do - let(:role) { 'user' } - - context 'when is update dossier informations' do - let(:action) { 'update' } - - it {is_expected.to eq('proposed')} - end - - context 'when is post a comment' do - let(:action) { 'comment' } - - it {is_expected.to eq('proposed')} - end - end - - context 'when gestionnaire is connect' do - let(:role) { 'gestionnaire' } - - context 'when is post a comment' do - let(:action) { 'comment' } - - it { is_expected.to eq('reply')} - end - - context 'when is confirmed the dossier' do - let(:action) { 'confirme' } - - it {is_expected.to eq('confirmed')} - end - end - end - - context 'when dossier is at state reply' do - before do - dossier.reply! - end - - context 'when user is connect' do - let(:role) { 'user' } - - context 'when is post a comment' do - let(:action) { 'comment' } - - it { is_expected.to eq('updated') } - end - - context 'when is updated dossier informations' do - let(:action) { 'update' } - - it { - - is_expected.to eq('updated') - } - end - end - - context 'when gestionnaire is connect' do - let(:role) { 'gestionnaire' } - - context 'when is post a comment' do - let(:action) { 'comment' } - - it { is_expected.to eq('reply')} - end - - context 'when is confirmed the dossier' do - let(:action) { 'confirme' } - - it {is_expected.to eq('confirmed')} - end - end - end - - context 'when dossier is at state updated' do - before do - dossier.updated! - end - - context 'when user is connect' do - let(:role) { 'user' } - - context 'when is post a comment' do - let(:action) { 'comment' } - - it { is_expected.to eq('updated')} - end - - context 'when is updated dossier informations' do - let(:action) { 'update' } - - it { is_expected.to eq('updated')} - end - end - - context 'when gestionnaire is connect' do - let(:role) { 'gestionnaire' } - - context 'when is post a comment' do - let(:action) { 'comment' } - - it { is_expected.to eq('reply')} - end - - context 'when is confirmed the dossier' do - let(:action) { 'confirme' } - - it {is_expected.to eq('confirmed')} - end - end - end - - context 'when dossier is at state confirmed' do - before do - dossier.confirmed! - end - - context 'when user is connect' do - let(:role) { 'user' } - - context 'when is post a comment' do - let(:action) { 'comment' } - it { is_expected.to eq('confirmed') } - end - - context 'when is deposed the dossier' do - let(:action) { 'depose' } - - it { is_expected.to eq('deposited') } - end - end - - context 'when gestionnaire is connect' do - let(:role) { 'gestionnaire' } - - context 'when is post a comment' do - let(:action) { 'comment' } - - it { is_expected.to eq('confirmed')} - end - end - end - - context 'when dossier is at state deposited' do - before do - dossier.deposited! - end - - context 'when user is connect' do - let(:role) { 'user' } - - context 'when is post a comment' do - let(:action) { 'comment' } - - it { is_expected.to eq('deposited') } - end - end - - context 'when gestionnaire is connect' do - let(:role) { 'gestionnaire' } - - context 'when is post a comment' do - let(:action) { 'comment' } - - it {is_expected.to eq('deposited')} - end - - context 'when is processed the dossier' do - let(:action) { 'process' } - - it {is_expected.to eq('processed')} - end - end - end - - context 'when dossier is at state processed' do - before do - dossier.processed! - end - - context 'when user is connect' do - let(:role) { 'user' } - - context 'when is post a comment' do - let(:action) { 'comment' } - - it { is_expected.to eq('processed')} - end - end - - context 'when gestionnaire is connect' do - let(:role) { 'gestionnaire' } - - context 'when is post a comment' do - let(:action) { 'comment' } - - it { is_expected.to eq('processed')} - end - end - end - end end end