Commit 17364563 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'remove-some-easy-factories-from-migration-specs' into 'master'

Remove some easy factories from migration specs

See merge request gitlab-org/gitlab-ce!26025
parents 60713c1f d81597e0
......@@ -36,7 +36,7 @@ describe AddForeignKeysToTodos, :migration do
end
context 'add foreign key on note_id' do
let(:note) { create(:note) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
let(:note) { table(:notes).create! }
let!(:todo_with_note) { create_todo(note_id: note.id) }
let!(:todo_with_invalid_note) { create_todo(note_id: 4711) }
let!(:todo_without_note) { create_todo(note_id: nil) }
......
......@@ -3,12 +3,30 @@
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170803090603_calculate_conv_dev_index_percentages.rb')
describe CalculateConvDevIndexPercentages, :delete do
describe CalculateConvDevIndexPercentages, :migration do
let(:migration) { described_class.new }
let!(:conv_dev_index) do
create(:conversational_development_index_metric, # rubocop:disable RSpec/FactoriesInMigrationSpecs
table(:conversational_development_index_metrics).create!(
leader_issues: 9.256,
leader_notes: 0,
leader_milestones: 16.2456,
leader_boards: 5.2123,
leader_merge_requests: 1.2,
leader_ci_pipelines: 12.1234,
leader_environments: 3.3333,
leader_deployments: 1.200,
leader_projects_prometheus_active: 0.111,
leader_service_desk_issues: 15.891,
instance_issues: 1.234,
instance_notes: 28.123,
instance_milestones: 0,
instance_boards: 3.254,
instance_merge_requests: 0.6,
instance_ci_pipelines: 2.344,
instance_environments: 2.2222,
instance_deployments: 0.771,
instance_projects_prometheus_active: 0.109,
instance_service_desk_issues: 13.345,
percentage_issues: 0,
percentage_notes: 0,
percentage_milestones: 0,
......
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170816102555_cleanup_nonexisting_namespace_pending_delete_projects.rb')
describe CleanupNonexistingNamespacePendingDeleteProjects do
before do
# Stub after_save callbacks that will fail when Project has invalid namespace
allow_any_instance_of(Project).to receive(:ensure_storage_path_exist).and_return(nil)
allow_any_instance_of(Project).to receive(:update_project_statistics).and_return(nil)
end
describe CleanupNonexistingNamespacePendingDeleteProjects, :migration do
let(:projects) { table(:projects) }
let(:namespaces) { table(:namespaces) }
describe '#up' do
set(:some_project) { create(:project) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
let!(:some_project) { projects.create! }
let(:namespace) { namespaces.create!(name: 'test', path: 'test') }
it 'only cleans up when namespace does not exist' do
create(:project, pending_delete: true) # rubocop:disable RSpec/FactoriesInMigrationSpecs
project = build(:project, pending_delete: true, namespace: nil, namespace_id: Namespace.maximum(:id).to_i.succ) # rubocop:disable RSpec/FactoriesInMigrationSpecs
project.save(validate: false)
projects.create!(pending_delete: true, namespace_id: namespace.id)
project = projects.create!(pending_delete: true, namespace_id: 0)
expect(NamespacelessProjectDestroyWorker).to receive(:bulk_perform_async).with([[project.id]])
......@@ -22,7 +19,7 @@ describe CleanupNonexistingNamespacePendingDeleteProjects do
end
it 'does nothing when no pending delete projects without namespace found' do
create(:project, pending_delete: true, namespace: create(:namespace)) # rubocop:disable RSpec/FactoriesInMigrationSpecs
projects.create!(pending_delete: true, namespace_id: namespace.id)
expect(NamespacelessProjectDestroyWorker).not_to receive(:bulk_perform_async)
......
require 'spec_helper'
require Rails.root.join('db', 'migrate', '20171106151218_issues_moved_to_id_foreign_key.rb')
# The schema version has to be far enough in advance to have the
# only_mirror_protected_branches column in the projects table to create a
# project via FactoryBot.
describe IssuesMovedToIdForeignKey, :migration, schema: 20171114150259 do
let!(:issue_first) { create(:issue, moved_to_id: issue_second.id) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
let!(:issue_second) { create(:issue, moved_to_id: issue_third.id) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
let!(:issue_third) { create(:issue) } # rubocop:disable RSpec/FactoriesInMigrationSpecs
describe IssuesMovedToIdForeignKey, :migration do
let(:issues) { table(:issues) }
let!(:issue_third) { issues.create! }
let!(:issue_second) { issues.create!(moved_to_id: issue_third.id) }
let!(:issue_first) { issues.create!(moved_to_id: issue_second.id) }
subject { described_class.new }
it 'removes the orphaned moved_to_id' do
subject.down
issue_third.update(moved_to_id: 100000)
issue_third.update!(moved_to_id: 0)
subject.up
......
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20170612071012_move_personal_snippets_files.rb')
describe MovePersonalSnippetsFiles do
describe MovePersonalSnippetsFiles, :migration do
let(:migration) { described_class.new }
let(:test_dir) { File.join(Rails.root, "tmp", "tests", "move_snippet_files_test") }
let(:uploads_dir) { File.join(test_dir, 'uploads') }
let(:new_uploads_dir) { File.join(uploads_dir, '-', 'system') }
let(:notes) { table(:notes) }
let(:snippets) { table(:snippets) }
let(:uploads) { table(:uploads) }
let(:user) { table(:users).create!(email: 'user@example.com', projects_limit: 10) }
let(:project) { table(:projects).create!(name: 'gitlab', namespace_id: 1) }
before do
allow(CarrierWave).to receive(:root).and_return(test_dir)
allow(migration).to receive(:base_directory).and_return(test_dir)
......@@ -16,14 +23,14 @@ describe MovePersonalSnippetsFiles do
describe "#up" do
let(:snippet) do
snippet = create(:personal_snippet) # rubocop:disable RSpec/FactoriesInMigrationSpecs
snippet = snippets.create!(author_id: user.id)
create_upload('picture.jpg', snippet)
snippet.update(description: markdown_linking_file('picture.jpg', snippet))
snippet
end
let(:snippet_with_missing_file) do
snippet = create(:snippet) # rubocop:disable RSpec/FactoriesInMigrationSpecs
snippet = snippets.create!(author_id: user.id, project_id: project.id)
create_upload('picture.jpg', snippet, create_file: false)
snippet.update(description: markdown_linking_file('picture.jpg', snippet))
snippet
......@@ -62,7 +69,10 @@ describe MovePersonalSnippetsFiles do
secret = "secret#{snippet.id}"
file_location = "/uploads/-/system/personal_snippet/#{snippet.id}/#{secret}/picture.jpg"
markdown = markdown_linking_file('picture.jpg', snippet)
note = create(:note_on_personal_snippet, noteable: snippet, note: "with #{markdown}") # rubocop:disable RSpec/FactoriesInMigrationSpecs
note = notes.create!(noteable_id: snippet.id,
noteable_type: Snippet,
note: "with #{markdown}",
author_id: user.id)
migration.up
......@@ -73,14 +83,14 @@ describe MovePersonalSnippetsFiles do
describe "#down" do
let(:snippet) do
snippet = create(:personal_snippet) # rubocop:disable RSpec/FactoriesInMigrationSpecs
snippet = snippets.create!(author_id: user.id)
create_upload('picture.jpg', snippet, in_new_path: true)
snippet.update(description: markdown_linking_file('picture.jpg', snippet, in_new_path: true))
snippet
end
let(:snippet_with_missing_file) do
snippet = create(:personal_snippet) # rubocop:disable RSpec/FactoriesInMigrationSpecs
snippet = snippets.create!(author_id: user.id)
create_upload('picture.jpg', snippet, create_file: false, in_new_path: true)
snippet.update(description: markdown_linking_file('picture.jpg', snippet, in_new_path: true))
snippet
......@@ -119,7 +129,10 @@ describe MovePersonalSnippetsFiles do
markdown = markdown_linking_file('picture.jpg', snippet, in_new_path: true)
secret = "secret#{snippet.id}"
file_location = "/uploads/personal_snippet/#{snippet.id}/#{secret}/picture.jpg"
note = create(:note_on_personal_snippet, noteable: snippet, note: "with #{markdown}") # rubocop:disable RSpec/FactoriesInMigrationSpecs
note = notes.create!(noteable_id: snippet.id,
noteable_type: Snippet,
note: "with #{markdown}",
author_id: user.id)
migration.down
......@@ -135,7 +148,7 @@ describe MovePersonalSnippetsFiles do
secret = '123456789'
filename = 'hello.jpg'
snippet = create(:personal_snippet) # rubocop:disable RSpec/FactoriesInMigrationSpecs
snippet = snippets.create!(author_id: user.id)
path_before = "/uploads/personal_snippet/#{snippet.id}/#{secret}/#{filename}"
path_after = "/uploads/system/personal_snippet/#{snippet.id}/#{secret}/#{filename}"
......@@ -161,7 +174,11 @@ describe MovePersonalSnippetsFiles do
FileUtils.touch(absolute_path)
end
create(:upload, model: snippet, path: "#{secret}/#{filename}", uploader: PersonalFileUploader) # rubocop:disable RSpec/FactoriesInMigrationSpecs
uploads.create!(model_id: snippet.id,
model_type: snippet.class,
path: "#{secret}/#{filename}",
uploader: PersonalFileUploader,
size: 100.kilobytes)
end
def markdown_linking_file(filename, snippet, in_new_path: false)
......
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