fix(champ): always check if a champ is in a valid revision before validate
This commit is contained in:
parent
b8481796c7
commit
b3701a12b4
30 changed files with 107 additions and 75 deletions
|
@ -1,9 +1,18 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
describe Champs::DossierLinkChamp, type: :model do
|
||||
let(:champ) { Champs::DossierLinkChamp.new(value:, dossier: build(:dossier)) }
|
||||
let(:mandatory) { false }
|
||||
|
||||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_dossier_link, mandatory:))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
end
|
||||
|
||||
describe 'prefilling validations' do
|
||||
let(:linked_dossier) { create(:dossier) }
|
||||
describe 'value' do
|
||||
subject { described_class.new(value:, dossier: build(:dossier)).valid?(:prefill) }
|
||||
subject { champ.valid?(:prefill) }
|
||||
|
||||
context 'when nil' do
|
||||
let(:value) { nil }
|
||||
|
@ -18,13 +27,13 @@ describe Champs::DossierLinkChamp, type: :model do
|
|||
end
|
||||
|
||||
context 'when an integer' do
|
||||
let(:value) { 42 }
|
||||
let(:value) { linked_dossier.id }
|
||||
|
||||
it { expect(subject).to eq(true) }
|
||||
end
|
||||
|
||||
context 'when a string representing an integer' do
|
||||
let(:value) { "42" }
|
||||
let(:value) { linked_dossier.id.to_s }
|
||||
|
||||
it { expect(subject).to eq(true) }
|
||||
end
|
||||
|
@ -38,14 +47,7 @@ describe Champs::DossierLinkChamp, type: :model do
|
|||
end
|
||||
|
||||
describe 'validation' do
|
||||
let(:champ) { Champs::DossierLinkChamp.new(value:, dossier: build(:dossier)) }
|
||||
|
||||
before do
|
||||
allow(champ).to receive(:type_de_champ).and_return(build(:type_de_champ_dossier_link, mandatory:))
|
||||
allow(champ).to receive(:in_dossier_revision?).and_return(true)
|
||||
champ.run_callbacks(:validation)
|
||||
end
|
||||
|
||||
before { champ.run_callbacks(:validation) }
|
||||
subject { champ.validate(:champs_public_value) }
|
||||
|
||||
context 'when not mandatory' do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue