Make transcendence_step optional in grid models

- Change transcendence_step validation from required to optional
- Allow nil values but maintain numeric validation when present
- Add nil check in GridCharacter transcendence validation
This commit is contained in:
Justin Edmund 2025-09-19 23:36:04 -07:00
parent 2860552c94
commit 4e5bb350d1
3 changed files with 7 additions and 6 deletions

View file

@ -27,9 +27,9 @@ class GridCharacter < ApplicationRecord
# Validations
validates_presence_of :party
# Validate that uncap_level and transcendence_step are present and numeric.
# Validate that uncap_level is present and numeric, transcendence_step is optional but must be numeric if present.
validates :uncap_level, presence: true, numericality: { only_integer: true }
validates :transcendence_step, presence: true, numericality: { only_integer: true }
validates :transcendence_step, numericality: { only_integer: true }, allow_nil: true
validate :validate_awakening_level, on: :update
validate :transcendence, on: :update
@ -77,6 +77,7 @@ class GridCharacter < ApplicationRecord
# @note Triggered on update.
# @return [void]
def transcendence
return if transcendence_step.nil?
errors.add(:transcendence_step, 'character has no transcendence') if transcendence_step.positive? && !character.ulb
errors.add(:transcendence_step, 'transcendence step too high') if transcendence_step > 5 && character.ulb
errors.add(:transcendence_step, 'transcendence step too low') if transcendence_step.negative? && character.ulb

View file

@ -22,9 +22,9 @@ class GridSummon < ApplicationRecord
validates :position, presence: true
validate :compatible_with_position, on: :create
# Validate that uncap_level and transcendence_step are present and numeric.
# Validate that uncap_level is present and numeric, transcendence_step is optional but must be numeric if present.
validates :uncap_level, presence: true, numericality: { only_integer: true }
validates :transcendence_step, presence: true, numericality: { only_integer: true }
validates :transcendence_step, numericality: { only_integer: true }, allow_nil: true
# Custom validation to enforce maximum uncap_level based on the associated Summons flags.
validate :validate_uncap_level_based_on_summon_flags

View file

@ -39,9 +39,9 @@ class GridWeapon < ApplicationRecord
belongs_to :awakening, optional: true
# Validate that uncap_level and transcendence_step are present and numeric.
# Validate that uncap_level is present and numeric, transcendence_step is optional but must be numeric if present.
validates :uncap_level, presence: true, numericality: { only_integer: true }
validates :transcendence_step, presence: true, numericality: { only_integer: true }
validates :transcendence_step, numericality: { only_integer: true }, allow_nil: true
validate :compatible_with_position, on: :create
validate :no_conflicts, on: :create