diff --git a/app/models/champs/email_champ.rb b/app/models/champs/email_champ.rb index d52462606..5dfcff902 100644 --- a/app/models/champs/email_champ.rb +++ b/app/models/champs/email_champ.rb @@ -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 diff --git a/spec/models/champs/email_champ_spec.rb b/spec/models/champs/email_champ_spec.rb index f655dd4a7..87233854b 100644 --- a/spec/models/champs/email_champ_spec.rb +++ b/spec/models/champs/email_champ_spec.rb @@ -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