From 23ee3e66011564178228ccb7b5d95b30f18d1da3 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Mon, 1 Nov 2021 16:32:21 +0000 Subject: [PATCH] Don't really need a wrapper method for the validations --- app/models/case_log.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/app/models/case_log.rb b/app/models/case_log.rb index bf0da4aee..43b219654 100644 --- a/app/models/case_log.rb +++ b/app/models/case_log.rb @@ -9,7 +9,7 @@ class CaseLogValidator < ActiveModel::Validator # If we've come from the form UI we only want to validate the specific fields # that have just been submitted. If we're submitting a log via API or Bulk Upload # we want to validate all data fields. - question_to_validate = options[:previous_page] + question_to_validate = options[:page] if question_to_validate if respond_to?("validate_#{question_to_validate}") public_send("validate_#{question_to_validate}", record) @@ -40,19 +40,16 @@ class CaseLog < ApplicationRecord include SoftValidations default_scope -> { kept } - validate :instance_validations + validates_with CaseLogValidator, ({ page: @current_page } || {}) before_save :update_status! - attr_accessor :current_page, :previous_page + attr_accessor :previous_page + attr_writer :current_page enum status: { "not_started" => 0, "in_progress" => 1, "completed" => 2 } AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze - def instance_validations - validates_with CaseLogValidator, ({ current_page: current_page } || {}) - end - def self.editable_fields attribute_names - AUTOGENERATED_FIELDS end