From 92b3004bf31d91c94efae4957234a36aef10da59 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 10 Jun 2024 11:03:41 -0400 Subject: [PATCH] Reference constants from account validation specs (#30634) --- spec/models/account_spec.rb | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/spec/models/account_spec.rb b/spec/models/account_spec.rb index 2c5df198d9..225929ae39 100644 --- a/spec/models/account_spec.rb +++ b/spec/models/account_spec.rb @@ -768,20 +768,20 @@ RSpec.describe Account do expect(account).to model_have_error_on_field(:username) end - it 'is invalid if the username is longer than 30 characters' do - account = Fabricate.build(:account, username: Faker::Lorem.characters(number: 31)) + it 'is invalid if the username is longer than the character limit' do + account = Fabricate.build(:account, username: username_over_limit) account.valid? expect(account).to model_have_error_on_field(:username) end - it 'is invalid if the display name is longer than 30 characters' do - account = Fabricate.build(:account, display_name: Faker::Lorem.characters(number: 31)) + it 'is invalid if the display name is longer than the character limit' do + account = Fabricate.build(:account, display_name: username_over_limit) account.valid? expect(account).to model_have_error_on_field(:display_name) end - it 'is invalid if the note is longer than 500 characters' do - account = Fabricate.build(:account, note: Faker::Lorem.characters(number: 501)) + it 'is invalid if the note is longer than the character limit' do + account = Fabricate.build(:account, note: account_note_over_limit) account.valid? expect(account).to model_have_error_on_field(:note) end @@ -814,24 +814,32 @@ RSpec.describe Account do expect(account).to model_have_error_on_field(:username) end - it 'is valid even if the username is longer than 30 characters' do - account = Fabricate.build(:account, domain: 'domain', username: Faker::Lorem.characters(number: 31)) + it 'is valid even if the username is longer than the character limit' do + account = Fabricate.build(:account, domain: 'domain', username: username_over_limit) account.valid? expect(account).to_not model_have_error_on_field(:username) end - it 'is valid even if the display name is longer than 30 characters' do - account = Fabricate.build(:account, domain: 'domain', display_name: Faker::Lorem.characters(number: 31)) + it 'is valid even if the display name is longer than the character limit' do + account = Fabricate.build(:account, domain: 'domain', display_name: username_over_limit) account.valid? expect(account).to_not model_have_error_on_field(:display_name) end - it 'is valid even if the note is longer than 500 characters' do - account = Fabricate.build(:account, domain: 'domain', note: Faker::Lorem.characters(number: 501)) + it 'is valid even if the note is longer than the character limit' do + account = Fabricate.build(:account, domain: 'domain', note: account_note_over_limit) account.valid? expect(account).to_not model_have_error_on_field(:note) end end + + def username_over_limit + 'a' * described_class::USERNAME_LENGTH_LIMIT * 2 + end + + def account_note_over_limit + 'a' * described_class::NOTE_LENGTH_LIMIT * 2 + end end describe 'scopes' do