Validate MembershipApplication#email
This commit is contained in:
parent
c519c2782b
commit
c637eaf8fa
2 changed files with 23 additions and 1 deletions
|
@ -4,13 +4,16 @@ class MembershipApplication < ApplicationRecord
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
belongs_to :country_state, optional: true
|
belongs_to :country_state, optional: true
|
||||||
|
|
||||||
|
validates :email, presence: true, format: Devise.email_regexp
|
||||||
|
|
||||||
validates :first_name, presence: true
|
validates :first_name, presence: true
|
||||||
validates :last_name, presence: true
|
validates :last_name, presence: true
|
||||||
validates :date_of_birth, presence: true
|
validates :date_of_birth, presence: true
|
||||||
validates :email, presence: true
|
|
||||||
validates :phone_number, presence: true
|
validates :phone_number, presence: true
|
||||||
|
|
||||||
before_validation do
|
before_validation do
|
||||||
|
email&.strip!
|
||||||
|
|
||||||
self.middle_name = nil if middle_name.blank?
|
self.middle_name = nil if middle_name.blank?
|
||||||
self.occupation = nil if occupation.blank?
|
self.occupation = nil if occupation.blank?
|
||||||
self.telegram_username = nil if telegram_username.blank?
|
self.telegram_username = nil if telegram_username.blank?
|
||||||
|
|
|
@ -21,6 +21,25 @@ RSpec.describe MembershipApplication do
|
||||||
it { is_expected.not_to validate_presence_of :organization_membership }
|
it { is_expected.not_to validate_presence_of :organization_membership }
|
||||||
it { is_expected.not_to validate_presence_of :comment }
|
it { is_expected.not_to validate_presence_of :comment }
|
||||||
|
|
||||||
|
describe '#email' do
|
||||||
|
def allow_value(*)
|
||||||
|
super.for :email
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to allow_value Faker::Internet.email }
|
||||||
|
it { is_expected.not_to allow_value Faker::Internet.username }
|
||||||
|
|
||||||
|
context 'when it has extra spaces' do
|
||||||
|
subject { create :membership_application, email: " #{email} " }
|
||||||
|
|
||||||
|
let(:email) { Faker::Internet.email }
|
||||||
|
|
||||||
|
specify do
|
||||||
|
expect(subject.email).to eq email
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#middle_name' do
|
describe '#middle_name' do
|
||||||
context 'when it is empty' do
|
context 'when it is empty' do
|
||||||
subject { create :membership_application, middle_name: '' }
|
subject { create :membership_application, middle_name: '' }
|
||||||
|
|
Reference in a new issue