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:
commit
b9a8176f3e
2 changed files with 10 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
class Champs::EmailChamp < Champs::TextChamp
|
class Champs::EmailChamp < Champs::TextChamp
|
||||||
include EmailSanitizableConcern
|
include EmailSanitizableConcern
|
||||||
before_validation -> { sanitize_email(:value) }
|
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
|
end
|
||||||
|
|
|
@ -1,22 +1,25 @@
|
||||||
describe Champs::EmailChamp do
|
describe Champs::EmailChamp do
|
||||||
describe 'validation' 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) }
|
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
|
context 'when value is username' do
|
||||||
let(:value) { 'username' }
|
let(:value) { 'username' }
|
||||||
# what we allowed but it was a mistake
|
# what we allowed but it was a mistake
|
||||||
it { is_expected.to be_truthy }
|
it { is_expected.to be_falsey }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when value does not contain extension' do
|
context 'when value does not contain extension' do
|
||||||
let(:value) { 'username@mailserver' }
|
let(:value) { 'username@mailserver' }
|
||||||
# what we allowed but it was a mistake
|
# what we allowed but it was a mistake
|
||||||
it { is_expected.to be_truthy }
|
it { is_expected.to be_falsey }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when value include an alias' do
|
context 'when value include an alias' do
|
||||||
|
|
Loading…
Reference in a new issue