Skip to content

Commit

Permalink
Merge pull request #10013 from mfo/US/fix-broken-validation-email-on-…
Browse files Browse the repository at this point in the history
…load

ETQ usager: fix validation du champ email lorsque l'email n'est pas saisi
  • Loading branch information
mfo authored Feb 19, 2024
2 parents 284ecf8 + 8dc3103 commit b9a8176
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/models/champs/email_champ.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 9 additions & 6 deletions spec/models/champs/email_champ_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit b9a8176

Please sign in to comment.