1
0
Fork 0

Strip extra spaces

This commit is contained in:
Alex Kotov 2019-03-24 19:42:33 +05:00
parent 7c3229adc2
commit ba11f9f67e
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 30 additions and 0 deletions

View File

@ -51,6 +51,7 @@ class Account < ApplicationRecord
after_initialize :generate_username
before_validation :turn_blanks_into_nils
before_validation :strip_extra_spaces
before_create :generate_guest_token
@ -123,4 +124,9 @@ private
self.public_name = nil if public_name.blank?
self.biography = nil if biography.blank?
end
def strip_extra_spaces
self.public_name = public_name&.strip
self.biography = biography&.strip
end
end

View File

@ -115,6 +115,18 @@ RSpec.describe Account do
expect(subject.public_name).to eq nil
end
end
context 'when it was set to value with leading and trailing spaces' do
subject { create :personal_account, public_name: public_name }
let :public_name do
"#{' ' * rand(4)}#{Faker::Name.name}#{' ' * rand(4)}"
end
specify do
expect(subject.public_name).to eq public_name.strip
end
end
end
describe '#biography' do
@ -140,6 +152,18 @@ RSpec.describe Account do
expect(subject.biography).to eq nil
end
end
context 'when it was set to value with leading and trailing spaces' do
subject { create :personal_account, biography: biography }
let :biography do
"#{' ' * rand(4)}#{Faker::Lorem.sentence}#{' ' * rand(4)}"
end
specify do
expect(subject.biography).to eq biography.strip
end
end
end
describe '#has_role?' do