user_spec.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe Selector::Base, 'user', searchindex: true do
  4. describe 'Basic tests' do
  5. let(:user_1) { create(:user, firstname: 'Philipp J.', lastname: 'Fry') }
  6. let(:user_2) { create(:user, firstname: 'Turanga', lastname: 'Leela') }
  7. let(:user_3) { create(:user, firstname: 'Bender', lastname: 'Rodriguez') }
  8. before do
  9. user_1 && user_2 && user_3
  10. searchindex_model_reload([User])
  11. end
  12. it 'does find users by firstname', :aggregate_failures do
  13. condition = {
  14. operator: 'OR',
  15. conditions: [
  16. {
  17. name: 'user.firstname',
  18. operator: 'contains',
  19. value: user_1.firstname,
  20. },
  21. {
  22. name: 'user.firstname',
  23. operator: 'contains',
  24. value: user_2.firstname,
  25. },
  26. {
  27. name: 'user.firstname',
  28. operator: 'contains',
  29. value: user_3.firstname,
  30. },
  31. ]
  32. }
  33. count, = User.selectors(condition)
  34. expect(count).to eq(3)
  35. result = SearchIndexBackend.selectors('User', condition)
  36. expect(result[:count]).to eq(3)
  37. end
  38. end
  39. end