2024-02-09 09:56:03 +01:00
|
|
|
|
describe Champs::EmailChamp do
|
|
|
|
|
describe 'validation' do
|
|
|
|
|
let(:now) { Time.zone.now }
|
|
|
|
|
let(:before) { now + 1.day }
|
|
|
|
|
let(:after) { now + 1.day }
|
2024-02-15 09:45:20 +01:00
|
|
|
|
let(:champ) { build(:champ_email, value: value) }
|
|
|
|
|
|
|
|
|
|
subject { champ.valid?(:validate_champ_value) }
|
2024-02-09 09:56:03 +01:00
|
|
|
|
|
|
|
|
|
context 'when value is username' do
|
|
|
|
|
let(:value) { 'username' }
|
|
|
|
|
# what we allowed but it was a mistake
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
|
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 }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when value include an alias' do
|
|
|
|
|
let(:value) { 'username+alias@mailserver.fr' }
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when value includes accents' do
|
|
|
|
|
let(:value) { 'tech@démarches.gouv.fr' }
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when value is the classic standard user@domain.ext' do
|
|
|
|
|
let(:value) { 'username@mailserver.domain' }
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
|
end
|
2024-02-15 09:45:20 +01:00
|
|
|
|
|
|
|
|
|
context 'when value contains white spaces plus a standard email' do
|
|
|
|
|
let(:value) { "\r\n\t username@mailserver.domain\r\n\t " }
|
|
|
|
|
it { is_expected.to be_truthy }
|
|
|
|
|
it 'normalize value' do
|
|
|
|
|
expect { subject }.to change { champ.value }.from(value).to('username@mailserver.domain')
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-02-09 09:56:03 +01:00
|
|
|
|
end
|
|
|
|
|
end
|