update state date in aasm after callbacks
call aasm event methods, not state methods directly
This commit is contained in:
parent
161b63f487
commit
f631acd118
5 changed files with 52 additions and 41 deletions
|
@ -346,13 +346,14 @@ describe Dossier do
|
|||
let(:state) { Dossier.states.fetch(:brouillon) }
|
||||
let(:dossier) { create(:dossier, state: state) }
|
||||
let(:beginning_of_day) { Time.zone.now.beginning_of_day }
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
|
||||
before { Timecop.freeze(beginning_of_day) }
|
||||
after { Timecop.return }
|
||||
|
||||
context 'when dossier is en_construction' do
|
||||
before do
|
||||
dossier.en_construction!
|
||||
dossier.passer_en_construction!
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
|
@ -361,8 +362,8 @@ describe Dossier do
|
|||
|
||||
it 'should keep first en_construction_at date' do
|
||||
Timecop.return
|
||||
dossier.en_instruction!
|
||||
dossier.en_construction!
|
||||
dossier.passer_en_instruction!(instructeur)
|
||||
dossier.repasser_en_construction!(instructeur)
|
||||
|
||||
expect(dossier.en_construction_at).to eq(beginning_of_day)
|
||||
end
|
||||
|
@ -370,9 +371,10 @@ describe Dossier do
|
|||
|
||||
context 'when dossier is en_instruction' do
|
||||
let(:state) { Dossier.states.fetch(:en_construction) }
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
|
||||
before do
|
||||
dossier.en_instruction!
|
||||
dossier.passer_en_instruction!(instructeur)
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
|
@ -381,39 +383,48 @@ describe Dossier do
|
|||
|
||||
it 'should keep first en_instruction_at date if dossier is set to en_construction again' do
|
||||
Timecop.return
|
||||
dossier.en_construction!
|
||||
dossier.en_instruction!
|
||||
dossier.repasser_en_construction!(instructeur)
|
||||
dossier.passer_en_instruction!(instructeur)
|
||||
|
||||
expect(dossier.en_instruction_at).to eq(beginning_of_day)
|
||||
end
|
||||
end
|
||||
|
||||
shared_examples 'dossier is processed' do |new_state|
|
||||
before do
|
||||
dossier.update(state: new_state)
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.state).to eq(new_state) }
|
||||
it { expect(dossier.processed_at).to eq(beginning_of_day) }
|
||||
end
|
||||
|
||||
context 'when dossier is accepte' do
|
||||
let(:state) { Dossier.states.fetch(:en_instruction) }
|
||||
|
||||
it_behaves_like 'dossier is processed', Dossier.states.fetch(:accepte)
|
||||
before do
|
||||
dossier.accepter!(instructeur, nil, nil)
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.state).to eq(Dossier.states.fetch(:accepte)) }
|
||||
it { expect(dossier.processed_at).to eq(beginning_of_day) }
|
||||
|
||||
end
|
||||
|
||||
context 'when dossier is refuse' do
|
||||
let(:state) { Dossier.states.fetch(:en_instruction) }
|
||||
|
||||
it_behaves_like 'dossier is processed', Dossier.states.fetch(:refuse)
|
||||
before do
|
||||
dossier.refuser!(instructeur, nil, nil)
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.state).to eq(Dossier.states.fetch(:refuse)) }
|
||||
it { expect(dossier.processed_at).to eq(beginning_of_day) }
|
||||
end
|
||||
|
||||
context 'when dossier is sans_suite' do
|
||||
let(:state) { Dossier.states.fetch(:en_instruction) }
|
||||
|
||||
it_behaves_like 'dossier is processed', Dossier.states.fetch(:sans_suite)
|
||||
before do
|
||||
dossier.classer_sans_suite!(instructeur, nil, nil)
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.state).to eq(Dossier.states.fetch(:sans_suite)) }
|
||||
it { expect(dossier.processed_at).to eq(beginning_of_day) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -478,13 +489,14 @@ describe Dossier do
|
|||
describe "#send_dossier_received" do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction)) }
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
|
||||
before do
|
||||
allow(NotificationMailer).to receive(:send_dossier_received).and_return(double(deliver_later: nil))
|
||||
end
|
||||
|
||||
it "sends an email when the dossier becomes en_instruction" do
|
||||
dossier.en_instruction!
|
||||
dossier.passer_en_instruction!(instructeur)
|
||||
expect(NotificationMailer).to have_received(:send_dossier_received).with(dossier)
|
||||
end
|
||||
|
||||
|
@ -777,6 +789,7 @@ describe Dossier do
|
|||
|
||||
describe 'webhook' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
|
||||
it 'should not call webhook' do
|
||||
expect {
|
||||
|
@ -792,7 +805,7 @@ describe Dossier do
|
|||
}.to_not have_enqueued_job(WebHookJob)
|
||||
|
||||
expect {
|
||||
dossier.en_construction!
|
||||
dossier.passer_en_construction!
|
||||
}.to have_enqueued_job(WebHookJob)
|
||||
|
||||
expect {
|
||||
|
@ -800,7 +813,7 @@ describe Dossier do
|
|||
}.to_not have_enqueued_job(WebHookJob)
|
||||
|
||||
expect {
|
||||
dossier.en_instruction!
|
||||
dossier.passer_en_instruction!(instructeur)
|
||||
}.to have_enqueued_job(WebHookJob)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue