Skip to content

Commit 29472ae

Browse files
committed
refactor(validator): rename lenient/legacy to permissive/strict
Same structure, clearer vocabulary: lenient_validate -> permissive_validate, legacy_validate -> strict_validate, lenient_external_data_validation? -> permissive_external_data_validation?.
1 parent 6bc8dbe commit 29472ae

5 files changed

Lines changed: 26 additions & 26 deletions

File tree

app/models/champ.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ class Champ < ApplicationRecord
2929
before_save :nullify_blank_json_columns
3030

3131
# Overridable extension point. Override to true in a champ subclass to opt into
32-
# lenient external data validation (see ExternalDataChampValidator).
33-
def lenient_external_data_validation?
32+
# permissive external data validation (see ExternalDataChampValidator).
33+
def permissive_external_data_validation?
3434
false
3535
end
3636

app/models/champs/siret_champ.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def has_async_external_data?
1111

1212
# A condition based on one of this champ's columns (value_json) cannot be
1313
# evaluated until the data is fetched: restore the blocking validation.
14-
def lenient_external_data_validation?
14+
def permissive_external_data_validation?
1515
!external_data_required_for_conditions?
1616
end
1717

app/validators/external_data_champ_validator.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
class ExternalDataChampValidator < ActiveModel::Validator
44
# Required checks are delegated to check_mandatory_and_visible_champs_public.
55
def validate(record)
6-
if record.lenient_external_data_validation?
7-
lenient_validate(record)
6+
if record.permissive_external_data_validation?
7+
permissive_validate(record)
88
else
9-
legacy_validate(record)
9+
strict_validate(record)
1010
end
1111
end
1212

1313
private
1414

1515
# Historical behavior: any pending or external_error blocks submission.
16-
def legacy_validate(record)
16+
def strict_validate(record)
1717
if record.pending?
1818
# User filled the field, but background job is still running.
1919
record.errors.add(:external_id, :api_response_pending)
@@ -23,10 +23,10 @@ def legacy_validate(record)
2323
end
2424
end
2525

26-
# Lenient behavior: only a not-found result (HTTP 404) blocks submission.
26+
# Permissive behavior: only a not-found result (HTTP 404) blocks submission.
2727
# Pending and technical errors let the user submit.
2828
# Exceptions accumulate across retries: only the most recent one is conclusive.
29-
def lenient_validate(record)
29+
def permissive_validate(record)
3030
return unless record.external_data_not_found?
3131

3232
record.errors.add(:value, error_key_for(record, record.fetch_external_data_exceptions.last))

spec/models/champs/siret_champ_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
context 'with a degraded-mode etablissement when the champ feeds a condition' do
9999
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }, { type: :text }]) }
100-
let(:champ) { dossier.champs.find(&:siret?).tap { _1.update(external_id:, etablissement:) } }
100+
let(:champ) { dossier.champ_data.find(&:siret?).tap { _1.update(external_id:, etablissement:) } }
101101
let(:external_id) { "12345678901245" }
102102
let(:etablissement) { Etablissement.new(siret: external_id) }
103103

@@ -234,7 +234,7 @@
234234
describe '#fetch_external_data (result mapping)' do
235235
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) }
236236
let(:dossier) { create(:dossier, procedure:) }
237-
let(:champ) { dossier.champs.first }
237+
let(:champ) { dossier.champ_data.first }
238238
before { champ.update_column(:external_id, '12345678901234') }
239239

240240
context 'when API returns not_found' do
@@ -295,7 +295,7 @@
295295
describe '#handle_exhausted_external_data_retries!' do
296296
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }]) }
297297
let(:dossier) { create(:dossier, procedure:) }
298-
let(:champ) { dossier.champs.first }
298+
let(:champ) { dossier.champ_data.first }
299299

