4cb747fdb6
Test helpers are separated between two files: spec_helper and rails_helper. This separation is meant to allow tests that do not require Rails (like testing standalone libs) to boot faster. The spec_helper file is always loaded, through `--require spec_helper` in the `.rspec` config file. When needed, the rails_helper file is expected to be required manually. This is fine, but: - Many test files have a redundant `require 'spec_helper'` line; - Many test files should require `rails_helper`, but don't. Not requiring `rails_helper` will cause the Rails-concerned section of the test environment not to be configured–which may cause subtle bugs (like the test database not being properly initialized). Moreover, Spring loads all the Rails files on preloading anyway. So the gains from using only `spec_helper` are thin. To streamline this process, this commit: - Configures `.rspec` to require `rails_helper` by default; - Remove all manual requires to spec_helper or rails_helper. Reference: https://stackoverflow.com/questions/24145329/how-is-spec-rails-helper-rb-different-from-spec-spec-helper-rb-do-i-need-it
106 lines
4.2 KiB
Ruby
106 lines
4.2 KiB
Ruby
describe ProcedureOverview, type: :model do
|
|
let(:procedure) { create(:procedure, libelle: 'libelle') }
|
|
let(:friday) { Time.zone.local(2017, 5, 12) } # vendredi 12 mai 2017, de la semaine du 8 mai
|
|
let(:monday) { Time.zone.local(2017, 5, 8) }
|
|
|
|
before { Timecop.freeze(friday) }
|
|
after { Timecop.return }
|
|
|
|
let(:procedure_overview) { ProcedureOverview.new(procedure, monday, [procedure.defaut_groupe_instructeur]) }
|
|
|
|
describe 'dossiers_en_instruction_count' do
|
|
let!(:en_instruction_dossier) do
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), created_at: monday)
|
|
end
|
|
|
|
it { expect(procedure_overview.dossiers_en_instruction_count).to eq(1) }
|
|
end
|
|
|
|
describe 'old_dossiers_en_instruction' do
|
|
let!(:old_dossier_en_instruction) do
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), en_instruction_at: monday - 1.month)
|
|
end
|
|
|
|
let!(:dossier_en_instruction) do
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_instruction), en_instruction_at: monday)
|
|
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
|
|
create(:dossier, procedure: procedure, state: Dossier.states.fetch(:en_construction), created_at: monday)
|
|
end
|
|
|
|
it { expect(procedure_overview.dossiers_en_construction_count).to eq(1) }
|
|
end
|
|
|
|
describe 'created_dossiers_count' do
|
|
let!(:created_dossier_during_the_week) do
|
|
create(:dossier, procedure: procedure, created_at: monday, state: Dossier.states.fetch(:en_instruction))
|
|
end
|
|
|
|
let!(:created_dossier_during_the_week_but_in_brouillon) do
|
|
create(:dossier, procedure: procedure, created_at: monday, state: Dossier.states.fetch(:brouillon))
|
|
end
|
|
|
|
let!(:created_dossier_before_the_week) do
|
|
create(:dossier, procedure: procedure, created_at: (monday - 1.week), state: Dossier.states.fetch(:en_instruction))
|
|
end
|
|
|
|
it { expect(procedure_overview.created_dossiers_count).to eq(1) }
|
|
end
|
|
|
|
describe 'with a procedure routee' do
|
|
let!(:gi_2) { procedure.groupe_instructeurs.create(label: 'groupe instructeur 2') }
|
|
let!(:gi_3) { procedure.groupe_instructeurs.create(label: 'groupe instructeur 3') }
|
|
|
|
def create_dossier_in_group(g)
|
|
create(:dossier, procedure: procedure, created_at: monday, state: Dossier.states.fetch(:en_instruction), groupe_instructeur: g)
|
|
end
|
|
|
|
let!(:created_dossier_during_the_week_on_group_2) { create_dossier_in_group(gi_2) }
|
|
let!(:created_dossier_during_the_week_on_group_3_a) { create_dossier_in_group(gi_3) }
|
|
let!(:created_dossier_during_the_week_on_group_3_b) { create_dossier_in_group(gi_3) }
|
|
|
|
let(:procedure_overview_gi_2) { ProcedureOverview.new(procedure, monday, [gi_2]) }
|
|
let(:procedure_overview_gi_3) { ProcedureOverview.new(procedure, monday, [gi_3]) }
|
|
let(:procedure_overview_default) { ProcedureOverview.new(procedure, monday, [procedure.defaut_groupe_instructeur]) }
|
|
|
|
it { expect(procedure_overview_gi_2.created_dossiers_count).to eq(1) }
|
|
it { expect(procedure_overview_gi_3.created_dossiers_count).to eq(2) }
|
|
it { expect(procedure_overview_default.created_dossiers_count).to eq(0) }
|
|
end
|
|
|
|
describe 'had_some_activities?' do
|
|
subject { procedure_overview.had_some_activities? }
|
|
|
|
before :each do
|
|
procedure_overview.dossiers_en_instruction_count = 0
|
|
procedure_overview.dossiers_en_construction_count = 0
|
|
procedure_overview.created_dossiers_count = 0
|
|
end
|
|
|
|
context 'when there are no activities' do
|
|
it { is_expected.to be false }
|
|
end
|
|
|
|
context 'when there are some dossiers en instruction' do
|
|
before { procedure_overview.dossiers_en_instruction_count = 2 }
|
|
it { is_expected.to be true }
|
|
end
|
|
|
|
context 'when there are some dossiers en construction' do
|
|
before { procedure_overview.dossiers_en_construction_count = 2 }
|
|
it { is_expected.to be true }
|
|
end
|
|
|
|
context 'when there are some created dossiers' do
|
|
before { procedure_overview.created_dossiers_count = 2 }
|
|
it { is_expected.to be true }
|
|
end
|
|
end
|
|
end
|