Merge pull request #10013 from mfo/US/fix-broken-validation-email-on-load

ETQ usager: fix validation du champ email lorsque l'email n'est pas saisi
This commit is contained in:
mfo 2024-02-19 15:29:02 +01:00 committed by GitHub
commit b9a8176f3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 7 deletions

View file

@ -1,5 +1,5 @@
class Champs::EmailChamp < Champs::TextChamp
include EmailSanitizableConcern
before_validation -> { sanitize_email(:value) }
validates :value, format: { with: StrictEmailValidator::REGEXP }, if: :validate_champ_value?
validates :value, allow_blank: true, format: { with: StrictEmailValidator::REGEXP }, if: :validate_champ_value?
end

View file

@ -1,22 +1,25 @@
describe Champs::EmailChamp do
describe 'validation' do
let(:now) { Time.zone.now }
let(:before) { now + 1.day }
let(:after) { now + 1.day }
let(:champ) { build(:champ_email, value: value) }
subject { champ.valid?(:validate_champ_value) }
subject { champ.validate(:champs_public_value) }
context 'when nil' do
let(:value) { nil }
it { is_expected.to be_truthy }
end
context 'when value is username' do
let(:value) { 'username' }
# what we allowed but it was a mistake
it { is_expected.to be_truthy }
it { is_expected.to be_falsey }
end
context 'when value does not contain extension' do
let(:value) { 'username@mailserver' }
# what we allowed but it was a mistake
it { is_expected.to be_truthy }
it { is_expected.to be_falsey }
end
context 'when value include an alias' do