Commit 981d4900 authored by Vitali Tatarintev's avatar Vitali Tatarintev

Create TimelineEvent model

Create `IncidentManagement::TimelineEvent` model
with associations and validation rules
parent 7d8c3c4c
# frozen_string_literal: true
module IncidentManagement
class TimelineEvent < ApplicationRecord
self.table_name = 'incident_management_timeline_events'
belongs_to :project
belongs_to :author, class_name: 'User', foreign_key: :author_id
belongs_to :incident, class_name: 'Issue', foreign_key: :issue_id
belongs_to :updated_by_user, class_name: 'User', foreign_key: :updated_by_user_id
belongs_to :promoted_from_note, class_name: 'Note', foreign_key: :promoted_from_note_id
validates :project, :incident, :occurred_at, presence: true
validates :action, presence: true, length: { maximum: 128 }
validates :note, :note_html, presence: true, length: { maximum: 10_000 }
end
end
# frozen_string_literal: true
FactoryBot.define do
factory :incident_management_timeline_event, class: 'IncidentManagement::TimelineEvent' do
association :project
association :author, factory: :user
association :incident
association :promoted_from_note, factory: :note
occurred_at { Time.current }
note { 'timeline created' }
note_html { '<strong>timeline created</strong>' }
action { 'comment' }
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe IncidentManagement::TimelineEvent do
let_it_be(:timeline_event) { create(:incident_management_timeline_event) }
describe 'associations' do
it { is_expected.to belong_to(:project) }
it { is_expected.to belong_to(:author) }
it { is_expected.to belong_to(:incident) }
it { is_expected.to belong_to(:updated_by_user) }
it { is_expected.to belong_to(:promoted_from_note) }
end
describe 'validations' do
subject { build(:incident_management_timeline_event) }
it { is_expected.to validate_presence_of(:project) }
it { is_expected.to validate_presence_of(:incident) }
it { is_expected.to validate_presence_of(:note) }
it { is_expected.to validate_length_of(:note).is_at_most(10_000) }
it { is_expected.to validate_presence_of(:note_html) }
it { is_expected.to validate_length_of(:note_html).is_at_most(10_000) }
it { is_expected.to validate_presence_of(:occurred_at) }
it { is_expected.to validate_presence_of(:action) }
it { is_expected.to validate_length_of(:action).is_at_most(128) }
end
end
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