Browse Source

Make autogenerated fields a named constant

pull/45/head
baarkerlounger 4 years ago
parent
commit
88eb53aa11
  1. 5
      app/models/case_log.rb

5
app/models/case_log.rb

@ -28,6 +28,8 @@ class CaseLog < ApplicationRecord
enum status: { "in progress" => 0, "submitted" => 1 } enum status: { "in progress" => 0, "submitted" => 1 }
AUTOGENERATED_FIELDS = %w[status created_at updated_at id].freeze
def instance_validations def instance_validations
validates_with CaseLogValidator, ({ previous_page: @previous_page } || {}) validates_with CaseLogValidator, ({ previous_page: @previous_page } || {})
end end
@ -37,8 +39,7 @@ class CaseLog < ApplicationRecord
end end
def all_fields_completed? def all_fields_completed?
non_mandatory_fields = %w[status created_at updated_at id] mandatory_fields = attributes.except(*AUTOGENERATED_FIELDS)
mandatory_fields = attributes.except(*non_mandatory_fields)
mandatory_fields.none? { |_key, val| val.nil? } mandatory_fields.none? { |_key, val| val.nil? }
end end
end end

Loading…
Cancel
Save