2016-09-08 16:21:54 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe DossiersListFacades do
|
|
|
|
|
|
|
|
let(:gestionnaire) { create :gestionnaire }
|
|
|
|
let(:procedure) { create :procedure }
|
2016-09-09 17:29:21 +02:00
|
|
|
let(:procedure_2) { create :procedure, libelle: 'plop' }
|
2016-09-08 16:21:54 +02:00
|
|
|
|
2016-10-14 12:02:39 +02:00
|
|
|
let!(:preference) { create :preference_list_dossier,
|
|
|
|
gestionnaire: gestionnaire,
|
|
|
|
table: nil,
|
|
|
|
attr: 'state',
|
|
|
|
attr_decorate: 'display_state' }
|
|
|
|
|
|
|
|
let!(:preference_2) { create :preference_list_dossier,
|
|
|
|
gestionnaire: gestionnaire,
|
|
|
|
table: 'champs',
|
|
|
|
attr: 'state',
|
|
|
|
attr_decorate: 'display_state',
|
|
|
|
procedure_id: procedure.id }
|
|
|
|
|
2016-09-08 16:21:54 +02:00
|
|
|
before do
|
2016-09-09 17:29:21 +02:00
|
|
|
create :assign_to, procedure: procedure, gestionnaire: gestionnaire
|
|
|
|
create :assign_to, procedure: procedure_2, gestionnaire: gestionnaire
|
2016-09-08 16:21:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
describe '#preference_list_dossiers_filter' do
|
|
|
|
|
|
|
|
subject { facade.preference_list_dossiers_filter }
|
|
|
|
|
|
|
|
context 'when procedure is not pasted at the facade' do
|
|
|
|
let(:facade) { described_class.new gestionnaire, 'nouveaux' }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq 6 }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when procedure is pasted at the facade' do
|
|
|
|
let(:facade) { described_class.new gestionnaire, 'nouveaux', procedure }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq 1 }
|
|
|
|
end
|
|
|
|
end
|
2016-09-09 17:29:21 +02:00
|
|
|
|
|
|
|
describe '#gestionnaire_procedures_name_and_id_list' do
|
|
|
|
let(:facade) { described_class.new gestionnaire, 'nouveaux' }
|
|
|
|
|
|
|
|
subject { facade.gestionnaire_procedures_name_and_id_list }
|
|
|
|
|
|
|
|
it { expect(subject.size).to eq 2 }
|
|
|
|
|
|
|
|
it { expect(subject.first[:id]).to eq procedure.id }
|
|
|
|
it { expect(subject.first[:libelle]).to eq procedure.libelle }
|
2016-12-26 17:25:59 +01:00
|
|
|
it { expect(subject.first[:notification_unread]).to eq 0 }
|
|
|
|
|
2016-09-09 17:29:21 +02:00
|
|
|
|
|
|
|
it { expect(subject.last[:id]).to eq procedure_2.id }
|
|
|
|
it { expect(subject.last[:libelle]).to eq procedure_2.libelle }
|
2016-12-26 17:25:59 +01:00
|
|
|
it { expect(subject.last[:notification_unread]).to eq 0 }
|
2016-09-09 17:29:21 +02:00
|
|
|
end
|
2016-10-14 12:02:39 +02:00
|
|
|
|
|
|
|
describe '#active_filter?' do
|
|
|
|
let(:table) { nil }
|
|
|
|
let(:filter) { nil }
|
|
|
|
let(:facade) { described_class.new gestionnaire, 'nouveaux', procedure_2 }
|
|
|
|
|
|
|
|
let!(:preference) { create :preference_list_dossier,
|
|
|
|
gestionnaire: gestionnaire,
|
|
|
|
table: table,
|
|
|
|
attr: 'state',
|
|
|
|
attr_decorate: 'display_state',
|
|
|
|
filter: filter,
|
|
|
|
procedure_id: procedure_id }
|
|
|
|
|
|
|
|
subject { facade.active_filter? preference }
|
|
|
|
|
|
|
|
context 'when gestionnaire does not have select a procedure' do
|
|
|
|
let(:procedure_2) { nil }
|
|
|
|
let(:procedure_id) { nil }
|
|
|
|
|
|
|
|
it { expect(preference.procedure).to be_nil }
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire have select a procedure' do
|
|
|
|
let(:procedure_id) { procedure_2.id }
|
|
|
|
|
|
|
|
it { expect(preference.procedure).not_to be_nil }
|
|
|
|
|
|
|
|
context 'when preference is not a champs filter' do
|
|
|
|
let(:table) { 'entreprises' }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire have an existant filter with a champ' do
|
|
|
|
let(:table) { 'champs' }
|
|
|
|
let(:filter) { 'plop' }
|
|
|
|
|
|
|
|
context 'when the preference is the existant champ filter' do
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the preference is not the existant champ filter' do
|
|
|
|
let(:preference) { preference_2 }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create :preference_list_dossier,
|
|
|
|
gestionnaire: gestionnaire,
|
|
|
|
table: 'champs',
|
|
|
|
attr: 'state',
|
|
|
|
attr_decorate: 'display_state',
|
|
|
|
filter: 'plop',
|
|
|
|
procedure_id: procedure_id
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to be_falsey }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when gestionnaire does not have an existant filter with a champ' do
|
|
|
|
let(:table) { nil }
|
|
|
|
let(:filter) { 'plop' }
|
|
|
|
|
|
|
|
context 'when the preference is the existant preference filter' do
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the preference is not the existant preference filter' do
|
|
|
|
let(:preference) { preference_2 }
|
|
|
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-09-08 16:21:54 +02:00
|
|
|
end
|