Commit 8f537845 authored by Markus Koller's avatar Markus Koller

Fix migration specs using factories

We need to stub default_git_depth and default_git_depth= because some
old migrations specs try to create a record using schema before that
column was introduced.

The `let!` calls were executed before the `before` hook which still
caused some factories to fail, so they're created in the `before` hook
now as well.
parent 3ef0c549
...@@ -5,23 +5,39 @@ describe Gitlab::BackgroundMigration::MigrateLegacyUploads, :migration, schema: ...@@ -5,23 +5,39 @@ describe Gitlab::BackgroundMigration::MigrateLegacyUploads, :migration, schema:
let(:test_dir) { FileUploader.options['storage_path'] } let(:test_dir) { FileUploader.options['storage_path'] }
# rubocop: disable RSpec/FactoriesInMigrationSpecs # rubocop: disable RSpec/FactoriesInMigrationSpecs
let!(:namespace) { create(:namespace) } let(:namespace) { create(:namespace) }
let!(:project) { create(:project, :legacy_storage, namespace: namespace) } let(:project) { create(:project, :legacy_storage, namespace: namespace) }
let!(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
let!(:note1) { create(:note, note: 'some note text awesome', project: project, noteable: issue) } let(:note1) { create(:note, note: 'some note text awesome', project: project, noteable: issue) }
let!(:note2) { create(:note, note: 'some note', project: project, noteable: issue) } let(:note2) { create(:note, note: 'some note', project: project, noteable: issue) }
let!(:hashed_project) { create(:project, namespace: namespace) } let(:hashed_project) { create(:project, namespace: namespace) }
let!(:issue_hashed_project) { create(:issue, project: hashed_project) } let(:issue_hashed_project) { create(:issue, project: hashed_project) }
let!(:note_hashed_project) { create(:note, note: 'some note', project: hashed_project, attachment: 'text.pdf', noteable: issue_hashed_project) } let(:note_hashed_project) { create(:note, note: 'some note', project: hashed_project, attachment: 'text.pdf', noteable: issue_hashed_project) }
let!(:standard_upload) do let(:standard_upload) do
create(:upload, create(:upload,
path: "secretabcde/image.png", path: "secretabcde/image.png",
model_id: create(:project).id, model_type: 'Project', uploader: 'FileUploader') model_id: create(:project).id, model_type: 'Project', uploader: 'FileUploader')
end end
before do
# This migration was created before we introduced ProjectCiCdSetting#default_git_depth
allow_any_instance_of(ProjectCiCdSetting).to receive(:default_git_depth).and_return(nil)
allow_any_instance_of(ProjectCiCdSetting).to receive(:default_git_depth=).and_return(0)
namespace
project
issue
note1
note2
hashed_project
issue_hashed_project
note_hashed_project
standard_upload
end
def create_remote_upload(model, filename) def create_remote_upload(model, filename)
create(:upload, :attachment_upload, create(:upload, :attachment_upload,
path: "note/attachment/#{model.id}/#{filename}", secret: nil, path: "note/attachment/#{model.id}/#{filename}", secret: nil,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment