1
0
Fork 0

Add validations to Account#public_name, #biography

This commit is contained in:
Alex Kotov 2019-03-24 19:32:07 +05:00
parent c78c4ebc23
commit 7c3229adc2
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 13 additions and 3 deletions

View File

@ -66,7 +66,9 @@ class Account < ApplicationRecord
format: USERNAME_RE,
uniqueness: { case_sensitive: false }
validates :biography, length: { maximum: 10_000 }
validates :public_name, allow_nil: true, length: { in: 3..255 }
validates :biography, allow_nil: true, length: { in: 3..10_000 }
###########
# Methods #

View File

@ -103,6 +103,11 @@ RSpec.describe Account do
it { is_expected.to allow_value Faker::Name.first_name }
it { is_expected.to allow_value 'Foo Bar' }
it do
is_expected.to \
validate_length_of(:public_name).is_at_least(3).is_at_most(255)
end
context 'when it was set to blank value' do
subject { create :personal_account, public_name: ' ' * rand(100) }
@ -117,14 +122,17 @@ RSpec.describe Account do
super.for :biography
end
it { is_expected.to validate_length_of(:biography).is_at_most(10_000) }
it { is_expected.to allow_value nil }
it { is_expected.to allow_value '' }
it { is_expected.to allow_value ' ' }
it { is_expected.to allow_value Faker::Lorem.sentence }
it do
is_expected.to \
validate_length_of(:biography).is_at_least(3).is_at_most(10_000)
end
context 'when it was set to blank value' do
subject { create :personal_account, biography: ' ' * rand(100) }