models: require belong_to associations on assign_to
This commit is contained in:
parent
11456109c0
commit
c1e2928ce7
7 changed files with 25 additions and 25 deletions
|
@ -14,8 +14,8 @@
|
|||
# procedure_id :integer
|
||||
#
|
||||
class AssignTo < ApplicationRecord
|
||||
belongs_to :instructeur
|
||||
belongs_to :groupe_instructeur
|
||||
belongs_to :instructeur, optional: false
|
||||
belongs_to :groupe_instructeur, optional: false
|
||||
has_one :procedure_presentation, dependent: :destroy
|
||||
has_one :procedure, through: :groupe_instructeur
|
||||
|
||||
|
|
|
@ -400,8 +400,8 @@ describe Users::DossiersController, type: :controller do
|
|||
|
||||
before do
|
||||
allow(DossierMailer).to receive(:notify_new_dossier_depose_to_instructeur).and_return(double(deliver_later: nil))
|
||||
create(:assign_to, instructeur: instructeur_with_instant_email_dossier, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: true, groupe_instructeur: dossier.procedure.defaut_groupe_instructeur)
|
||||
create(:assign_to, instructeur: instructeur_without_instant_email_dossier, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: false, groupe_instructeur: dossier.procedure.defaut_groupe_instructeur)
|
||||
create(:assign_to, instructeur: instructeur_with_instant_email_dossier, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: true)
|
||||
create(:assign_to, instructeur: instructeur_without_instant_email_dossier, procedure: dossier.procedure, instant_email_dossier_notifications_enabled: false)
|
||||
end
|
||||
|
||||
it "sends notification mail to instructeurs" do
|
||||
|
@ -838,8 +838,8 @@ describe Users::DossiersController, type: :controller do
|
|||
allow(DossierMailer).to receive(:notify_new_commentaire_to_instructeur).and_return(double(deliver_later: nil))
|
||||
instructeur_with_instant_message.follow(dossier)
|
||||
instructeur_without_instant_message.follow(dossier)
|
||||
create(:assign_to, instructeur: instructeur_with_instant_message, procedure: procedure, instant_email_message_notifications_enabled: true, groupe_instructeur: procedure.defaut_groupe_instructeur)
|
||||
create(:assign_to, instructeur: instructeur_without_instant_message, procedure: procedure, instant_email_message_notifications_enabled: false, groupe_instructeur: procedure.defaut_groupe_instructeur)
|
||||
create(:assign_to, instructeur: instructeur_with_instant_message, procedure: procedure, instant_email_message_notifications_enabled: true)
|
||||
create(:assign_to, instructeur: instructeur_without_instant_message, procedure: procedure, instant_email_message_notifications_enabled: false)
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
|
|
|
@ -1,11 +1,5 @@
|
|||
FactoryBot.define do
|
||||
factory :assign_to do
|
||||
after(:build) do |assign_to, evaluator|
|
||||
if evaluator.groupe_instructeur.persisted?
|
||||
assign_to.groupe_instructeur = evaluator.groupe_instructeur
|
||||
else
|
||||
assign_to.groupe_instructeur = assign_to.procedure.defaut_groupe_instructeur
|
||||
end
|
||||
end
|
||||
groupe_instructeur { procedure.defaut_groupe_instructeur }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
FactoryBot.define do
|
||||
factory :procedure_presentation do
|
||||
assign_to { create(:assign_to, procedure: create(:procedure, :with_type_de_champ)) }
|
||||
transient do
|
||||
procedure { create(:procedure, :with_instructeur, :with_type_de_champ) }
|
||||
end
|
||||
|
||||
assign_to { association :assign_to, procedure: procedure, instructeur: procedure.instructeurs.first }
|
||||
sort { { "table" => "user", "column" => "email", "order" => "asc" } }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
describe AssignTo, type: :model do
|
||||
describe '#procedure_presentation_or_default_and_errors' do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let(:assign_to) { create(:assign_to, procedure: procedure) }
|
||||
let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: create(:instructeur)) }
|
||||
|
||||
let(:procedure_presentation_and_errors) { assign_to.procedure_presentation_or_default_and_errors }
|
||||
let(:procedure_presentation_or_default) { procedure_presentation_and_errors.first }
|
||||
|
|
|
@ -389,7 +389,7 @@ describe Instructeur, type: :model do
|
|||
let(:procedure_to_assign) { create(:procedure) }
|
||||
|
||||
before do
|
||||
create(:assign_to, instructeur: instructeur, procedure: procedure_to_assign, daily_email_notifications_enabled: true, groupe_instructeur: procedure_to_assign.defaut_groupe_instructeur)
|
||||
create(:assign_to, instructeur: instructeur, procedure: procedure_to_assign, daily_email_notifications_enabled: true)
|
||||
end
|
||||
|
||||
context 'when a dossier in construction exists' do
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
describe ProcedurePresentation do
|
||||
let(:procedure) { create(:procedure, :with_type_de_champ, :with_type_de_champ_private) }
|
||||
let(:assign_to) { create(:assign_to, procedure: procedure) }
|
||||
let(:instructeur) { create(:instructeur) }
|
||||
let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) }
|
||||
let(:first_type_de_champ) { assign_to.procedure.types_de_champ.first }
|
||||
let(:first_type_de_champ_id) { first_type_de_champ.id.to_s }
|
||||
let(:procedure_presentation) {
|
||||
ProcedurePresentation.create(
|
||||
create(:procedure_presentation,
|
||||
assign_to: assign_to,
|
||||
displayed_fields: [
|
||||
{ "label" => "test1", "table" => "user", "column" => "email" },
|
||||
|
@ -86,7 +87,7 @@ describe ProcedurePresentation do
|
|||
procedure.types_de_champ_private[3].update_attribute(:type_champ, TypeDeChamp.type_champs.fetch(:explication))
|
||||
end
|
||||
|
||||
subject { create(:procedure_presentation, assign_to: create(:assign_to, procedure: procedure)) }
|
||||
subject { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
it { expect(subject.fields).to eq(expected) }
|
||||
end
|
||||
|
@ -96,7 +97,7 @@ describe ProcedurePresentation do
|
|||
let(:surname_field) { { "label" => "Nom", "table" => "individual", "column" => "nom" } }
|
||||
let(:gender_field) { { "label" => "Civilité", "table" => "individual", "column" => "gender" } }
|
||||
let(:procedure) { create(:procedure, :for_individual) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: create(:assign_to, procedure: procedure)) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
subject { procedure_presentation.fields }
|
||||
|
||||
|
@ -105,7 +106,7 @@ describe ProcedurePresentation do
|
|||
end
|
||||
|
||||
describe "#fields_for_select" do
|
||||
subject { create(:procedure_presentation) }
|
||||
subject { create(:procedure_presentation, assign_to: assign_to) }
|
||||
|
||||
before do
|
||||
allow(subject).to receive(:fields).and_return([
|
||||
|
@ -126,7 +127,7 @@ describe ProcedurePresentation do
|
|||
end
|
||||
|
||||
describe '#get_value' do
|
||||
let(:procedure_presentation) { ProcedurePresentation.create(assign_to: assign_to, displayed_fields: [{ 'table' => table, 'column' => column }]) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, procedure: procedure, assign_to: assign_to, displayed_fields: [{ 'table' => table, 'column' => column }]) }
|
||||
|
||||
subject { procedure_presentation.displayed_field_values(dossier).first }
|
||||
|
||||
|
@ -168,6 +169,7 @@ describe ProcedurePresentation do
|
|||
|
||||
context 'for individual table' do
|
||||
let(:table) { 'individual' }
|
||||
let(:procedure) { create(:procedure, :for_individual, :with_type_de_champ, :with_type_de_champ_private) }
|
||||
let(:dossier) { create(:dossier, procedure: procedure, individual: create(:individual, nom: 'Martin', prenom: 'Jacques', gender: 'M.')) }
|
||||
|
||||
context 'for prenom column' do
|
||||
|
@ -248,7 +250,7 @@ describe ProcedurePresentation do
|
|||
let(:instructeur) { create(:instructeur) }
|
||||
let(:assign_to) { create(:assign_to, procedure: procedure, instructeur: instructeur) }
|
||||
let(:sort) { { 'table' => table, 'column' => column, 'order' => order } }
|
||||
let(:procedure_presentation) { ProcedurePresentation.create(assign_to: assign_to, sort: sort) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to, sort: sort) }
|
||||
|
||||
subject { procedure_presentation.sorted_ids(procedure.dossiers, instructeur) }
|
||||
|
||||
|
@ -416,7 +418,7 @@ describe ProcedurePresentation do
|
|||
end
|
||||
|
||||
describe '#filtered_ids' do
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: create(:assign_to, procedure: procedure), filters: { "suivis" => filter }) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, assign_to: assign_to, filters: { "suivis" => filter }) }
|
||||
|
||||
subject { procedure_presentation.filtered_ids(procedure.dossiers.joins(:user), 'suivis') }
|
||||
|
||||
|
@ -755,7 +757,7 @@ describe ProcedurePresentation do
|
|||
end
|
||||
|
||||
describe '#eager_load_displayed_fields' do
|
||||
let(:procedure_presentation) { ProcedurePresentation.create(assign_to: assign_to, displayed_fields: [{ 'table' => table, 'column' => column }]) }
|
||||
let(:procedure_presentation) { create(:procedure_presentation, procedure: procedure, assign_to: assign_to, displayed_fields: [{ 'table' => table, 'column' => column }]) }
|
||||
let!(:dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||
let(:displayed_dossier) { procedure_presentation.eager_load_displayed_fields(procedure.dossiers).first }
|
||||
|
||||
|
|
Loading…
Reference in a new issue