discourse/spec/models/reviewable_action_log_spec.rb
Gary Pendergast 57f2f5a5ea
DEV: Log Reviewable actions (#36076)
With reviewables now being able to have multiple actions performed on
them, we don't want to update the final reviewable state until an action
from every action bundle has been performed.

This change makes use of the new `ReviewableActionLog`, logging actions
when they occur, then checking to see if a reviewable has had all
actions performed before finalising it.
2025-11-20 13:41:40 +11:00

57 lines
1.6 KiB
Ruby

# frozen_string_literal: true
RSpec.describe ReviewableActionLog, type: :model do
fab!(:moderator)
fab!(:reviewable, :reviewable_flagged_post)
describe "reviewable_action_logs association on reviewable" do
it "creates action logs associated with reviewable" do
log =
ReviewableActionLog.create!(
reviewable: reviewable,
action_key: "agree_and_keep",
status: :approved,
performed_by: moderator,
bundle: "legacy-actions",
)
expect(reviewable.reviewable_action_logs).to include(log)
expect(reviewable.reviewable_action_logs.count).to eq(1)
end
it "orders action logs by created_at ascending" do
log1 =
ReviewableActionLog.create!(
reviewable: reviewable,
action_key: "agree_and_keep",
status: :approved,
performed_by: moderator,
bundle: "legacy-actions",
)
log2 =
ReviewableActionLog.create!(
reviewable: reviewable,
action_key: "suspend_user",
status: :rejected,
performed_by: moderator,
bundle: "user-actions",
)
expect(reviewable.reviewable_action_logs.to_a).to eq([log1, log2])
end
it "deletes action logs when reviewable is destroyed" do
log =
ReviewableActionLog.create!(
reviewable: reviewable,
action_key: "agree_and_keep",
status: :approved,
performed_by: moderator,
bundle: "legacy-actions",
)
reviewable.destroy!
expect(ReviewableActionLog.exists?(log.id)).to be false
end
end
end