Set nil to blank attributes
This commit is contained in:
parent
86250c8125
commit
02e234f564
|
@ -19,6 +19,7 @@ Layout/EmptyLinesAroundArguments:
|
|||
Metrics/BlockLength:
|
||||
Exclude:
|
||||
- 'config/initializers/*.rb'
|
||||
- 'spec/**/*.rb'
|
||||
|
||||
Metrics/LineLength:
|
||||
Exclude:
|
||||
|
|
|
@ -6,4 +6,12 @@ class MembershipApplication < ApplicationRecord
|
|||
validates :date_of_birth, presence: true
|
||||
validates :email, presence: true
|
||||
validates :phone_number, presence: true
|
||||
|
||||
before_validation do
|
||||
self.middle_name = nil if middle_name.blank?
|
||||
self.occupation = nil if occupation.blank?
|
||||
self.telegram_username = nil if telegram_username.blank?
|
||||
self.organization_membership = nil if organization_membership.blank?
|
||||
self.comment = nil if comment.blank?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,4 +15,94 @@ RSpec.describe MembershipApplication, type: :model do
|
|||
it { is_expected.not_to validate_presence_of :telegram_username }
|
||||
it { is_expected.not_to validate_presence_of :organization_membership }
|
||||
it { is_expected.not_to validate_presence_of :comment }
|
||||
|
||||
describe '#middle_name' do
|
||||
context 'when it is empty' do
|
||||
subject { create :membership_application, middle_name: '' }
|
||||
|
||||
specify do
|
||||
expect(subject.middle_name).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is blank' do
|
||||
subject { create :membership_application, middle_name: ' ' }
|
||||
|
||||
specify do
|
||||
expect(subject.middle_name).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#occupation' do
|
||||
context 'when it is empty' do
|
||||
subject { create :membership_application, occupation: '' }
|
||||
|
||||
specify do
|
||||
expect(subject.occupation).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is blank' do
|
||||
subject { create :membership_application, occupation: ' ' }
|
||||
|
||||
specify do
|
||||
expect(subject.occupation).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#telegram_username' do
|
||||
context 'when it is empty' do
|
||||
subject { create :membership_application, telegram_username: '' }
|
||||
|
||||
specify do
|
||||
expect(subject.telegram_username).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is blank' do
|
||||
subject { create :membership_application, telegram_username: ' ' }
|
||||
|
||||
specify do
|
||||
expect(subject.telegram_username).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#organization_membership' do
|
||||
context 'when it is empty' do
|
||||
subject { create :membership_application, organization_membership: '' }
|
||||
|
||||
specify do
|
||||
expect(subject.organization_membership).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is blank' do
|
||||
subject { create :membership_application, organization_membership: ' ' }
|
||||
|
||||
specify do
|
||||
expect(subject.organization_membership).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#comment' do
|
||||
context 'when it is empty' do
|
||||
subject { create :membership_application, comment: '' }
|
||||
|
||||
specify do
|
||||
expect(subject.comment).to eq nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when it is blank' do
|
||||
subject { create :membership_application, comment: ' ' }
|
||||
|
||||
specify do
|
||||
expect(subject.comment).to eq nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in New Issue