Reference constants from account validation specs (#30634)

This commit is contained in:
Matt Jankowski 2024-06-10 11:03:41 -04:00 committed by GitHub
parent 28f9a8f2ec
commit 92b3004bf3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -768,20 +768,20 @@ RSpec.describe Account do
expect(account).to model_have_error_on_field(:username) expect(account).to model_have_error_on_field(:username)
end end
it 'is invalid if the username is longer than 30 characters' do it 'is invalid if the username is longer than the character limit' do
account = Fabricate.build(:account, username: Faker::Lorem.characters(number: 31)) account = Fabricate.build(:account, username: username_over_limit)
account.valid? account.valid?
expect(account).to model_have_error_on_field(:username) expect(account).to model_have_error_on_field(:username)
end end
it 'is invalid if the display name is longer than 30 characters' do it 'is invalid if the display name is longer than the character limit' do
account = Fabricate.build(:account, display_name: Faker::Lorem.characters(number: 31)) account = Fabricate.build(:account, display_name: username_over_limit)
account.valid? account.valid?
expect(account).to model_have_error_on_field(:display_name) expect(account).to model_have_error_on_field(:display_name)
end end
it 'is invalid if the note is longer than 500 characters' do it 'is invalid if the note is longer than the character limit' do
account = Fabricate.build(:account, note: Faker::Lorem.characters(number: 501)) account = Fabricate.build(:account, note: account_note_over_limit)
account.valid? account.valid?
expect(account).to model_have_error_on_field(:note) expect(account).to model_have_error_on_field(:note)
end end
@ -814,24 +814,32 @@ RSpec.describe Account do
expect(account).to model_have_error_on_field(:username) expect(account).to model_have_error_on_field(:username)
end end
it 'is valid even if the username is longer than 30 characters' do it 'is valid even if the username is longer than the character limit' do
account = Fabricate.build(:account, domain: 'domain', username: Faker::Lorem.characters(number: 31)) account = Fabricate.build(:account, domain: 'domain', username: username_over_limit)
account.valid? account.valid?
expect(account).to_not model_have_error_on_field(:username) expect(account).to_not model_have_error_on_field(:username)
end end
it 'is valid even if the display name is longer than 30 characters' do it 'is valid even if the display name is longer than the character limit' do
account = Fabricate.build(:account, domain: 'domain', display_name: Faker::Lorem.characters(number: 31)) account = Fabricate.build(:account, domain: 'domain', display_name: username_over_limit)
account.valid? account.valid?
expect(account).to_not model_have_error_on_field(:display_name) expect(account).to_not model_have_error_on_field(:display_name)
end end
it 'is valid even if the note is longer than 500 characters' do it 'is valid even if the note is longer than the character limit' do
account = Fabricate.build(:account, domain: 'domain', note: Faker::Lorem.characters(number: 501)) account = Fabricate.build(:account, domain: 'domain', note: account_note_over_limit)
account.valid? account.valid?
expect(account).to_not model_have_error_on_field(:note) expect(account).to_not model_have_error_on_field(:note)
end end
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 end
describe 'scopes' do describe 'scopes' do