0
     ˆÆÅÑ568ÄÐÏ 8    ‹      Õ–M�Ú0†ïû+\zƒ	,­ÔÝ�jK�ŠÊb©ªªª�‰±HìÈž�Ò__‡¤‚Ý‚ÚªRNž™¼öÌ3vûÏÂé`ñq6$o÷c2{ÿf<Úøp= aõ ×ö: Ã	%4FÌn Š¢h×mm6°˜CŒiÒ‹FFØæÈipå—±àŠø±`Ü�ÄG‰‰FŠ‹/D¯	è­äÂÍÛ[àb'#aKE
©HµÙ×Cï(Í…W»¯™.„ñ¡ZÒ%�:‹¿Ò|_&ïüÝDn½[ò•¦	|ŒÉŽ%r£úuF_¦bMÔ§ #­,¬¦¶í�\SÂìÓO£Áô³ÓÆåìÀg$6bÝ§¯ýÉí´Ò`ÂRá;¯¹wš;Œ™E’j.×Rð‹â‡Jü ¿^^0¬4¡°‘‘J­ŽRpˆ§¨‘NlÆëG›SU%á?ë‹5cv7Náh^µ„—K«û£m£ÁŒ¡�„Òˆ]´æª’<W+›Ý~wI]µ‘›i@H‹œUþj®¶Jê”Öuò,'³{Ñà0œù¤ª®×}ÙêtZÝñz7žGÈ¡{WßýÏòsÔ6·™P|ÉEÂöËÔ:š3ÑÂ9=�Ð 6ˆ`r…2K¡Ü‰åVr·=g‚ÍG+íÐJ»ÁhB•~ÄªF²È0?9ƒ•ßd ê;'ø“ø8Þ`ÀÜ²Í	×Áý÷8¿xó€úNæÃáêçCuïü“ôŠÚ
    7   ˆl–ß=¿JÅ!¶e8 �q§®	Å1hß�þBÙYÆÞqÐ	Ð²ûOÿ?Óƒm·[ÒÎÑÐ Ç    # Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'
require 'lib/validations/object_manager/attribute_validator/backend_examples'

RSpec.describe Validations::ObjectManager::AttributeValidator::Option, application_handle: 'ai_agent_execution', db_strategy: :reset do
  subject do
    described_class.new(
      record:    record,
      attribute: attribute,
    )
  end

  let(:record)        { build(:user) }
  let(:run_migration) { true }

  before do
    attribute
    next if !run_migration

    ObjectManager::Attribute.migration_execute
    attribute.reload
  end

  context 'when basic behavior is checked' do
    let(:attribute) { create(:object_manager_attribute_select) }

    it_behaves_like 'validate backend'
  end

  context 'when historical_options are not yet populated (migration pending)' do
    let(:run_migration) { false }

    context 'with select attribute having numeric option values' do
      let(:attribute) { create(:object_manager_attribute_select, data_option_options: { '2025' => '2025', '2026' => '2026' }) }

      context 'when value matches an existing option' do
        let(:value) { '2025' }

        it_behaves_like 'a validation without errors'
      end
    end
  end

  context 'when validation should not be performed' do
    context 'with blank value' do
      let(:attribute) { create(:object_manager_attribute_select) }
      let(:value)     { nil }

      it_behaves_like 'a validation without errors'
    end

    context 'with non-option attribute data_type' do
      let(:attribute) { create(:object_manager_attribute_text) }
      let(:value)     { 'some_value' }

      it_behaves_like 'a validation without errors'
    end
  end

  context 'with select attribute' do
    let(:attribute) { create(:object_manager_attribute_select) }

    context 'when value is valid' do
      let(:value) { 'key_1' }

      it_behaves_like 'a validation without errors'
    end

    context 'when value is invalid' do
      let(:value) { 'invalid_key' }

      it_behaves_like 'a validation with errors'
    end

    context 'when validation is turned off', application_handle: 'application_server' do
      let(:value) { 'invalid_key' }

      it_behaves_like 'a validation without errors'
    end

    context 'when options use numeric values' do
      let(:attribute) { create(:object_manager_attribute_select, data_option_options: { '2025' => '2025', '2026' => '2026' }) }

      context 'when value matches a numeric option' do
        let(:value) { '2025' }

        it_behaves_like 'a validation without errors'
      end
    end
  end

  context 'with tree_select attribute' do
    let(:attribute) { create(:object_manager_attribute_tree_select) }

    context 'when value is valid' do
      let(:value) { 'Incident' }

      it_behaves_like 'a validation without errors'
    end

    context 'when value is invalid' do
      let(:value) { 'invalid_key' }

      it_behaves_like 'a validation with errors'
    end

    context 'with nested options' do
      context 'when value is valid child' do
        let(:value) { 'Incident::Hardware' }

        it_behaves_like 'a validation without errors'
      end

      context 'when value is valid parent' do
        let(:value) { 'Incident' }

        it_behaves_like 'a validation without errors'
      end

      context 'when value is invalid' do
        let(:value) { 'invalid_key