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 prepared upload specs
Oliver Günther2508ede65cec
diff --git a/app/models/attachment.rb b/app/models/attachment.rbindex da8a646dc77..2dbce28730e 100644--- a/app/models/attachment.rb+++ b/app/models/attachment.rb@@ -72,8 +72,8 @@ class Attachment < ApplicationRecordafter_commit :enqueue_jobs, on: :create, if: -> { !internal_container? }- scope :pending_direct_upload, -> { where(digest: "", downloads: -1) }- scope :not_pending_direct_upload, -> { where.not(digest: "", downloads: -1) }+ scope :pending_direct_upload, -> { status_prepared }+ scope :not_pending_direct_upload, -> { not_status_prepared }### Returns an URL if the attachment is stored in an external (fog) attachment storage@@ -248,15 +248,19 @@ class Attachment < ApplicationRecordenddef enqueue_jobs- if OpenProject::Database.allows_tsv? && (!container || container.class.attachment_tsv_extracted?)- Attachments::ExtractFulltextJob.perform_later(id)- end+ extract_fulltextif pending_virus_scan?Attachments::VirusScanJob.perform_later(self)endend+ def extract_fulltext+ if OpenProject::Database.allows_tsv? && (!container || container.class.attachment_tsv_extracted?)+ Attachments::ExtractFulltextJob.perform_later(id)+ end+ end+# Extract the fulltext of any attachments where fulltext is still nil.# This runs inline and not in an asynchronous worker.def self.extract_fulltext_where_missing(run_now: true)@@ -315,6 +319,10 @@ class Attachment < ApplicationRecorddigest == "" && downloads == -1end+ def internal_container?+ container&.is_a?(Export)+ end+privatedef filesize_below_allowed_maximum@@ -323,10 +331,6 @@ class Attachment < ApplicationRecordendend- def internal_container?- container&.is_a?(Export)- end-def container_changed_more_than_onceif container_id_changed_more_than_once? || container_type_changed_more_than_once?errors.add(:container, :unchangeable)diff --git a/app/workers/attachments/finish_direct_upload_job.rb b/app/workers/attachments/finish_direct_upload_job.rbindex 4454abc6a0c..b99ed1ca0e1 100644--- a/app/workers/attachments/finish_direct_upload_job.rb+++ b/app/workers/attachments/finish_direct_upload_job.rb@@ -91,7 +91,7 @@ class Attachments::FinishDirectUploadJob < ApplicationJoboptions:end- def schedule_jobs+ def schedule_jobs(attachment)attachment.extract_fulltextenddiff --git a/spec/factories/attachment_factory.rb b/spec/factories/attachment_factory.rbindex d4c89749aa2..885c49cd394 100644--- a/spec/factories/attachment_factory.rb+++ b/spec/factories/attachment_factory.rb@@ -58,8 +58,7 @@ FactoryBot.define doendfactory :pending_direct_upload do- digest { "" }- downloads { -1 }+ status { 'prepared' }created_at { DateTime.now - 2.weeks }endenddiff --git a/spec/models/attachment_spec.rb b/spec/models/attachment_spec.rbindex 5f5b9ccbcce..cc0017451f7 100644--- a/spec/models/attachment_spec.rb+++ b/spec/models/attachment_spec.rb@@ -323,7 +323,9 @@ RSpec.describe Attachment doendend- context 'with setting enabled', with_settings: { antivirus_scan_mode: :clamav_socket } do+ context 'with setting enabled',+ with_ee: %i[virus_scanning],+ with_settings: { antivirus_scan_mode: :clamav_socket } doit 'runs the job' doattachment.saveexpect(attachment.pending_virus_scan?).to be truediff --git a/spec/requests/api/v3/attachments_spec.rb b/spec/requests/api/v3/attachments_spec.rbindex b05203db31f..d84b9e539c0 100644--- a/spec/requests/api/v3/attachments_spec.rb+++ b/spec/requests/api/v3/attachments_spec.rb@@ -81,9 +81,9 @@ RSpec.describe API::V3::Attachments::AttachmentsAPI dolet(:container_href) { nil }describe 'GET /uploaded' do- let(:digest) { "" }+ let(:status) { :prepared }let(:attachment) do- create(:attachment, digest:, author: current_user, container: nil, container_type: nil, downloads: -1)+ create(:attachment, status:, author: current_user, container: nil, container_type: nil)endbefore do@@ -91,7 +91,7 @@ RSpec.describe API::V3::Attachments::AttachmentsAPI doendcontext 'with no pending attachments' do- let(:digest) { "0xFF" }+ let(:status) { :uploaded }it 'returns 404' doexpect(last_response.status).to eq 404diff --git a/spec/services/attachments/prepare_upload_service_integration_spec.rb b/spec/services/attachments/prepare_upload_service_integration_spec.rbindex a5db9a919d4..9af9f848721 100644--- a/spec/services/attachments/prepare_upload_service_integration_spec.rb+++ b/spec/services/attachments/prepare_upload_service_integration_spec.rb@@ -79,9 +79,8 @@ RSpec.describe Attachments::PrepareUploadService,.to eql ""end- it 'sets the download count to -1' do- expect(attachment.downloads)- .to be -1+ it 'sets the status to prepared' do+ expect(attachment.status).to eq 'prepared'endcontext 'with a special character in the filename' dodiff --git a/spec/workers/attachments/cleanup_uncontainered_job_integration_spec.rb b/spec/workers/attachments/cleanup_uncontainered_job_integration_spec.rbindex bc94bf8a6e4..4b38aa370e1 100644--- a/spec/workers/attachments/cleanup_uncontainered_job_integration_spec.rb+++ b/spec/workers/attachments/cleanup_uncontainered_job_integration_spec.rb@@ -40,13 +40,13 @@ RSpec.describe Attachments::CleanupUncontaineredJob, type: :job doendlet!(:finished_upload) do- create(:attachment, created_at: Time.now - grace_period.minutes, digest: "0x42")+ create(:attachment, created_at: Time.now - grace_period.minutes, status: :uploaded)endlet!(:old_pending_upload) do- create(:attachment, created_at: Time.now - grace_period.minutes, digest: "", downloads: -1)+ create(:attachment, created_at: Time.now - grace_period.minutes, status: :prepared)endlet!(:new_pending_upload) do- create(:attachment, created_at: Time.now - (grace_period - 1).minutes, digest: "", downloads: -1)+ create(:attachment, created_at: Time.now - (grace_period - 1).minutes, status: :prepared)endlet(:job) { described_class.new }diff --git a/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb b/spec/workers/attachments/finish_direct_upload_job_integration_spec.rbindex 2e13ef8326f..d647aeb3e0a 100644--- a/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb+++ b/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb@@ -34,7 +34,7 @@ RSpec.describe Attachments::FinishDirectUploadJob, 'integration', type: :job dolet!(:pending_attachment) docreate(:attachment,author: user,- downloads: -1,+ status: :prepared,digest: '',container:)end@@ -47,6 +47,7 @@ RSpec.describe Attachments::FinishDirectUploadJob, 'integration', type: :job doattachment = Attachment.find(pending_attachment.id)+ expect(attachment.status).to eq 'uploaded'expect(attachment.downloads).to be(0)# expect to replace the content type with the actual value