Skip to content

Commit

Permalink
Add stage_changed timeline events
Browse files Browse the repository at this point in the history
This adds a new type of timeline event which captures whenever the
stage of an application has changed.
  • Loading branch information
thomasleese committed Sep 27, 2023
1 parent 0c4e53f commit 0af5dc8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/models/timeline_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TimelineEvent < ApplicationRecord
requestable_received: "requestable_received",
requestable_requested: "requestable_requested",
reviewer_assigned: "reviewer_assigned",
stage_changed: "stage_changed",
state_changed: "state_changed",
}

Expand Down Expand Up @@ -152,11 +153,17 @@ class TimelineEvent < ApplicationRecord
validates :old_value,
:new_value,
presence: true,
if: -> { action_required_by_changed? || information_changed? }
if: -> do
action_required_by_changed? || information_changed? ||
stage_changed?
end
validates :old_value,
:new_value,
absence: true,
unless: -> { action_required_by_changed? || information_changed? }
unless: -> do
action_required_by_changed? || information_changed? ||
stage_changed?
end
validates :column_name, presence: true, if: :information_changed?
validates :work_history_id,
:column_name,
Expand Down
24 changes: 24 additions & 0 deletions spec/models/timeline_event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
requestable_received: "requestable_received",
requestable_requested: "requestable_requested",
reviewer_assigned: "reviewer_assigned",
stage_changed: "stage_changed",
state_changed: "state_changed",
).backed_by_column_of_type(:string)
end
Expand Down Expand Up @@ -410,5 +411,28 @@
it { is_expected.to validate_presence_of(:old_value) }
it { is_expected.to validate_presence_of(:new_value) }
end

context "with a stage changed event type" do
before { timeline_event.event_type = :stage_changed }

it { is_expected.to validate_absence_of(:assignee) }
it { is_expected.to validate_absence_of(:old_state) }
it { is_expected.to validate_absence_of(:new_state) }
it { is_expected.to validate_absence_of(:assessment_section) }
it { is_expected.to validate_absence_of(:note) }
it { is_expected.to validate_absence_of(:mailer_class_name) }
it { is_expected.to validate_absence_of(:mailer_action_name) }
it { is_expected.to validate_absence_of(:message_subject) }
it { is_expected.to validate_absence_of(:assessment) }
it { is_expected.to validate_absence_of(:age_range_min) }
it { is_expected.to validate_absence_of(:age_range_max) }
it { is_expected.to validate_absence_of(:subjects) }
it { is_expected.to validate_absence_of(:requestable_id) }
it { is_expected.to validate_absence_of(:requestable_type) }
it { is_expected.to validate_absence_of(:work_history_id) }
it { is_expected.to validate_absence_of(:column_name) }
it { is_expected.to validate_presence_of(:old_value) }
it { is_expected.to validate_presence_of(:new_value) }
end
end
end

0 comments on commit 0af5dc8

Please sign in to comment.