diff options
author | Felipe Artur <felipefac@gmail.com> | 2019-03-27 21:19:12 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2019-03-27 21:19:12 +0300 |
commit | 16a3fea3998e813b95d7d09ea31f6a88dc908102 (patch) | |
tree | f896b456433d21ab5d8b3dd24625348175ac06a6 /spec/migrations | |
parent | 294c5c41beaac1fbc60c67df2c8745f7583544a1 (diff) | |
parent | 97f8d4e96870324c4ce6534022397d33c4bf5dbc (diff) |
Merge master
Diffstat (limited to 'spec/migrations')
11 files changed, 196 insertions, 95 deletions
diff --git a/spec/migrations/add_foreign_keys_to_todos_spec.rb b/spec/migrations/add_foreign_keys_to_todos_spec.rb index efd87173b9c..2500e2f8333 100644 --- a/spec/migrations/add_foreign_keys_to_todos_spec.rb +++ b/spec/migrations/add_foreign_keys_to_todos_spec.rb @@ -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) } diff --git a/spec/migrations/add_head_pipeline_for_each_merge_request_spec.rb b/spec/migrations/add_head_pipeline_for_each_merge_request_spec.rb index d8dd7a2fb83..13dc62595b5 100644 --- a/spec/migrations/add_head_pipeline_for_each_merge_request_spec.rb +++ b/spec/migrations/add_head_pipeline_for_each_merge_request_spec.rb @@ -1,23 +1,21 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20170508170547_add_head_pipeline_for_each_merge_request.rb') -describe AddHeadPipelineForEachMergeRequest, :delete do - include ProjectForksHelper - +describe AddHeadPipelineForEachMergeRequest, :migration do let(:migration) { described_class.new } - let!(:project) { create(:project) } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:other_project) { fork_project(project) } + let!(:project) { table(:projects).create! } + let!(:other_project) { table(:projects).create! } - let!(:pipeline_1) { create(:ci_pipeline, project: project, ref: "branch_1") } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:pipeline_2) { create(:ci_pipeline, project: other_project, ref: "branch_1") } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:pipeline_3) { create(:ci_pipeline, project: other_project, ref: "branch_1") } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:pipeline_4) { create(:ci_pipeline, project: project, ref: "branch_2") } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:pipeline_1) { table(:ci_pipelines).create!(project_id: project.id, ref: "branch_1") } + let!(:pipeline_2) { table(:ci_pipelines).create!(project_id: other_project.id, ref: "branch_1") } + let!(:pipeline_3) { table(:ci_pipelines).create!(project_id: other_project.id, ref: "branch_1") } + let!(:pipeline_4) { table(:ci_pipelines).create!(project_id: project.id, ref: "branch_2") } - let!(:mr_1) { create(:merge_request, source_project: project, target_project: project, source_branch: "branch_1", target_branch: "target_1") } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:mr_2) { create(:merge_request, source_project: other_project, target_project: project, source_branch: "branch_1", target_branch: "target_2") } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:mr_3) { create(:merge_request, source_project: project, target_project: project, source_branch: "branch_2", target_branch: "master") } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:mr_4) { create(:merge_request, source_project: project, target_project: project, source_branch: "branch_3", target_branch: "master") } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:mr_1) { table(:merge_requests).create!(source_project_id: project.id, target_project_id: project.id, source_branch: "branch_1", target_branch: "target_1") } + let!(:mr_2) { table(:merge_requests).create!(source_project_id: other_project.id, target_project_id: project.id, source_branch: "branch_1", target_branch: "target_2") } + let!(:mr_3) { table(:merge_requests).create!(source_project_id: project.id, target_project_id: project.id, source_branch: "branch_2", target_branch: "master") } + let!(:mr_4) { table(:merge_requests).create!(source_project_id: project.id, target_project_id: project.id, source_branch: "branch_3", target_branch: "master") } context "#up" do context "when source_project and source_branch of pipeline are the same of merge request" do diff --git a/spec/migrations/calculate_conv_dev_index_percentages_spec.rb b/spec/migrations/calculate_conv_dev_index_percentages_spec.rb index 19f06810e54..09c78d02890 100644 --- a/spec/migrations/calculate_conv_dev_index_percentages_spec.rb +++ b/spec/migrations/calculate_conv_dev_index_percentages_spec.rb @@ -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, diff --git a/spec/migrations/cleanup_nonexisting_namespace_pending_delete_projects_spec.rb b/spec/migrations/cleanup_nonexisting_namespace_pending_delete_projects_spec.rb index 8f40ac3e38b..0e6bded29b4 100644 --- a/spec/migrations/cleanup_nonexisting_namespace_pending_delete_projects_spec.rb +++ b/spec/migrations/cleanup_nonexisting_namespace_pending_delete_projects_spec.rb @@ -1,20 +1,17 @@ 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) diff --git a/spec/migrations/delete_inconsistent_internal_id_records_spec.rb b/spec/migrations/delete_inconsistent_internal_id_records_spec.rb index e2ce69a7bb1..58b8b4a16f0 100644 --- a/spec/migrations/delete_inconsistent_internal_id_records_spec.rb +++ b/spec/migrations/delete_inconsistent_internal_id_records_spec.rb @@ -1,25 +1,36 @@ # frozen_string_literal: true -# rubocop:disable RSpec/FactoriesInMigrationSpecs + require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20180723130817_delete_inconsistent_internal_id_records.rb') describe DeleteInconsistentInternalIdRecords, :migration do - let!(:project1) { create(:project) } - let!(:project2) { create(:project) } - let!(:project3) { create(:project) } + let!(:namespace) { table(:namespaces).create!(name: 'test', path: 'test') } + let!(:project1) { table(:projects).create!(namespace_id: namespace.id) } + let!(:project2) { table(:projects).create!(namespace_id: namespace.id) } + let!(:project3) { table(:projects).create!(namespace_id: namespace.id) } - let(:internal_id_query) { ->(project) { InternalId.where(usage: InternalId.usages[scope.to_s.tableize], project: project) } } + let(:internal_ids) { table(:internal_ids) } + let(:internal_id_query) { ->(project) { InternalId.where(usage: InternalId.usages[scope.to_s.tableize], project_id: project.id) } } let(:create_models) do - 3.times { create(scope, project: project1) } - 3.times { create(scope, project: project2) } - 3.times { create(scope, project: project3) } + [project1, project2, project3].each do |project| + 3.times do |i| + attributes = required_attributes.merge(project_id: project.id, + iid: i.succ) + + table(scope.to_s.pluralize).create!(attributes) + end + end end shared_examples_for 'deleting inconsistent internal_id records' do before do create_models + [project1, project2, project3].each do |project| + internal_ids.create!(project_id: project.id, usage: InternalId.usages[scope.to_s.tableize], last_value: 3) + end + internal_id_query.call(project1).first.tap do |iid| iid.last_value = iid.last_value - 2 # This is an inconsistent record @@ -33,11 +44,11 @@ describe DeleteInconsistentInternalIdRecords, :migration do end end - it "deletes inconsistent issues" do + it "deletes inconsistent records" do expect { migrate! }.to change { internal_id_query.call(project1).size }.from(1).to(0) end - it "retains consistent issues" do + it "retains consistent records" do expect { migrate! }.not_to change { internal_id_query.call(project2).size } end @@ -48,6 +59,8 @@ describe DeleteInconsistentInternalIdRecords, :migration do context 'for issues' do let(:scope) { :issue } + let(:required_attributes) { {} } + it_behaves_like 'deleting inconsistent internal_id records' end @@ -55,9 +68,17 @@ describe DeleteInconsistentInternalIdRecords, :migration do let(:scope) { :merge_request } let(:create_models) do - 3.times { |i| create(scope, target_project: project1, source_project: project1, source_branch: i.to_s) } - 3.times { |i| create(scope, target_project: project2, source_project: project2, source_branch: i.to_s) } - 3.times { |i| create(scope, target_project: project3, source_project: project3, source_branch: i.to_s) } + [project1, project2, project3].each do |project| + 3.times do |i| + table(:merge_requests).create!( + target_project_id: project.id, + source_project_id: project.id, + target_branch: 'master', + source_branch: j.to_s, + iid: i.succ + ) + end + end end it_behaves_like 'deleting inconsistent internal_id records' @@ -66,13 +87,6 @@ describe DeleteInconsistentInternalIdRecords, :migration do context 'for deployments' do let(:scope) { :deployment } let(:deployments) { table(:deployments) } - let(:internal_ids) { table(:internal_ids) } - - before do - internal_ids.create!(project_id: project1.id, usage: 2, last_value: 2) - internal_ids.create!(project_id: project2.id, usage: 2, last_value: 2) - internal_ids.create!(project_id: project3.id, usage: 2, last_value: 2) - end let(:create_models) do 3.times { |i| deployments.create!(project_id: project1.id, iid: i, environment_id: 1, ref: 'master', sha: 'a', tag: false) } @@ -85,17 +99,14 @@ describe DeleteInconsistentInternalIdRecords, :migration do context 'for milestones (by project)' do let(:scope) { :milestone } + let(:required_attributes) { { title: 'test' } } + it_behaves_like 'deleting inconsistent internal_id records' end context 'for ci_pipelines' do let(:scope) { :ci_pipeline } - - let(:create_models) do - create_list(:ci_empty_pipeline, 3, project: project1) - create_list(:ci_empty_pipeline, 3, project: project2) - create_list(:ci_empty_pipeline, 3, project: project3) - end + let(:required_attributes) { { ref: 'test' } } it_behaves_like 'deleting inconsistent internal_id records' end @@ -107,12 +118,20 @@ describe DeleteInconsistentInternalIdRecords, :migration do let(:group2) { groups.create(name: 'Group 2', type: 'Group', path: 'group_2') } let(:group3) { groups.create(name: 'Group 2', type: 'Group', path: 'group_3') } - let(:internal_id_query) { ->(group) { InternalId.where(usage: InternalId.usages['milestones'], namespace: group) } } + let(:internal_id_query) { ->(group) { InternalId.where(usage: InternalId.usages['milestones'], namespace_id: group.id) } } before do - 3.times { create(:milestone, group_id: group1.id) } - 3.times { create(:milestone, group_id: group2.id) } - 3.times { create(:milestone, group_id: group3.id) } + [group1, group2, group3].each do |group| + 3.times do |i| + table(:milestones).create!( + group_id: group.id, + title: 'test', + iid: i.succ + ) + end + + internal_ids.create!(namespace_id: group.id, usage: InternalId.usages['milestones'], last_value: 3) + end internal_id_query.call(group1).first.tap do |iid| iid.last_value = iid.last_value - 2 @@ -127,11 +146,11 @@ describe DeleteInconsistentInternalIdRecords, :migration do end end - it "deletes inconsistent issues" do + it "deletes inconsistent records" do expect { migrate! }.to change { internal_id_query.call(group1).size }.from(1).to(0) end - it "retains consistent issues" do + it "retains consistent records" do expect { migrate! }.not_to change { internal_id_query.call(group2).size } end diff --git a/spec/migrations/issues_moved_to_id_foreign_key_spec.rb b/spec/migrations/issues_moved_to_id_foreign_key_spec.rb index 495e86ee888..71a4e71ac8a 100644 --- a/spec/migrations/issues_moved_to_id_foreign_key_spec.rb +++ b/spec/migrations/issues_moved_to_id_foreign_key_spec.rb @@ -1,20 +1,19 @@ 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 diff --git a/spec/migrations/migrate_old_artifacts_spec.rb b/spec/migrations/migrate_old_artifacts_spec.rb index af77d64fdbf..79e21514506 100644 --- a/spec/migrations/migrate_old_artifacts_spec.rb +++ b/spec/migrations/migrate_old_artifacts_spec.rb @@ -3,7 +3,9 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20170523083112_migrate_old_artifacts.rb') -describe MigrateOldArtifacts do +# Adding the ci_job_artifacts table (from the 20170918072948 schema) +# makes the use of model code below easier. +describe MigrateOldArtifacts, :migration, schema: 20170918072948 do let(:migration) { described_class.new } let!(:directory) { Dir.mktmpdir } @@ -16,18 +18,22 @@ describe MigrateOldArtifacts do end context 'with migratable data' do - set(:project1) { create(:project, ci_id: 2) } # rubocop:disable RSpec/FactoriesInMigrationSpecs - set(:project2) { create(:project, ci_id: 3) } # rubocop:disable RSpec/FactoriesInMigrationSpecs - set(:project3) { create(:project) } # rubocop:disable RSpec/FactoriesInMigrationSpecs - - set(:pipeline1) { create(:ci_empty_pipeline, project: project1) } # rubocop:disable RSpec/FactoriesInMigrationSpecs - set(:pipeline2) { create(:ci_empty_pipeline, project: project2) } # rubocop:disable RSpec/FactoriesInMigrationSpecs - set(:pipeline3) { create(:ci_empty_pipeline, project: project3) } # rubocop:disable RSpec/FactoriesInMigrationSpecs - - let!(:build_with_legacy_artifacts) { create(:ci_build, pipeline: pipeline1) } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:build_without_artifacts) { create(:ci_build, pipeline: pipeline1) } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:build2) { create(:ci_build, pipeline: pipeline2) } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:build3) { create(:ci_build, pipeline: pipeline3) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let(:projects) { table(:projects) } + let(:ci_pipelines) { table(:ci_pipelines) } + let(:ci_builds) { table(:ci_builds) } + + let!(:project1) { projects.create!(ci_id: 2) } + let!(:project2) { projects.create!(ci_id: 3) } + let!(:project3) { projects.create! } + + let!(:pipeline1) { ci_pipelines.create!(project_id: project1.id) } + let!(:pipeline2) { ci_pipelines.create!(project_id: project2.id) } + let!(:pipeline3) { ci_pipelines.create!(project_id: project3.id) } + + let!(:build_with_legacy_artifacts) { ci_builds.create!(commit_id: pipeline1.id, project_id: project1.id, type: 'Ci::Build').becomes(Ci::Build) } + let!(:build_without_artifacts) { ci_builds.create!(commit_id: pipeline1.id, project_id: project1.id, type: 'Ci::Build').becomes(Ci::Build) } + let!(:build2) { ci_builds.create!(commit_id: pipeline2.id, project_id: project2.id, type: 'Ci::Build').becomes(Ci::Build) } + let!(:build3) { ci_builds.create!(commit_id: pipeline3.id, project_id: project3.id, type: 'Ci::Build').becomes(Ci::Build) } before do setup_builds(build2, build3) diff --git a/spec/migrations/migrate_user_activities_to_users_last_activity_on_spec.rb b/spec/migrations/migrate_user_activities_to_users_last_activity_on_spec.rb index 99173708190..88aef3b70b4 100644 --- a/spec/migrations/migrate_user_activities_to_users_last_activity_on_spec.rb +++ b/spec/migrations/migrate_user_activities_to_users_last_activity_on_spec.rb @@ -3,10 +3,10 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20170324160416_migrate_user_activities_to_users_last_activity_on.rb') -describe MigrateUserActivitiesToUsersLastActivityOn, :clean_gitlab_redis_shared_state, :delete do +describe MigrateUserActivitiesToUsersLastActivityOn, :clean_gitlab_redis_shared_state, :migration do let(:migration) { described_class.new } - let!(:user_active_1) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:user_active_2) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:user_active_1) { table(:users).create!(email: 'test1', username: 'test1') } + let!(:user_active_2) { table(:users).create!(email: 'test2', username: 'test2') } def record_activity(user, time) Gitlab::Redis::SharedState.with do |redis| diff --git a/spec/migrations/migrate_user_project_view_spec.rb b/spec/migrations/migrate_user_project_view_spec.rb index 80468b9d01e..a0179ab3ceb 100644 --- a/spec/migrations/migrate_user_project_view_spec.rb +++ b/spec/migrations/migrate_user_project_view_spec.rb @@ -3,15 +3,15 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20170406142253_migrate_user_project_view.rb') -describe MigrateUserProjectView, :delete do +describe MigrateUserProjectView, :migration do let(:migration) { described_class.new } - let!(:user) { create(:user, project_view: 'readme') } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:user) { table(:users).create!(project_view: User.project_views['readme']) } describe '#up' do it 'updates project view setting with new value' do migration.up - expect(user.reload.project_view).to eq('files') + expect(user.reload.project_view).to eq(User.project_views['files']) end end end diff --git a/spec/migrations/move_personal_snippets_files_spec.rb b/spec/migrations/move_personal_snippets_files_spec.rb index 1f39ad98fb8..d94ae1e52f5 100644 --- a/spec/migrations/move_personal_snippets_files_spec.rb +++ b/spec/migrations/move_personal_snippets_files_spec.rb @@ -1,12 +1,19 @@ 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) diff --git a/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb b/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb new file mode 100644 index 00000000000..e397fbb7138 --- /dev/null +++ b/spec/migrations/schedule_populate_merge_request_assignees_table_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20190322132835_schedule_populate_merge_request_assignees_table.rb') + +describe SchedulePopulateMergeRequestAssigneesTable, :migration, :sidekiq do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:namespace) { namespaces.create(name: 'gitlab', path: 'gitlab-org') } + let(:project) { projects.create(namespace_id: namespace.id, name: 'foo') } + let(:merge_requests) { table(:merge_requests) } + + def create_merge_request(id) + params = { + id: id, + target_project_id: project.id, + target_branch: 'master', + source_project_id: project.id, + source_branch: 'mr name', + title: "mr name#{id}" + } + + merge_requests.create!(params) + end + + it 'correctly schedules background migrations' do + create_merge_request(1) + create_merge_request(2) + create_merge_request(3) + + stub_const("#{described_class.name}::BATCH_SIZE", 2) + + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(described_class::MIGRATION) + .to be_scheduled_delayed_migration(8.minutes, 1, 2) + + expect(described_class::MIGRATION) + .to be_scheduled_delayed_migration(16.minutes, 3, 3) + + expect(BackgroundMigrationWorker.jobs.size).to eq(2) + end + end + end +end |