2024-04-29 00:17:15 +02:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2018-02-28 16:23:50 +01:00
|
|
|
|
describe EmailSanitizableConcern, type: :model do
|
|
|
|
|
describe 'sanitize_email' do
|
|
|
|
|
let(:email_concern) do
|
|
|
|
|
(Class.new do
|
2018-09-20 14:34:49 +02:00
|
|
|
|
include EmailSanitizableConcern
|
|
|
|
|
attr_accessor :email
|
2018-02-28 16:23:50 +01:00
|
|
|
|
|
2018-09-20 14:34:49 +02:00
|
|
|
|
def initialize(email)
|
|
|
|
|
self.email = email
|
|
|
|
|
end
|
2018-02-28 16:23:50 +01:00
|
|
|
|
|
2018-09-20 14:34:49 +02:00
|
|
|
|
def [](key)
|
|
|
|
|
self.send(key)
|
|
|
|
|
end
|
2018-02-28 16:23:50 +01:00
|
|
|
|
|
2018-09-20 14:34:49 +02:00
|
|
|
|
def []=(key, value)
|
|
|
|
|
self.send("#{key}=", value)
|
|
|
|
|
end
|
|
|
|
|
end).new(email)
|
2018-02-28 16:23:50 +01:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
before do
|
|
|
|
|
email_concern.sanitize_email(:email)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'on an empty email' do
|
|
|
|
|
let(:email) { '' }
|
|
|
|
|
it { expect(email_concern.email).to eq('') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'on a valid email' do
|
|
|
|
|
let(:email) { 'michel@toto.fr' }
|
|
|
|
|
it { expect(email_concern.email).to eq('michel@toto.fr') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'on an email with trailing spaces' do
|
|
|
|
|
let(:email) { ' michel@toto.fr ' }
|
|
|
|
|
it { expect(email_concern.email).to eq('michel@toto.fr') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'on an email with trailing nbsp' do
|
|
|
|
|
let(:email) { ' michel@toto.fr ' }
|
|
|
|
|
it { expect(email_concern.email).to eq('michel@toto.fr') }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'on an invalid email' do
|
|
|
|
|
let(:email) { 'mich el@toto.fr' }
|
|
|
|
|
it { expect(email_concern.email).to eq('mich el@toto.fr') }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|