has_search_index_backend_spec.rb 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. RSpec.describe 'HasSearchIndexBackend', searchindex: true, type: :model do
  4. describe 'Updating referenced data between user and organizations' do
  5. let(:organization) { create(:organization, name: 'Tomato42') }
  6. let(:user) { create(:customer, organization: organization) }
  7. before do
  8. user && organization
  9. searchindex_model_reload([User, Organization])
  10. end
  11. it 'finds added users' do
  12. result = SearchIndexBackend.search('organization.name:Tomato42', 'User', sort_by: ['updated_at'], order_by: ['desc'])
  13. expect(result).to eq([{ id: user.id.to_s, type: 'User' }])
  14. end
  15. context 'when renaming the organization' do
  16. before do
  17. organization.update(name: 'Cucumber43 Ltd.')
  18. organization.search_index_update_associations
  19. SearchIndexBackend.refresh
  20. end
  21. it 'finds added users by organization name in sub hash' do
  22. result = SearchIndexBackend.search('organization.name:Cucumber43', 'User', sort_by: ['updated_at'], order_by: ['desc'])
  23. expect(result).to eq([{ id: user.id.to_s, type: 'User' }])
  24. end
  25. it 'finds added users by organization name' do
  26. result = SearchIndexBackend.search('Cucumber43', 'User', sort_by: ['updated_at'], order_by: ['desc'])
  27. expect(result).to eq([{ id: user.id.to_s, type: 'User' }])
  28. end
  29. end
  30. end
  31. describe 'Updating group settings causes huge numbers of delayed jobs #4306' do
  32. let(:user) { create(:user) }
  33. before do
  34. user
  35. Delayed::Job.destroy_all
  36. end
  37. it 'does not create any jobs if nothing has changed' do
  38. expect { user.update(firstname: user.firstname) }.not_to change(Delayed::Job, :count)
  39. end
  40. end
  41. describe 'Search doesnt show tickets belonging to secondary organization #4425' do
  42. let(:user) { create(:user, organization: create(:organization), organizations: create_list(:organization, 1, name: SecureRandom.uuid)) }
  43. before do
  44. user
  45. searchindex_model_reload([User, Organization])
  46. end
  47. it 'does find user by secondary organization' do
  48. result = SearchIndexBackend.search(user.organizations.first.name, 'User', sort_by: ['updated_at'], order_by: ['desc'])
  49. expect(result).to eq([{ id: user.id.to_s, type: 'User' }])
  50. end
  51. end
  52. end