Add validations to Account#public_name, #biography
This commit is contained in:
parent
c78c4ebc23
commit
7c3229adc2
|
@ -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 #
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
|
Reference in New Issue