attribute_spec.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'Ticket::Selector', db_strategy: :reset, searchindex: true do
  4. before do
  5. Ticket.destroy_all
  6. attribute
  7. tickets
  8. searchindex_model_reload([Ticket])
  9. end
  10. let(:agent) { create(:agent, groups: [Group.first]) }
  11. let(:attribute) do
  12. attribute = create(:object_manager_attribute_text)
  13. ObjectManager::Attribute.migration_execute
  14. attribute
  15. end
  16. let(:tickets) do
  17. tickets = create_list(:ticket, 10, group: Group.first)
  18. tickets.each_with_index do |ticket, index|
  19. ticket[attribute.name] = index.odd? ? '1st value' : '2nd value'
  20. ticket.save!
  21. end
  22. end
  23. let(:condition) do
  24. {
  25. "ticket.#{attribute.name}" => {
  26. operator: 'is',
  27. value: '1st value',
  28. },
  29. }
  30. end
  31. describe 'select by condition attribute' do
  32. context 'when using the ticket selector' do
  33. it 'is successful' do
  34. ticket_count, = Ticket.selectors(condition, limit: 100)
  35. expect(ticket_count).to eq(5)
  36. end
  37. end
  38. context 'when using the search index backend' do
  39. it 'is successful' do
  40. result = SearchIndexBackend.selectors('Ticket', condition, { current_user: agent })
  41. expect(result[:count]).to eq(5)
  42. end
  43. end
  44. end
  45. end