search_with_attachment_spec.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. require 'rails_helper'
  3. require 'models/concerns/checks_kb_client_notification_examples'
  4. require 'models/contexts/factory_context'
  5. RSpec.describe KnowledgeBase::Answer::Translation, current_user_id: 1, searchindex: 1, type: :model do
  6. include_context 'basic Knowledge Base'
  7. let(:user) { create(:admin) }
  8. let(:filename) { 'test.rtf' }
  9. let(:query) { 'RTF document' }
  10. context 'search with attachment' do
  11. before do
  12. published_answer
  13. published_answer.add_attachment File.open "spec/fixtures/files/upload/#{filename}"
  14. searchindex_model_reload([KnowledgeBase::Translation, KnowledgeBase::Category::Translation, described_class])
  15. end
  16. it do
  17. expect(described_class.search(query: query, current_user: user))
  18. .to include published_answer.translations.first
  19. end
  20. # https://github.com/zammad/zammad/issues/4134
  21. context 'when associations are updated' do
  22. it 'does not delete the attachment from the search index' do
  23. User.find(1).search_index_update_associations
  24. SearchIndexBackend.refresh
  25. expect(described_class.search(query: query, current_user: user))
  26. .to include published_answer.translations.first
  27. end
  28. end
  29. end
  30. end