fix: do not allow empty filter in models

This commit is contained in:
simon lehericey 2024-10-24 11:16:12 +02:00
parent c56aa67297
commit b22f049318
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
6 changed files with 46 additions and 13 deletions

View file

@ -11,7 +11,7 @@ describe FilteredColumn do
let(:filter) { 'a' * (FilteredColumn::FILTERS_VALUE_MAX_LENGTH + 1) }
it 'adds an error' do
expect(filtered_column.errors.map(&:message)).to include(/Le filtre label est trop long/)
expect(filtered_column.errors.map(&:message)).to include(/Le filtre « label » est trop long/)
end
end
@ -22,14 +22,6 @@ describe FilteredColumn do
expect(filtered_column.errors).to be_empty
end
end
context 'when the filter is empty' do
let(:filter) { nil }
it 'does not add an error' do
expect(filtered_column.errors).to be_empty
end
end
end
describe '#check_filters_max_integer' do
@ -43,7 +35,7 @@ describe FilteredColumn do
let(:filter) { (FilteredColumn::PG_INTEGER_MAX_VALUE + 1).to_s }
it 'adds an error' do
expect(filtered_column.errors.map(&:message)).to include(/Le filtre label n'est pas un numéro de dossier possible/)
expect(filtered_column.errors.map(&:message)).to include(/Le filtre « label » n'est pas un numéro de dossier possible/)
end
end
@ -56,4 +48,27 @@ describe FilteredColumn do
end
end
end
describe '#check_filter_is_not_blank' do
let(:column) { Column.new(procedure_id: 1, table: 'table', column: 'column', label: 'label') }
let(:filtered_column) { described_class.new(column:, filter:) }
before { filtered_column.valid? }
context 'when the filter is blank' do
let(:filter) { '' }
it 'adds an error' do
expect(filtered_column.errors.map(&:message)).to include(/Le filtre « label » ne peut pas être vide/)
end
end
context 'when the filter is not blank' do
let(:filter) { 'a' }
it 'does not add an error' do
expect(filtered_column.errors).to be_empty
end
end
end
end