models: require belong_to associations on individual
This commit is contained in:
parent
afb1c33154
commit
fe8804f208
5 changed files with 6 additions and 5 deletions
|
@ -12,7 +12,7 @@
|
||||||
# dossier_id :integer
|
# dossier_id :integer
|
||||||
#
|
#
|
||||||
class Individual < ApplicationRecord
|
class Individual < ApplicationRecord
|
||||||
belongs_to :dossier
|
belongs_to :dossier, optional: false
|
||||||
|
|
||||||
validates :dossier_id, uniqueness: true
|
validates :dossier_id, uniqueness: true
|
||||||
validates :gender, presence: true, allow_nil: false, on: :update
|
validates :gender, presence: true, allow_nil: false, on: :update
|
||||||
|
|
|
@ -49,7 +49,7 @@ FactoryBot.define do
|
||||||
if !dossier.procedure.for_individual?
|
if !dossier.procedure.for_individual?
|
||||||
raise 'Inconsistent factory: attempting to create a dossier :with_individual on a procedure that is not `for_individual?`'
|
raise 'Inconsistent factory: attempting to create a dossier :with_individual on a procedure that is not `for_individual?`'
|
||||||
end
|
end
|
||||||
dossier.individual = create(:individual)
|
dossier.individual = build(:individual, dossier: dossier)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,5 +4,6 @@ FactoryBot.define do
|
||||||
nom { 'Julien' }
|
nom { 'Julien' }
|
||||||
prenom { 'Xavier' }
|
prenom { 'Xavier' }
|
||||||
birthdate { Date.new(1991, 11, 01) }
|
birthdate { Date.new(1991, 11, 01) }
|
||||||
|
association :dossier
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,8 +41,8 @@ RSpec.describe DossierHelper, type: :helper do
|
||||||
describe ".demandeur_dossier" do
|
describe ".demandeur_dossier" do
|
||||||
subject { demandeur_dossier(dossier) }
|
subject { demandeur_dossier(dossier) }
|
||||||
|
|
||||||
let(:individual) { create(:individual) }
|
let(:individual) { build(:individual, dossier: nil) }
|
||||||
let(:etablissement) { create(:etablissement) }
|
let(:etablissement) { build(:etablissement) }
|
||||||
let(:dossier) { create(:dossier, procedure: procedure, individual: individual, etablissement: etablissement) }
|
let(:dossier) { create(:dossier, procedure: procedure, individual: individual, etablissement: etablissement) }
|
||||||
|
|
||||||
context "when the dossier is for an individual" do
|
context "when the dossier is for an individual" do
|
||||||
|
|
|
@ -2,7 +2,7 @@ describe Individual do
|
||||||
it { is_expected.to have_db_column(:gender) }
|
it { is_expected.to have_db_column(:gender) }
|
||||||
it { is_expected.to have_db_column(:nom) }
|
it { is_expected.to have_db_column(:nom) }
|
||||||
it { is_expected.to have_db_column(:prenom) }
|
it { is_expected.to have_db_column(:prenom) }
|
||||||
it { is_expected.to belong_to(:dossier) }
|
it { is_expected.to belong_to(:dossier).required }
|
||||||
|
|
||||||
describe "#save" do
|
describe "#save" do
|
||||||
let(:individual) { build(:individual) }
|
let(:individual) { build(:individual) }
|
||||||
|
|
Loading…
Add table
Reference in a new issue