Favoring constant over magic string (#15852)

This commit is contained in:
Jeremy Friesen 2021-12-27 11:31:29 -05:00 committed by GitHub
parent 2bf13cab00
commit 0b8c09851c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 3 deletions

View file

@ -5,7 +5,7 @@ module Admin
def index
@q = AuditLog
.includes(:user)
.where(category: "moderator.audit.log")
.where(category: AuditLog::MODERATOR_AUDIT_LOG_CATEGORY)
.order(created_at: :desc)
.ransack(params[:q])
@moderator_actions = @q.result.page(params[:page] || 1).per(25)

View file

@ -2,4 +2,6 @@ class AuditLog < ApplicationRecord
belongs_to :user, optional: true
validates :data, presence: true
MODERATOR_AUDIT_LOG_CATEGORY = "moderator.audit.log".freeze
end

View file

@ -43,7 +43,7 @@ RSpec.describe "/admin/moderation/moderator_reactions", type: :request do
it "renders the page with a user's audit log" do
audit_log = create(
:audit_log,
category: "moderator.audit.log",
category: AuditLog::MODERATOR_AUDIT_LOG_CATEGORY,
user: admin,
roles: admin.roles.pluck(:name),
)
@ -57,7 +57,7 @@ RSpec.describe "/admin/moderation/moderator_reactions", type: :request do
it "renders the page with an audit log not belonging to a specific user" do
audit_log = create(
:audit_log,
category: "moderator.audit.log",
category: AuditLog::MODERATOR_AUDIT_LOG_CATEGORY,
user: nil,
)