0
  6   -ˆl–Ü4ý('ÜZÔâ€vàZ¸ÓJbÑ¿�þ^•¥œl�Èû�� „_Ï×ƒŸÖÏÀÓ ô    -# Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

RSpec.describe ActiveModel::Error, :aggregate_failures do

  context 'with a default rails error available from locale.yml (including interpolation)' do
    let(:error) { User.first.errors.add(:firstname, :equal_to, count: '25') }

    context 'when using the standard error format and the default locale' do
      it 'produces a standard Rails error including the field name' do
        expect(error.message).to eq('must be equal to 25')
        expect(error.full_message).to eq('Firstname must be equal to 25')
      end
    end

    context 'when using a custom error format and a custom locale' do
      let(:custom_translations) { { 'must be equal to %{count}' => 'muss den Wert %{count} haben', 'This field %s' => 'Dieses Feld %<message>s' } } # rubocop:disable Style/FormatStringToken

      it 'produces a custom error NOT including the field name' do
        allow(Translation).to receive(:translate) { |_locale, string| custom_translations[string] || string }
        expect(error.message).to eq('must be equal to 25')
        expect(error.localized_full_message(no_field_name: true, locale: 'de-de')).to eq('Dieses Feld muss den Wert 25 haben')
      end
    end
  end

  context 'with a custom error not available from locale.yml (does not support interpolation)' do
    let(:error) { User.first.errors.add(:firstname, 'is unknown') }

    context 'when using the standard error format and the default locale' do
      it 'produces a standard Rails error including the field name' do
        expect(error.message).to eq('is unknown')
        expect(error.full_message).to eq('Firstname is unknown')
      end
    end

    context 'when using a custom error format and a custom locale' do
      let(:custom_translations) { { 'is unknown' => 'ist unbekannt', 'This field %s' => 'Dieses Feld %{message}' } }

      it 'produces a custom error NOT including the field name' do
        allow(Translation).to receive(:translate) { |_locale, string| custom_translations[string] || string }
        expect(error.message).to eq('is unknown')
        expect(error.localized_full_message(no_field_name: true, locale: 'de-de')).to eq('Dieses Feld ist unbekannt')
      end
    end
  end
end
     /ˆØ�þcm•œp,Æ2¶ŠQÿ?×ƒÏ¿ÖÏÀÓ S    /# Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/

require 'rails_helper'

RSpec.describe Service::AI::Agent::Run::Context::Entity::ObjectAttributes::Relation, type: :service do
  let(:relation_context) { described_class.new(object_attribute: object_attribute, entity_value: entity_value) }

  describe '.applicable?' do
    context 'when relation is present' do
      let(:object_attribute) { build(:object_manager_attribute_select, data_option: { relation: 'Group' }) }

      it 'returns true' do
        expect(described_class.applicable?(object_attribute)).to be true
      end
    end

    context 'when relation is not present' do
      let(:object_attribute) { build(:object_manager_attribute_text) }

      it 'returns false' do
        expect(described_class.applicable?(object_attribute)).to be false
      end
    end
  end

  describe '#prepare' do
    let(:group)            { create(:group, name: 'Test Group') }
    let(:object_attribute) { build(:object_manager_attribute_select, data_option: { relation: 'Group' }) }
    let(:entity_value)     { group.id }

    context 'when entity value exists' do
      it 'returns the value and label for the specific entity' do
        group # create the group
        result = relation_context.prepare

        expect(result).to eq({
                               value: group.id,
                               label: 'Test Group'
                             })
      end
    end

    context 'when entity value does not exist' do
      let(:entity_value) { 99_999 }

      it 'returns nil' do
        result = relation_context.prepare

        expect(result).to be_nil
      end
    end

    co