300300
before do
301301
champ.update_columns(
@@ -319,7 +319,7 @@
319319
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }, { type: :text }]) }
320320
let(:siret_tdc) { procedure.draft_revision.types_de_champ_public.first }
321321
let(:text_tdc) { procedure.draft_revision.types_de_champ_public.second }
322-
let(:champ) { dossier.champs.find(&:siret?) }
322+
let(:champ) { dossier.champ_data.find(&:siret?) }
323323

324324
context 'when no other champ has a condition based on the siret champ' do
325325
it { expect(champ.external_data_required_for_conditions?).to be false }
@@ -335,12 +335,12 @@
335335
end
336336
end
337337

338-
describe '#lenient_external_data_validation?' do
338+
describe '#permissive_external_data_validation?' do
339339
let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :siret }, { type: :text }]) }
340-
let(:champ) { dossier.champs.find(&:siret?) }
340+
let(:champ) { dossier.champ_data.find(&:siret?) }
341341

342-
it 'is lenient by default' do
343-
expect(champ.lenient_external_data_validation?).to be true
342+
it 'is permissive by default' do
343+
expect(champ.permissive_external_data_validation?).to be true
344344
end
345345

346346
context 'when another champ has a condition based on a column of the siret champ' do
@@ -352,7 +352,7 @@
352352
end
353353

354354
it 'restores the blocking validation' do
355-
expect(champ.lenient_external_data_validation?).to be false
355+
expect(champ.permissive_external_data_validation?).to be false
356356
end
357357
end
358358
end

spec/validators/external_data_champ_validator_spec.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
it { expect { validator.validate(champ) }.not_to change { champ.errors.size } }
1313
end
1414

15-
shared_examples 'adds a lenient error' do
15+
shared_examples 'adds a permissive error' do
1616
it { expect { validator.validate(champ) }.to change { champ.errors[:value].size }.by(1) }
1717
end
1818

19-
shared_examples 'adds a legacy error' do
19+
shared_examples 'adds a strict error' do
2020
it { expect { validator.validate(champ) }.to change { champ.errors[:external_id].size }.by(1) }
2121
end
2222

@@ -36,7 +36,7 @@
3636
before do
3737
allow(champ).to receive_messages(pending?: true, external_error?: false, external_data_required_for_conditions?: true)
3838
end
39-
include_examples 'adds a legacy error'
39+
include_examples 'adds a strict error'
4040
end
4141

4242
context 'external_error 404 (not found) and not required for conditions' do
@@ -47,7 +47,7 @@
4747
fetch_external_data_exceptions: [ExternalDataException.new(error: 'NF', code: 404)]
4848
)
4949
end
50-
include_examples 'adds a lenient error'
50+
include_examples 'adds a permissive error'
5151
end
5252

5353
context 'external_error with a technical code and not required for conditions' do
@@ -69,7 +69,7 @@
6969
fetch_external_data_exceptions: [ExternalDataException.new(error: 'boom', code: 503)]
7070
)
7171
end
72-
include_examples 'adds a legacy error'
72+
include_examples 'adds a strict error'
7373
end
7474

7575
context 'external_error with a technical retry followed by a 404 (exceptions accumulate)' do
@@ -83,15 +83,15 @@
8383
]
8484
)
8585
end
86-
include_examples 'adds a lenient error'
86+
include_examples 'adds a permissive error'
8787

8888
it 'uses the error key of the most recent exception' do
8989
validator.validate(champ)
9090
expect(champ.errors.map(&:type)).to include(:code_404)
9191
end
9292
end
9393

94-
context 'external_error with accumulated exceptions and required for conditions (legacy path)' do
94+
context 'external_error with accumulated exceptions and required for conditions (strict path)' do
9595
before do
9696
allow(champ).to receive_messages(
9797
pending?: false, external_error?: true,
@@ -102,7 +102,7 @@
102102
]
103103
)
104104
end
105-
include_examples 'adds a legacy error'
105+
include_examples 'adds a strict error'
106106

107107
it 'uses the error key of the most recent exception' do
108108
validator.validate(champ)

0 commit comments

Comments
 (0)