DEV: Set a limit for ApiKey#description (#21502)

This commit is contained in:
Loïc Guitaut 2023-05-15 06:12:25 +02:00 committed by GitHub
parent f160f073b0
commit 9f283eb836
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 0 deletions

View File

@ -17,6 +17,8 @@ class ApiKey < ActiveRecord::Base
where(key_hash: hashed)
}
validates :description, length: { maximum: 255 }
after_initialize :generate_key
def generate_key

View File

@ -6,6 +6,7 @@ RSpec.describe ApiKey do
it { is_expected.to belong_to :user }
it { is_expected.to belong_to :created_by }
it { is_expected.to validate_length_of(:description).is_at_most(255) }
it "generates a key when saving" do
api_key = ApiKey.new