2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
# Specifications for behavior common to all objects with an email attribute.
|
|
|
|
# Takes a list of email-format attributes and requires:
|
|
|
|
# - subject { "the object with a attribute= setter" }
|
|
|
|
# Note: You have access to `email_value` which is the email address value
|
|
|
|
# being currently tested).
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
RSpec.shared_examples 'an object with email-formatted attributes' do |*attributes|
|
2016-04-02 18:10:28 +05:30
|
|
|
attributes.each do |attribute|
|
|
|
|
describe "specifically its :#{attribute} attribute" do
|
|
|
|
%w[
|
|
|
|
info@example.com
|
|
|
|
info+test@example.com
|
|
|
|
o'reilly@example.com
|
|
|
|
mailto:test@example.com
|
|
|
|
lol!'+=?><#$%^&*()@gmail.com
|
|
|
|
].each do |valid_email|
|
|
|
|
context "with a value of '#{valid_email}'" do
|
|
|
|
let(:email_value) { valid_email }
|
|
|
|
|
|
|
|
it 'is valid' do
|
|
|
|
subject.send("#{attribute}=", valid_email)
|
|
|
|
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%w[
|
|
|
|
foobar
|
|
|
|
test@test@example.com
|
|
|
|
].each do |invalid_email|
|
|
|
|
context "with a value of '#{invalid_email}'" do
|
|
|
|
let(:email_value) { invalid_email }
|
|
|
|
|
|
|
|
it 'is invalid' do
|
|
|
|
subject.send("#{attribute}=", invalid_email)
|
|
|
|
|
|
|
|
expect(subject).to be_invalid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
RSpec.shared_examples 'an object with RFC3696 compliant email-formatted attributes' do |*attributes|
|
2020-05-24 23:13:21 +05:30
|
|
|
attributes.each do |attribute|
|
|
|
|
describe "specifically its :#{attribute} attribute" do
|
|
|
|
%w[
|
|
|
|
info@example.com
|
|
|
|
info+test@example.com
|
|
|
|
o'reilly@example.com
|
|
|
|
].each do |valid_email|
|
|
|
|
context "with a value of '#{valid_email}'" do
|
|
|
|
let(:email_value) { valid_email }
|
|
|
|
|
|
|
|
it 'is valid' do
|
|
|
|
subject.send("#{attribute}=", valid_email)
|
|
|
|
|
|
|
|
expect(subject).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%w[
|
|
|
|
foobar
|
|
|
|
test@test@example.com
|
|
|
|
test.test.@example.com
|
|
|
|
.test.test@example.com
|
|
|
|
mailto:test@example.com
|
|
|
|
lol!'+=?><#$%^&*()@gmail.com
|
|
|
|
].each do |invalid_email|
|
|
|
|
context "with a value of '#{invalid_email}'" do
|
|
|
|
let(:email_value) { invalid_email }
|
|
|
|
|
|
|
|
it 'is invalid' do
|
|
|
|
subject.send("#{attribute}=", invalid_email)
|
|
|
|
|
|
|
|
expect(subject).to be_invalid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|