update controllers specs to use revisions
This commit is contained in:
parent
dee12a2b0b
commit
6a33a8e48b
4 changed files with 122 additions and 119 deletions
|
@ -255,9 +255,8 @@ describe API::V1::DossiersController do
|
|||
end
|
||||
|
||||
describe 'repetition' do
|
||||
let(:procedure) { create(:procedure, administrateur: admin) }
|
||||
let(:champ) { build(:champ_repetition) }
|
||||
let(:dossier) { create(:dossier, :en_construction, champs: [champ], procedure: procedure) }
|
||||
let(:procedure) { create(:procedure, :with_repetition, administrateur: admin) }
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_all_champs, procedure: procedure) }
|
||||
|
||||
subject { super().first[:rows] }
|
||||
|
||||
|
|
|
@ -560,36 +560,34 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
describe "#update_annotations" do
|
||||
let(:procedure) do
|
||||
create(:procedure, :published, types_de_champ_private: [
|
||||
build(:type_de_champ_multiple_drop_down_list, position: 0),
|
||||
build(:type_de_champ_linked_drop_down_list, position: 1),
|
||||
build(:type_de_champ_datetime, position: 2),
|
||||
build(:type_de_champ_repetition, :with_types_de_champ, position: 3)
|
||||
], instructeurs: instructeurs)
|
||||
end
|
||||
let(:dossier) { create(:dossier, :en_construction, :with_all_annotations, procedure: procedure) }
|
||||
let(:now) { Time.zone.parse('01/01/2100') }
|
||||
|
||||
let(:champ_multiple_drop_down_list) do
|
||||
tdc = create(:type_de_champ_multiple_drop_down_list, :private, procedure: procedure, libelle: 'libelle')
|
||||
create(:champ_multiple_drop_down_list, :private, type_de_champ: tdc, dossier: dossier)
|
||||
dossier.champs_private.first
|
||||
end
|
||||
|
||||
let(:champ_linked_drop_down_list) do
|
||||
tdc = create(:type_de_champ_linked_drop_down_list, :private, procedure: procedure, libelle: 'libelle')
|
||||
create(:champ_linked_drop_down_list, :private, type_de_champ: tdc, dossier: dossier)
|
||||
dossier.champs_private.second
|
||||
end
|
||||
|
||||
let(:champ_datetime) do
|
||||
tdc = create(:type_de_champ_datetime, :private, procedure: procedure, libelle: 'libelle')
|
||||
create(:champ_datetime, :private, type_de_champ: tdc, dossier: dossier)
|
||||
dossier.champs_private.third
|
||||
end
|
||||
|
||||
let(:champ_repetition) do
|
||||
tdc = create(:type_de_champ_repetition, :private, :with_types_de_champ, procedure: procedure, libelle: 'libelle')
|
||||
tdc.types_de_champ << create(:type_de_champ_text, procedure: procedure, libelle: 'libelle')
|
||||
champ = create(:champ_repetition, :private, type_de_champ: tdc, dossier: dossier)
|
||||
champ.add_row
|
||||
champ
|
||||
dossier.champs_private.fourth
|
||||
end
|
||||
|
||||
let(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||
|
||||
let(:now) { Time.zone.parse('01/01/2100') }
|
||||
|
||||
before do
|
||||
dossier.champs_private << [champ_multiple_drop_down_list, champ_linked_drop_down_list, champ_datetime, champ_repetition]
|
||||
|
||||
Timecop.freeze(now)
|
||||
patch :update_annotations, params: params
|
||||
|
||||
|
@ -607,64 +605,70 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
let(:params) do
|
||||
{
|
||||
procedure_id: procedure.id,
|
||||
dossier_id: dossier.id,
|
||||
dossier: {
|
||||
champs_private_attributes: {
|
||||
'0': {
|
||||
id: champ_multiple_drop_down_list.id,
|
||||
value: ['', 'un', 'deux']
|
||||
},
|
||||
'1': {
|
||||
id: champ_datetime.id,
|
||||
'value(1i)': 2019,
|
||||
'value(2i)': 12,
|
||||
'value(3i)': 21,
|
||||
'value(4i)': 13,
|
||||
'value(5i)': 17
|
||||
},
|
||||
'2': {
|
||||
id: champ_linked_drop_down_list.id,
|
||||
primary_value: 'primary',
|
||||
secondary_value: 'secondary'
|
||||
},
|
||||
'3': {
|
||||
id: champ_repetition.id,
|
||||
champs_attributes: {
|
||||
id: champ_repetition.champs.first.id,
|
||||
value: 'text'
|
||||
dossier_id: dossier.id,
|
||||
dossier: {
|
||||
champs_private_attributes: {
|
||||
'0': {
|
||||
id: champ_multiple_drop_down_list.id,
|
||||
value: ['', 'un', 'deux']
|
||||
},
|
||||
'1': {
|
||||
id: champ_datetime.id,
|
||||
'value(1i)': 2019,
|
||||
'value(2i)': 12,
|
||||
'value(3i)': 21,
|
||||
'value(4i)': 13,
|
||||
'value(5i)': 17
|
||||
},
|
||||
'2': {
|
||||
id: champ_linked_drop_down_list.id,
|
||||
primary_value: 'primary',
|
||||
secondary_value: 'secondary'
|
||||
},
|
||||
'3': {
|
||||
id: champ_repetition.id,
|
||||
champs_attributes: {
|
||||
id: champ_repetition.champs.first.id,
|
||||
value: 'text'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
it { expect(champ_multiple_drop_down_list.value).to eq('["un", "deux"]') }
|
||||
it { expect(champ_linked_drop_down_list.primary_value).to eq('primary') }
|
||||
it { expect(champ_linked_drop_down_list.secondary_value).to eq('secondary') }
|
||||
it { expect(champ_datetime.value).to eq('21/12/2019 13:17') }
|
||||
it { expect(champ_repetition.champs.first.value).to eq('text') }
|
||||
it { expect(dossier.reload.last_champ_private_updated_at).to eq(now) }
|
||||
it { expect(response).to redirect_to(annotations_privees_instructeur_dossier_path(dossier.procedure, dossier)) }
|
||||
|
||||
it {
|
||||
expect(champ_multiple_drop_down_list.value).to eq('["un", "deux"]')
|
||||
expect(champ_linked_drop_down_list.primary_value).to eq('primary')
|
||||
expect(champ_linked_drop_down_list.secondary_value).to eq('secondary')
|
||||
expect(champ_datetime.value).to eq('21/12/2019 13:17')
|
||||
expect(champ_repetition.champs.first.value).to eq('text')
|
||||
expect(dossier.reload.last_champ_private_updated_at).to eq(now)
|
||||
expect(response).to redirect_to(annotations_privees_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
}
|
||||
end
|
||||
|
||||
context "without new values for champs_private" do
|
||||
let(:params) do
|
||||
{
|
||||
procedure_id: procedure.id,
|
||||
dossier_id: dossier.id,
|
||||
dossier: {
|
||||
champs_private_attributes: {},
|
||||
champs_attributes: {
|
||||
'0': {
|
||||
id: champ_multiple_drop_down_list.id,
|
||||
value: ['', 'un', 'deux']
|
||||
dossier_id: dossier.id,
|
||||
dossier: {
|
||||
champs_private_attributes: {},
|
||||
champs_attributes: {
|
||||
'0': {
|
||||
id: champ_multiple_drop_down_list.id,
|
||||
value: ['', 'un', 'deux']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
it { expect(dossier.reload.last_champ_private_updated_at).to eq(nil) }
|
||||
it { expect(response).to redirect_to(annotations_privees_instructeur_dossier_path(dossier.procedure, dossier)) }
|
||||
|
||||
it {
|
||||
expect(dossier.reload.last_champ_private_updated_at).to eq(nil)
|
||||
expect(response).to redirect_to(annotations_privees_instructeur_dossier_path(dossier.procedure, dossier))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ describe Manager::ProceduresController, type: :controller do
|
|||
describe '#show' do
|
||||
render_views
|
||||
|
||||
let(:procedure) { create(:procedure, :with_repetition) }
|
||||
let(:procedure) { create(:procedure, :published, :with_repetition) }
|
||||
|
||||
before do
|
||||
get :show, params: { id: procedure.id }
|
||||
|
|
|
@ -2,17 +2,17 @@ describe StatsController, type: :controller do
|
|||
describe "#last_four_months_hash" do
|
||||
context "while a regular user is logged in" do
|
||||
before do
|
||||
FactoryBot.create(:procedure, :created_at => 6.months.ago, :updated_at => 6.months.ago)
|
||||
FactoryBot.create(:procedure, :created_at => 2.months.ago, :updated_at => 62.days.ago)
|
||||
FactoryBot.create(:procedure, :created_at => 2.months.ago, :updated_at => 62.days.ago)
|
||||
FactoryBot.create(:procedure, :created_at => 2.months.ago, :updated_at => 31.days.ago)
|
||||
FactoryBot.create(:procedure, :created_at => 2.months.ago, :updated_at => Time.zone.now)
|
||||
create(:procedure, created_at: 6.months.ago, updated_at: 6.months.ago)
|
||||
create(:procedure, created_at: 2.months.ago, updated_at: 62.days.ago)
|
||||
create(:procedure, created_at: 2.months.ago, updated_at: 62.days.ago)
|
||||
create(:procedure, created_at: 2.months.ago, updated_at: 31.days.ago)
|
||||
create(:procedure, created_at: 2.months.ago, updated_at: Time.zone.now)
|
||||
@controller = StatsController.new
|
||||
|
||||
allow(@controller).to receive(:administration_signed_in?).and_return(false)
|
||||
end
|
||||
|
||||
let (:association) { Procedure.all }
|
||||
let(:association) { Procedure.all }
|
||||
|
||||
subject { @controller.send(:last_four_months_hash, association, :updated_at) }
|
||||
|
||||
|
@ -26,10 +26,10 @@ describe StatsController, type: :controller do
|
|||
|
||||
context "while a super admin is logged in" do
|
||||
before do
|
||||
FactoryBot.create(:procedure, :updated_at => 6.months.ago)
|
||||
FactoryBot.create(:procedure, :updated_at => 45.days.ago)
|
||||
FactoryBot.create(:procedure, :updated_at => 1.day.ago)
|
||||
FactoryBot.create(:procedure, :updated_at => 1.day.ago)
|
||||
create(:procedure, updated_at: 6.months.ago)
|
||||
create(:procedure, updated_at: 45.days.ago)
|
||||
create(:procedure, updated_at: 1.day.ago)
|
||||
create(:procedure, updated_at: 1.day.ago)
|
||||
|
||||
@controller = StatsController.new
|
||||
|
||||
|
@ -52,11 +52,11 @@ describe StatsController, type: :controller do
|
|||
describe '#cumulative_hash' do
|
||||
before do
|
||||
Timecop.freeze(Time.zone.local(2016, 10, 2))
|
||||
FactoryBot.create(:procedure, :created_at => 55.days.ago, :updated_at => 43.days.ago)
|
||||
FactoryBot.create(:procedure, :created_at => 45.days.ago, :updated_at => 40.days.ago)
|
||||
FactoryBot.create(:procedure, :created_at => 45.days.ago, :updated_at => 20.days.ago)
|
||||
FactoryBot.create(:procedure, :created_at => 15.days.ago, :updated_at => 20.days.ago)
|
||||
FactoryBot.create(:procedure, :created_at => 15.days.ago, :updated_at => 1.hour.ago)
|
||||
create(:procedure, created_at: 55.days.ago, updated_at: 43.days.ago)
|
||||
create(:procedure, created_at: 45.days.ago, updated_at: 40.days.ago)
|
||||
create(:procedure, created_at: 45.days.ago, updated_at: 20.days.ago)
|
||||
create(:procedure, created_at: 15.days.ago, updated_at: 20.days.ago)
|
||||
create(:procedure, created_at: 15.days.ago, updated_at: 1.hour.ago)
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
|
@ -104,24 +104,24 @@ describe StatsController, type: :controller do
|
|||
# dossier_p1_c: 5 days
|
||||
|
||||
before do
|
||||
procedure_1 = FactoryBot.create(:procedure)
|
||||
procedure_2 = FactoryBot.create(:procedure)
|
||||
dossier_p1_a = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 3.days)
|
||||
dossier_p1_b = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 1.day)
|
||||
dossier_p1_c = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:en_construction_at => 1.month.ago.beginning_of_month,
|
||||
:processed_at => 1.month.ago.beginning_of_month + 5.days)
|
||||
dossier_p2_a = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_2,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 4.days)
|
||||
procedure_1 = create(:procedure)
|
||||
procedure_2 = create(:procedure)
|
||||
dossier_p1_a = create(:dossier, :accepte,
|
||||
procedure: procedure_1,
|
||||
en_construction_at: 2.months.ago.beginning_of_month,
|
||||
processed_at: 2.months.ago.beginning_of_month + 3.days)
|
||||
dossier_p1_b = create(:dossier, :accepte,
|
||||
procedure: procedure_1,
|
||||
en_construction_at: 2.months.ago.beginning_of_month,
|
||||
processed_at: 2.months.ago.beginning_of_month + 1.day)
|
||||
dossier_p1_c = create(:dossier, :accepte,
|
||||
procedure: procedure_1,
|
||||
en_construction_at: 1.month.ago.beginning_of_month,
|
||||
processed_at: 1.month.ago.beginning_of_month + 5.days)
|
||||
dossier_p2_a = create(:dossier, :accepte,
|
||||
procedure: procedure_2,
|
||||
en_construction_at: 2.months.ago.beginning_of_month,
|
||||
processed_at: 2.months.ago.beginning_of_month + 4.days)
|
||||
|
||||
@expected_hash = {
|
||||
(2.months.ago.beginning_of_month).to_s => 3.0,
|
||||
|
@ -149,28 +149,28 @@ describe StatsController, type: :controller do
|
|||
# dossier_p1_c: 50 minutes
|
||||
|
||||
before do
|
||||
procedure_1 = FactoryBot.create(:procedure, :with_type_de_champ, :types_de_champ_count => 24)
|
||||
procedure_2 = FactoryBot.create(:procedure, :with_type_de_champ, :types_de_champ_count => 48)
|
||||
dossier_p1_a = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:created_at => 2.months.ago.beginning_of_month,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month + 30.minutes,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 1.day)
|
||||
dossier_p1_b = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:created_at => 2.months.ago.beginning_of_month,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month + 10.minutes,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 1.day)
|
||||
dossier_p1_c = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:created_at => 1.month.ago.beginning_of_month,
|
||||
:en_construction_at => 1.month.ago.beginning_of_month + 50.minutes,
|
||||
:processed_at => 1.month.ago.beginning_of_month + 1.day)
|
||||
dossier_p2_a = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_2,
|
||||
:created_at => 2.months.ago.beginning_of_month,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month + 80.minutes,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 1.day)
|
||||
procedure_1 = create(:procedure, :with_type_de_champ, types_de_champ_count: 24)
|
||||
procedure_2 = create(:procedure, :with_type_de_champ, types_de_champ_count: 48)
|
||||
dossier_p1_a = create(:dossier, :accepte,
|
||||
procedure: procedure_1,
|
||||
created_at: 2.months.ago.beginning_of_month,
|
||||
en_construction_at: 2.months.ago.beginning_of_month + 30.minutes,
|
||||
processed_at: 2.months.ago.beginning_of_month + 1.day)
|
||||
dossier_p1_b = create(:dossier, :accepte,
|
||||
procedure: procedure_1,
|
||||
created_at: 2.months.ago.beginning_of_month,
|
||||
en_construction_at: 2.months.ago.beginning_of_month + 10.minutes,
|
||||
processed_at: 2.months.ago.beginning_of_month + 1.day)
|
||||
dossier_p1_c = create(:dossier, :accepte,
|
||||
procedure: procedure_1,
|
||||
created_at: 1.month.ago.beginning_of_month,
|
||||
en_construction_at: 1.month.ago.beginning_of_month + 50.minutes,
|
||||
processed_at: 1.month.ago.beginning_of_month + 1.day)
|
||||
dossier_p2_a = create(:dossier, :accepte,
|
||||
procedure: procedure_2,
|
||||
created_at: 2.months.ago.beginning_of_month,
|
||||
en_construction_at: 2.months.ago.beginning_of_month + 80.minutes,
|
||||
processed_at: 2.months.ago.beginning_of_month + 1.day)
|
||||
|
||||
@expected_hash = {
|
||||
(2.months.ago.beginning_of_month).to_s => 30.0,
|
||||
|
|
Loading…
Reference in a new issue