Commit 80bd4134 authored by Peter Leitzen's avatar Peter Leitzen

Add length validations for error tracking errors and events

These validations mirror the actual database constraints.
parent 20a19ef2
......@@ -18,9 +18,10 @@ class ErrorTracking::Error < ApplicationRecord
scope :for_status, -> (status) { where(status: status) }
validates :project, presence: true
validates :name, presence: true
validates :description, presence: true
validates :actor, presence: true
validates :name, presence: true, length: { maximum: 255 }
validates :description, presence: true, length: { maximum: 1024 }
validates :actor, presence: true, length: { maximum: 255 }
validates :platform, length: { maximum: 255 }
validates :status, presence: true
enum status: {
......
......@@ -6,7 +6,9 @@ class ErrorTracking::ErrorEvent < ApplicationRecord
validates :payload, json_schema: { filename: 'error_tracking_event_payload' }
validates :error, presence: true
validates :description, presence: true
validates :description, presence: true, length: { maximum: 1024 }
validates :level, length: { maximum: 255 }
validates :environment, length: { maximum: 255 }
validates :occurred_at, presence: true
def stacktrace
......
......@@ -11,7 +11,10 @@ RSpec.describe ErrorTracking::ErrorEvent, type: :model do
describe 'validations' do
it { is_expected.to validate_presence_of(:description) }
it { is_expected.to validate_length_of(:description).is_at_most(1024) }
it { is_expected.to validate_presence_of(:occurred_at) }
it { is_expected.to validate_length_of(:level).is_at_most(255) }
it { is_expected.to validate_length_of(:environment).is_at_most(255) }
end
describe '#stacktrace' do
......
......@@ -12,8 +12,12 @@ RSpec.describe ErrorTracking::Error, type: :model do
describe 'validations' do
it { is_expected.to validate_presence_of(:name) }
it { is_expected.to validate_length_of(:name).is_at_most(255) }
it { is_expected.to validate_presence_of(:description) }
it { is_expected.to validate_length_of(:description).is_at_most(1024) }
it { is_expected.to validate_presence_of(:actor) }
it { is_expected.to validate_length_of(:actor).is_at_most(255) }
it { is_expected.to validate_length_of(:platform).is_at_most(255) }
end
describe '.report_error' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment