Merge pull request #8899 from demarches-simplifiees/8738-validate-adresse-electronique
ETQ usager, je veux que les champs de type adresse électronique soit validé
This commit is contained in:
commit
efb98e5c99
4 changed files with 44 additions and 0 deletions
|
@ -21,4 +21,11 @@
|
||||||
# type_de_champ_id :integer
|
# type_de_champ_id :integer
|
||||||
#
|
#
|
||||||
class Champs::EmailChamp < Champs::TextChamp
|
class Champs::EmailChamp < Champs::TextChamp
|
||||||
|
validates :value,
|
||||||
|
format: {
|
||||||
|
with: Devise.email_regexp,
|
||||||
|
message: I18n.t('invalid', scope: 'activerecord.errors.models.email_champ.attributes.value')
|
||||||
|
},
|
||||||
|
allow_nil: true,
|
||||||
|
if: -> { validation_context != :brouillon }
|
||||||
end
|
end
|
||||||
|
|
|
@ -565,6 +565,10 @@ en:
|
||||||
attributes:
|
attributes:
|
||||||
email:
|
email:
|
||||||
taken: ': Invitation already sent'
|
taken: ': Invitation already sent'
|
||||||
|
email_champ:
|
||||||
|
attributes:
|
||||||
|
value:
|
||||||
|
invalid: "is invalid. Fill in a valid email address, example: john.doe@example.fr"
|
||||||
|
|
||||||
user:
|
user:
|
||||||
attributes: &error_attributes
|
attributes: &error_attributes
|
||||||
|
|
|
@ -566,6 +566,10 @@ fr:
|
||||||
attributes:
|
attributes:
|
||||||
email:
|
email:
|
||||||
taken: ': Invitation déjà envoyée'
|
taken: ': Invitation déjà envoyée'
|
||||||
|
email_champ:
|
||||||
|
attributes:
|
||||||
|
value:
|
||||||
|
invalid: "est invalide. Saisir une adresse éléctronique valide, exemple : john.doe@exemple.fr"
|
||||||
user:
|
user:
|
||||||
attributes: &error_attributes
|
attributes: &error_attributes
|
||||||
reset_password_token:
|
reset_password_token:
|
||||||
|
|
29
spec/models/champs/email_champ_spec.rb
Normal file
29
spec/models/champs/email_champ_spec.rb
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
describe Champs::EmailChamp do
|
||||||
|
subject { build(:champ_email, value: value).tap(&:valid?) }
|
||||||
|
|
||||||
|
describe '#valid?' do
|
||||||
|
context 'when the value is an email' do
|
||||||
|
let(:value) { 'jean@dupont.fr' }
|
||||||
|
|
||||||
|
it { is_expected.to be_valid }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the value is not an email' do
|
||||||
|
let(:value) { 'jean@' }
|
||||||
|
|
||||||
|
it { is_expected.to_not be_valid }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the value is blank' do
|
||||||
|
let(:value) { '' }
|
||||||
|
|
||||||
|
it { is_expected.to_not be_valid }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when the value is nil' do
|
||||||
|
let(:value) { nil }
|
||||||
|
|
||||||
|
it { is_expected.to be_valid }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue