OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix tsv spec
Oliver Güntherb6237fcc889c
diff --git a/app/workers/extract_fulltext_job.rb b/app/workers/extract_fulltext_job.rbindex 7fbbb7f0932..975cac15bf9 100644--- a/app/workers/extract_fulltext_job.rb+++ b/app/workers/extract_fulltext_job.rb@@ -81,7 +81,7 @@ class ExtractFulltextJob < ApplicationJobenddef find_attachment(id)- Attachment.find_by_id id+ Attachment.find_by(id: id)enddef remote_file?diff --git a/spec/workers/extract_fulltext_job_spec.rb b/spec/workers/extract_fulltext_job_spec.rbindex 802b72b53af..1267ebaac83 100644--- a/spec/workers/extract_fulltext_job_spec.rb+++ b/spec/workers/extract_fulltext_job_spec.rb@@ -31,86 +31,89 @@require 'spec_helper'describe ExtractFulltextJob, type: :job do- # These jobs only get created when TSVector is supported by the DB.- if OpenProject::Database.allows_tsv?- let(:text) { 'lorem ipsum' }- let(:attachment) do- FactoryBot.create(:attachment).tap do |attachment|- expect(ExtractFulltextJob)- .to have_been_enqueued- .with(attachment.id)-- perform_enqueued_jobs-- attachment.reload- end+ let(:text) { 'lorem ipsum' }+ let(:attachment) do+ FactoryBot.create(:attachment).tap do |attachment|+ expect(ExtractFulltextJob)+ .to have_been_enqueued+ .with(attachment.id)end+ end++ let(:subject) do+ perform_enqueued_jobs++ attachment.reload+ end++ before do+ allow(Attachment).to receive(:find_by).with(id: attachment.id).and_return(attachment)+ end- context "with successful text extraction" do+ context "with successful text extraction" do+ before do+ allow_any_instance_of(Plaintext::Resolver).to receive(:text).and_return(text)+ end++ context 'attachment is readable' dobefore do- allow_any_instance_of(Plaintext::Resolver).to receive(:text).and_return(text)+ allow(attachment).to receive(:readable?).and_return(true)+ subjectend- context 'attachment is readable' do- before do- allow(attachment).to receive(:readable?).and_return(true)- attachment.reload- end-- it 'updates the attachment\'s DB record with fulltext, fulltext_tsv, and file_tsv' do- expect(attachment.fulltext).to eq text- expect(attachment.fulltext_tsv.size).to be > 0- expect(attachment.file_tsv.size).to be > 0- end+ it 'updates the attachment\'s DB record with fulltext, fulltext_tsv, and file_tsv' do+ expect(attachment.fulltext).to eq text+ expect(attachment.fulltext_tsv.size).to be > 0+ expect(attachment.file_tsv.size).to be > 0+ end- # shared_examples 'no fulltext but file name saved as TSV' do- # end+ # shared_examples 'no fulltext but file name saved as TSV' do+ # end- context 'No content was extracted' do- let(:text) { nil }+ context 'No content was extracted' do+ let(:text) { nil }- # include_examples 'no fulltext but file name saved as TSV'- it 'updates the attachment\'s DB record with file_tsv' do- expect(attachment.fulltext).to be_blank- expect(attachment.fulltext_tsv).to be_blank- expect(attachment.file_tsv.size).to be > 0- end+ # include_examples 'no fulltext but file name saved as TSV'+ it 'updates the attachment\'s DB record with file_tsv' do+ expect(attachment.fulltext).to be_blank+ expect(attachment.fulltext_tsv).to be_blank+ expect(attachment.file_tsv.size).to be > 0endendend+ end- shared_examples 'only file name indexed' do- it 'updates the attachment\'s DB record with file_tsv' do- expect(attachment.fulltext).to be_blank- expect(attachment.fulltext_tsv).to be_blank- expect(attachment.file_tsv.size).to be > 0- end+ shared_examples 'only file name indexed' do+ it 'updates the attachment\'s DB record with file_tsv' do+ expect(attachment.fulltext).to be_blank+ expect(attachment.fulltext_tsv).to be_blank+ expect(attachment.file_tsv.size).to be > 0end+ end- context 'file not readable' do- before do- allow(attachment).to receive(:readable?).and_return(false)- attachment.reload- end-- include_examples 'only file name indexed'+ context 'file not readable' do+ before do+ allow(attachment).to receive(:readable?).and_return(false)+ subjectend- context 'with exception in extraction' do- let(:exception_message) { 'boom-internal-error' }- let(:logger) { Rails.logger }+ include_examples 'only file name indexed'+ end- before do- allow_any_instance_of(Plaintext::Resolver).to receive(:text).and_raise(exception_message)+ context 'with exception in extraction' do+ let(:exception_message) { 'boom-internal-error' }+ let(:logger) { Rails.logger }- # This line is actually part of the test. `expect` call needs to go so far up here, as we want to verify that a message gets logged.- expect(logger).to receive(:error).with(/boom-internal-error/)+ before do+ allow_any_instance_of(Plaintext::Resolver).to receive(:text).and_raise(exception_message)- allow(attachment).to receive(:readable?).and_return(true)- attachment.reload- end+ # This line is actually part of the test. `expect` call needs to go so far up here, as we want to verify that a message gets logged.+ expect(logger).to receive(:error).with(/boom-internal-error/)- include_examples 'only file name indexed'+ allow(attachment).to receive(:readable?).and_return(true)+ subjectend++ include_examples 'only file name indexed'endend