2017-05-12 15:47:05 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe ProcedureOverview, type: :model do
|
|
|
|
let(:procedure) { create(:procedure, libelle: 'libelle') }
|
|
|
|
let(:friday) { DateTime.new(2017, 5, 12) } # vendredi 12 mai 2017, de la semaine du 8 mai
|
|
|
|
let(:monday) { DateTime.new(2017, 5, 8) }
|
|
|
|
|
2017-11-29 16:07:39 +01:00
|
|
|
before { Timecop.freeze(friday) }
|
|
|
|
after { Timecop.return }
|
2017-05-12 15:47:05 +02:00
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
let(:procedure_overview) { ProcedureOverview.new(procedure, monday) }
|
2017-05-12 15:47:05 +02:00
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
describe 'dossiers_en_instruction_count' do
|
|
|
|
let!(:en_instruction_dossier) do
|
2017-12-14 15:53:02 +01:00
|
|
|
create(:dossier, procedure: procedure, state: :en_instruction, created_at: monday)
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
it { expect(procedure_overview.dossiers_en_instruction_count).to eq(1) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'old_dossiers_en_instruction' do
|
|
|
|
let!(:old_dossier_en_instruction) do
|
2017-12-14 15:53:02 +01:00
|
|
|
create(:dossier, procedure: procedure, state: :en_instruction, en_instruction_at: monday - 1.month)
|
2017-06-27 18:00:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:dossier_en_instruction) do
|
2017-12-14 15:53:02 +01:00
|
|
|
create(:dossier, procedure: procedure, state: :en_instruction, en_instruction_at: monday)
|
2017-06-27 18:00:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it do
|
|
|
|
expect(procedure_overview.old_dossiers_en_instruction).to match([old_dossier_en_instruction])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'dossiers_en_construction_count' do
|
|
|
|
let!(:dossier_en_construction) do
|
2017-12-14 15:51:45 +01:00
|
|
|
create(:dossier, procedure: procedure, state: :en_construction, created_at: monday)
|
2017-06-27 18:00:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure_overview.dossiers_en_construction_count).to eq(1) }
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'created_dossiers_count' do
|
|
|
|
let!(:created_dossier_during_the_week) do
|
2017-12-14 15:53:02 +01:00
|
|
|
create(:dossier, procedure: procedure, created_at: monday, state: :en_instruction)
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
2017-12-04 16:17:15 +01:00
|
|
|
let!(:created_dossier_during_the_week_but_in_brouillon) do
|
|
|
|
create(:dossier, procedure: procedure, created_at: monday, state: :brouillon)
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
let!(:created_dossier_before_the_week) do
|
2017-12-14 15:53:02 +01:00
|
|
|
create(:dossier, procedure: procedure, created_at: (monday - 1.week), state: :en_instruction)
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(procedure_overview.created_dossiers_count).to eq(1) }
|
|
|
|
end
|
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
describe 'had_some_activities?' do
|
|
|
|
subject { procedure_overview.had_some_activities? }
|
2017-05-12 15:47:05 +02:00
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
before :each do
|
|
|
|
procedure_overview.dossiers_en_instruction_count = 0
|
|
|
|
procedure_overview.dossiers_en_construction_count = 0
|
|
|
|
procedure_overview.created_dossiers_count = 0
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
context 'when there are no activities' do
|
|
|
|
it { is_expected.to be false }
|
|
|
|
end
|
2017-05-12 15:47:05 +02:00
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
context 'when there are some dossiers en instruction' do
|
|
|
|
before { procedure_overview.dossiers_en_instruction_count = 2 }
|
|
|
|
it { is_expected.to be true }
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
context 'when there are some dossiers en construction' do
|
|
|
|
before { procedure_overview.dossiers_en_construction_count = 2 }
|
|
|
|
it { is_expected.to be true }
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
|
2017-06-27 18:00:05 +02:00
|
|
|
context 'when there are some created dossiers' do
|
|
|
|
before { procedure_overview.created_dossiers_count = 2 }
|
|
|
|
it { is_expected.to be true }
|
2017-05-12 15:47:05 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|