1
0
Fork 0

Validate MembershipApplication#email

This commit is contained in:
Alex Kotov 2018-12-06 07:46:32 +05:00
parent c519c2782b
commit c637eaf8fa
No known key found for this signature in database
GPG key ID: 4E831250F47DE154
2 changed files with 23 additions and 1 deletions

View file

@ -4,13 +4,16 @@ class MembershipApplication < ApplicationRecord
belongs_to :account
belongs_to :country_state, optional: true
validates :email, presence: true, format: Devise.email_regexp
validates :first_name, presence: true
validates :last_name, presence: true
validates :date_of_birth, presence: true
validates :email, presence: true
validates :phone_number, presence: true
before_validation do
email&.strip!
self.middle_name = nil if middle_name.blank?
self.occupation = nil if occupation.blank?
self.telegram_username = nil if telegram_username.blank?

View file

@ -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 :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
context 'when it is empty' do
subject { create :membership_application, middle_name: '' }