From 88eb53aa114e818bb3ee0fbf30399808d646a1e7 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Wed, 13 Oct 2021 13:35:18 +0100 Subject: [PATCH] Make autogenerated fields a named constant --- app/models/case_log.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index ac1dd2054..1407e9dfd 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -28,6 +28,8 @@ class CaseLog < ApplicationRecord enum status: { "in progress" => 0, "submitted" => 1 } + AUTOGENERATED_FIELDS = %w[status created_at updated_at id].freeze + def instance_validations validates_with CaseLogValidator, ({ previous_page: @previous_page } || {}) end @@ -37,8 +39,7 @@ class CaseLog < ApplicationRecord end def all_fields_completed? - non_mandatory_fields = %w[status created_at updated_at id] - mandatory_fields = attributes.except(*non_mandatory_fields) + mandatory_fields = attributes.except(*AUTOGENERATED_FIELDS) mandatory_fields.none? { |_key, val| val.nil? } end end