diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2018-05-04 14:58:47 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2018-05-04 14:58:47 +0100 |
commit | 1983356d647290fe38ca21bbbca43fe2d6292913 (patch) | |
tree | d07fba5693e239993dfc6d1f724b2103f90a3fa6 /spec/migrations | |
parent | 703f45632292e7fc45359d0144cd616725bf9b0d (diff) | |
parent | 4bf47cd76fd69a26b7b2b4ac029f088ec5493712 (diff) | |
download | gitlab-ce-1983356d647290fe38ca21bbbca43fe2d6292913.tar.gz |
Merge branch 'master' into 44427-state-management-with-vuext
* master: (1063 commits)
Replace commits spinach tests with RSpec analog
Update repository.rb
Add note about rebase/squash duplication in Gitaly
Resolve "Reconcile project templates with Auto DevOps"
Move import project pane to a separate partial
Inform the user when there are no project import options available
Clarify location of Vue templates
Make add_index_to_namespaces_runners_token migration reversible
Fix lambda arguments in Grape entities
Update grape-entity 0.6.0 -> 0.7.1
Fix constants in backfill_runner_type_for_ci_runners_post_migrate.rb
Use limited_counter_with_delimiter in the admin user list tabs
Remove a warning from spec/features/admin/admin_users_spec.rb
Use smallint for runner_type since its an enum
Dont remove duplicates in Runner.owned_or_shared since its not necessary
Change the docs license to CC BY-SA
Remove unnecessary disable transaction in add_ci_runner_namespaces
Split migration to add and index namespaces.runners_token
Output some useful information when running the rails console
Revert "Use factory in specs for ProjectCiCdSettings"
...
Diffstat (limited to 'spec/migrations')
29 files changed, 306 insertions, 91 deletions
diff --git a/spec/migrations/active_record/schedule_set_confidential_note_events_on_services_spec.rb b/spec/migrations/active_record/schedule_set_confidential_note_events_on_services_spec.rb new file mode 100644 index 00000000000..4395e2f8264 --- /dev/null +++ b/spec/migrations/active_record/schedule_set_confidential_note_events_on_services_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20180122154930_schedule_set_confidential_note_events_on_services.rb') + +describe ScheduleSetConfidentialNoteEventsOnServices, :migration, :sidekiq do + let(:services_table) { table(:services) } + let(:migration_class) { Gitlab::BackgroundMigration::SetConfidentialNoteEventsOnServices } + let(:migration_name) { migration_class.to_s.demodulize } + + let!(:service_1) { services_table.create!(confidential_note_events: nil, note_events: true) } + let!(:service_2) { services_table.create!(confidential_note_events: nil, note_events: true) } + let!(:service_migrated) { services_table.create!(confidential_note_events: true, note_events: true) } + let!(:service_skip) { services_table.create!(confidential_note_events: nil, note_events: false) } + let!(:service_new) { services_table.create!(confidential_note_events: false, note_events: true) } + let!(:service_4) { services_table.create!(confidential_note_events: nil, note_events: true) } + + before do + stub_const("#{described_class}::BATCH_SIZE", 1) + end + + it 'schedules background migrations at correct time' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(migration_name).to be_scheduled_delayed_migration(20.minutes, service_1.id, service_1.id) + expect(migration_name).to be_scheduled_delayed_migration(40.minutes, service_2.id, service_2.id) + expect(migration_name).to be_scheduled_delayed_migration(60.minutes, service_4.id, service_4.id) + expect(BackgroundMigrationWorker.jobs.size).to eq 3 + end + end + end + + it 'correctly processes services' do + Sidekiq::Testing.inline! do + expect(services_table.where(confidential_note_events: nil).count).to eq 4 + expect(services_table.where(confidential_note_events: true).count).to eq 1 + + migrate! + + expect(services_table.where(confidential_note_events: nil).count).to eq 1 + expect(services_table.where(confidential_note_events: true).count).to eq 4 + end + end +end diff --git a/spec/migrations/add_foreign_keys_to_todos_spec.rb b/spec/migrations/add_foreign_keys_to_todos_spec.rb index 4a22bd6f342..bf2fa5c0f56 100644 --- a/spec/migrations/add_foreign_keys_to_todos_spec.rb +++ b/spec/migrations/add_foreign_keys_to_todos_spec.rb @@ -4,8 +4,8 @@ require Rails.root.join('db', 'migrate', '20180201110056_add_foreign_keys_to_tod describe AddForeignKeysToTodos, :migration do let(:todos) { table(:todos) } - let(:project) { create(:project) } - let(:user) { create(:user) } + let(:project) { create(:project) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let(:user) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs context 'add foreign key on user_id' do let!(:todo_with_user) { create_todo(user_id: user.id) } @@ -34,7 +34,7 @@ describe AddForeignKeysToTodos, :migration do end context 'add foreign key on note_id' do - let(:note) { create(:note) } + let(:note) { create(:note) } # rubocop:disable RSpec/FactoriesInMigrationSpecs 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 63defcb39bf..d8dd7a2fb83 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 @@ -6,18 +6,18 @@ describe AddHeadPipelineForEachMergeRequest, :delete do let(:migration) { described_class.new } - let!(:project) { create(:project) } + let!(:project) { create(:project) } # rubocop:disable RSpec/FactoriesInMigrationSpecs let!(:other_project) { fork_project(project) } - let!(:pipeline_1) { create(:ci_pipeline, project: project, ref: "branch_1") } - let!(:pipeline_2) { create(:ci_pipeline, project: other_project, ref: "branch_1") } - let!(:pipeline_3) { create(:ci_pipeline, project: other_project, ref: "branch_1") } - let!(:pipeline_4) { create(:ci_pipeline, project: project, ref: "branch_2") } + 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!(:mr_1) { create(:merge_request, source_project: project, target_project: project, source_branch: "branch_1", target_branch: "target_1") } - let!(:mr_2) { create(:merge_request, source_project: other_project, target_project: project, source_branch: "branch_1", target_branch: "target_2") } - let!(:mr_3) { create(:merge_request, source_project: project, target_project: project, source_branch: "branch_2", target_branch: "master") } - let!(:mr_4) { create(:merge_request, source_project: project, target_project: project, source_branch: "branch_3", target_branch: "master") } + 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 context "#up" do context "when source_project and source_branch of pipeline are the same of merge request" do diff --git a/spec/migrations/assure_commits_count_for_merge_request_diff_spec.rb b/spec/migrations/assure_commits_count_for_merge_request_diff_spec.rb new file mode 100644 index 00000000000..b8c3a3eda4e --- /dev/null +++ b/spec/migrations/assure_commits_count_for_merge_request_diff_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20180425131009_assure_commits_count_for_merge_request_diff.rb') + +describe AssureCommitsCountForMergeRequestDiff, :migration, :sidekiq, :redis do + let(:migration) { spy('migration') } + + before do + allow(Gitlab::BackgroundMigration::AddMergeRequestDiffCommitsCount) + .to receive(:new).and_return(migration) + end + + context 'when there are still unmigrated commit_counts afterwards' do + let(:namespaces) { table('namespaces') } + let(:projects) { table('projects') } + let(:merge_requests) { table('merge_requests') } + let(:diffs) { table('merge_request_diffs') } + + before do + namespace = namespaces.create(name: 'foo', path: 'foo') + project = projects.create!(namespace_id: namespace.id) + merge_request = merge_requests.create!(source_branch: 'x', target_branch: 'y', target_project_id: project.id) + diffs.create!(commits_count: nil, merge_request_id: merge_request.id) + diffs.create!(commits_count: nil, merge_request_id: merge_request.id) + end + + it 'migrates commit_counts sequentially in batches' do + migrate! + + expect(migration).to have_received(:perform).once + end + end +end diff --git a/spec/migrations/calculate_conv_dev_index_percentages_spec.rb b/spec/migrations/calculate_conv_dev_index_percentages_spec.rb index f3a46025376..19f06810e54 100644 --- a/spec/migrations/calculate_conv_dev_index_percentages_spec.rb +++ b/spec/migrations/calculate_conv_dev_index_percentages_spec.rb @@ -6,7 +6,7 @@ require Rails.root.join('db', 'post_migrate', '20170803090603_calculate_conv_dev describe CalculateConvDevIndexPercentages, :delete do let(:migration) { described_class.new } let!(:conv_dev_index) do - create(:conversational_development_index_metric, + create(:conversational_development_index_metric, # rubocop:disable RSpec/FactoriesInMigrationSpecs leader_notes: 0, instance_milestones: 0, percentage_issues: 0, diff --git a/spec/migrations/cleanup_namespaceless_pending_delete_projects_spec.rb b/spec/migrations/cleanup_namespaceless_pending_delete_projects_spec.rb index 033d0e7584d..b5980cb9ddb 100644 --- a/spec/migrations/cleanup_namespaceless_pending_delete_projects_spec.rb +++ b/spec/migrations/cleanup_namespaceless_pending_delete_projects_spec.rb @@ -10,9 +10,9 @@ describe CleanupNamespacelessPendingDeleteProjects, :migration, schema: 20180222 describe '#up' do it 'only cleans up pending delete projects' do - create(:project) - create(:project, pending_delete: true) - project = build(:project, pending_delete: true, namespace_id: nil) + create(:project) # rubocop:disable RSpec/FactoriesInMigrationSpecs + create(:project, pending_delete: true) # rubocop:disable RSpec/FactoriesInMigrationSpecs + project = build(:project, pending_delete: true, namespace_id: nil) # rubocop:disable RSpec/FactoriesInMigrationSpecs project.save(validate: false) expect(NamespacelessProjectDestroyWorker).to receive(:bulk_perform_async).with([[project.id]]) @@ -21,8 +21,8 @@ describe CleanupNamespacelessPendingDeleteProjects, :migration, schema: 20180222 end it 'does nothing when no pending delete projects without namespace found' do - create(:project) - create(:project, pending_delete: true) + create(:project) # rubocop:disable RSpec/FactoriesInMigrationSpecs + create(:project, pending_delete: true) # rubocop:disable RSpec/FactoriesInMigrationSpecs expect(NamespacelessProjectDestroyWorker).not_to receive(:bulk_perform_async) 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 7879105a334..8f40ac3e38b 100644 --- a/spec/migrations/cleanup_nonexisting_namespace_pending_delete_projects_spec.rb +++ b/spec/migrations/cleanup_nonexisting_namespace_pending_delete_projects_spec.rb @@ -9,11 +9,11 @@ describe CleanupNonexistingNamespacePendingDeleteProjects do end describe '#up' do - set(:some_project) { create(:project) } + set(:some_project) { create(:project) } # rubocop:disable RSpec/FactoriesInMigrationSpecs it 'only cleans up when namespace does not exist' do - create(:project, pending_delete: true) - project = build(:project, pending_delete: true, namespace: nil, namespace_id: Namespace.maximum(:id).to_i.succ) + 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) expect(NamespacelessProjectDestroyWorker).to receive(:bulk_perform_async).with([[project.id]]) @@ -22,7 +22,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)) + create(:project, pending_delete: true, namespace: create(:namespace)) # rubocop:disable RSpec/FactoriesInMigrationSpecs expect(NamespacelessProjectDestroyWorker).not_to receive(:bulk_perform_async) diff --git a/spec/migrations/create_missing_namespace_for_internal_users_spec.rb b/spec/migrations/create_missing_namespace_for_internal_users_spec.rb new file mode 100644 index 00000000000..ac3a4b1f68f --- /dev/null +++ b/spec/migrations/create_missing_namespace_for_internal_users_spec.rb @@ -0,0 +1,42 @@ +require 'spec_helper' +require Rails.root.join('db', 'migrate', '20180413022611_create_missing_namespace_for_internal_users.rb') + +describe CreateMissingNamespaceForInternalUsers, :migration do + let(:users) { table(:users) } + let(:namespaces) { table(:namespaces) } + let(:routes) { table(:routes) } + + internal_user_types = [:ghost] + internal_user_types << :support_bot if ActiveRecord::Base.connection.column_exists?(:users, :support_bot) + + internal_user_types.each do |attr| + context "for #{attr} user" do + let(:internal_user) do + users.create!(email: 'test@example.com', projects_limit: 100, username: 'test', attr => true) + end + + it 'creates the missing namespace' do + expect(namespaces.find_by(owner_id: internal_user.id)).to be_nil + + migrate! + + namespace = Namespace.find_by(type: nil, owner_id: internal_user.id) + route = namespace.route + + expect(namespace.path).to eq(route.path) + expect(namespace.name).to eq(route.name) + end + + it 'sets notification email' do + users.update(internal_user.id, notification_email: nil) + + expect(users.find(internal_user.id).notification_email).to be_nil + + migrate! + + user = users.find(internal_user.id) + expect(user.notification_email).to eq(user.email) + end + end + end +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 d2eef81f396..dd2b08099f2 100644 --- a/spec/migrations/issues_moved_to_id_foreign_key_spec.rb +++ b/spec/migrations/issues_moved_to_id_foreign_key_spec.rb @@ -5,9 +5,9 @@ require Rails.root.join('db', 'migrate', '20171106151218_issues_moved_to_id_fore # 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) } - let!(:issue_second) { create(:issue, moved_to_id: issue_third.id) } - let!(:issue_third) { create(:issue) } + 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 subject { described_class.new } diff --git a/spec/migrations/migrate_gcp_clusters_to_new_clusters_architectures_spec.rb b/spec/migrations/migrate_gcp_clusters_to_new_clusters_architectures_spec.rb index c81ec887ded..df009cec25c 100644 --- a/spec/migrations/migrate_gcp_clusters_to_new_clusters_architectures_spec.rb +++ b/spec/migrations/migrate_gcp_clusters_to_new_clusters_architectures_spec.rb @@ -4,8 +4,24 @@ require Rails.root.join('db', 'post_migrate', '20171013104327_migrate_gcp_cluste describe MigrateGcpClustersToNewClustersArchitectures, :migration do let(:projects) { table(:projects) } let(:project) { projects.create } - let(:user) { create(:user) } - let(:service) { create(:kubernetes_service, project_id: project.id) } + let(:users) { table(:users) } + let(:user) { users.create! } + let(:service) { GcpMigrationSpec::KubernetesService.create!(project_id: project.id) } + + module GcpMigrationSpec + class KubernetesService < ActiveRecord::Base + self.table_name = 'services' + + serialize :properties, JSON # rubocop:disable Cop/ActiveRecordSerialize + + default_value_for :active, true + default_value_for :type, 'KubernetesService' + default_value_for :properties, { + api_url: 'https://kubernetes.example.com', + token: 'a' * 40 + } + end + end context 'when cluster is being created' do let(:project_id) { project.id } diff --git a/spec/migrations/migrate_old_artifacts_spec.rb b/spec/migrations/migrate_old_artifacts_spec.rb index 638b2853374..4187ab149a5 100644 --- a/spec/migrations/migrate_old_artifacts_spec.rb +++ b/spec/migrations/migrate_old_artifacts_spec.rb @@ -16,18 +16,18 @@ describe MigrateOldArtifacts do end context 'with migratable data' do - set(:project1) { create(:project, ci_id: 2) } - set(:project2) { create(:project, ci_id: 3) } - set(:project3) { create(:project) } - - set(:pipeline1) { create(:ci_empty_pipeline, project: project1) } - set(:pipeline2) { create(:ci_empty_pipeline, project: project2) } - set(:pipeline3) { create(:ci_empty_pipeline, project: project3) } - - let!(:build_with_legacy_artifacts) { create(:ci_build, pipeline: pipeline1) } - let!(:build_without_artifacts) { create(:ci_build, pipeline: pipeline1) } - let!(:build2) { create(:ci_build, pipeline: pipeline2) } - let!(:build3) { create(:ci_build, pipeline: pipeline3) } + 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 before do setup_builds(build2, build3) diff --git a/spec/migrations/migrate_process_commit_worker_jobs_spec.rb b/spec/migrations/migrate_process_commit_worker_jobs_spec.rb index 657113812bd..4ee1d255fbd 100644 --- a/spec/migrations/migrate_process_commit_worker_jobs_spec.rb +++ b/spec/migrations/migrate_process_commit_worker_jobs_spec.rb @@ -4,8 +4,8 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20161124141322_migrate_process_commit_worker_jobs.rb') describe MigrateProcessCommitWorkerJobs do - let(:project) { create(:project, :legacy_storage, :repository) } - let(:user) { create(:user) } + let(:project) { create(:project, :legacy_storage, :repository) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let(:user) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs let(:commit) { project.commit.raw.rugged_commit } describe 'Project' do 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 a17c9c72bde..99173708190 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 @@ -5,8 +5,8 @@ require Rails.root.join('db', 'post_migrate', '20170324160416_migrate_user_activ describe MigrateUserActivitiesToUsersLastActivityOn, :clean_gitlab_redis_shared_state, :delete do let(:migration) { described_class.new } - let!(:user_active_1) { create(:user) } - let!(:user_active_2) { create(:user) } + let!(:user_active_1) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:user_active_2) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs 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 31d16e17d7b..80468b9d01e 100644 --- a/spec/migrations/migrate_user_project_view_spec.rb +++ b/spec/migrations/migrate_user_project_view_spec.rb @@ -5,7 +5,7 @@ require Rails.root.join('db', 'post_migrate', '20170406142253_migrate_user_proje describe MigrateUserProjectView, :delete do let(:migration) { described_class.new } - let!(:user) { create(:user, project_view: 'readme') } + let!(:user) { create(:user, project_view: 'readme') } # rubocop:disable RSpec/FactoriesInMigrationSpecs describe '#up' do it 'updates project view setting with new value' do diff --git a/spec/migrations/move_personal_snippets_files_spec.rb b/spec/migrations/move_personal_snippets_files_spec.rb index 1a319eccc0d..1f39ad98fb8 100644 --- a/spec/migrations/move_personal_snippets_files_spec.rb +++ b/spec/migrations/move_personal_snippets_files_spec.rb @@ -16,14 +16,14 @@ describe MovePersonalSnippetsFiles do describe "#up" do let(:snippet) do - snippet = create(:personal_snippet) + snippet = create(:personal_snippet) # rubocop:disable RSpec/FactoriesInMigrationSpecs 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) + snippet = create(:snippet) # rubocop:disable RSpec/FactoriesInMigrationSpecs create_upload('picture.jpg', snippet, create_file: false) snippet.update(description: markdown_linking_file('picture.jpg', snippet)) snippet @@ -62,7 +62,7 @@ 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}") + note = create(:note_on_personal_snippet, noteable: snippet, note: "with #{markdown}") # rubocop:disable RSpec/FactoriesInMigrationSpecs migration.up @@ -73,14 +73,14 @@ describe MovePersonalSnippetsFiles do describe "#down" do let(:snippet) do - snippet = create(:personal_snippet) + snippet = create(:personal_snippet) # rubocop:disable RSpec/FactoriesInMigrationSpecs 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) + snippet = create(:personal_snippet) # rubocop:disable RSpec/FactoriesInMigrationSpecs 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 +119,7 @@ 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}") + note = create(:note_on_personal_snippet, noteable: snippet, note: "with #{markdown}") # rubocop:disable RSpec/FactoriesInMigrationSpecs migration.down @@ -135,7 +135,7 @@ describe MovePersonalSnippetsFiles do secret = '123456789' filename = 'hello.jpg' - snippet = create(:personal_snippet) + snippet = create(:personal_snippet) # rubocop:disable RSpec/FactoriesInMigrationSpecs path_before = "/uploads/personal_snippet/#{snippet.id}/#{secret}/#{filename}" path_after = "/uploads/system/personal_snippet/#{snippet.id}/#{secret}/#{filename}" @@ -161,7 +161,7 @@ describe MovePersonalSnippetsFiles do FileUtils.touch(absolute_path) end - create(:upload, model: snippet, path: "#{secret}/#{filename}", uploader: PersonalFileUploader) + create(:upload, model: snippet, path: "#{secret}/#{filename}", uploader: PersonalFileUploader) # rubocop:disable RSpec/FactoriesInMigrationSpecs end def markdown_linking_file(filename, snippet, in_new_path: false) diff --git a/spec/migrations/remove_dot_git_from_usernames_spec.rb b/spec/migrations/remove_dot_git_from_usernames_spec.rb index 3a88a66a476..f11880a83e9 100644 --- a/spec/migrations/remove_dot_git_from_usernames_spec.rb +++ b/spec/migrations/remove_dot_git_from_usernames_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20161226122833_remove_dot_git_from_usernames.rb') describe RemoveDotGitFromUsernames do - let(:user) { create(:user) } + let(:user) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs let(:migration) { described_class.new } describe '#up' do @@ -23,7 +23,7 @@ describe RemoveDotGitFromUsernames do context 'when new path exists already' do describe '#up' do - let(:user2) { create(:user) } + let(:user2) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs before do update_namespace(user, 'test.git') diff --git a/spec/migrations/remove_duplicate_mr_events_spec.rb b/spec/migrations/remove_duplicate_mr_events_spec.rb index e51872239ad..2509ac6afd6 100644 --- a/spec/migrations/remove_duplicate_mr_events_spec.rb +++ b/spec/migrations/remove_duplicate_mr_events_spec.rb @@ -5,17 +5,17 @@ describe RemoveDuplicateMrEvents, :delete do let(:migration) { described_class.new } describe '#up' do - let(:user) { create(:user) } - let(:merge_requests) { create_list(:merge_request, 2) } - let(:issue) { create(:issue) } + let(:user) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let(:merge_requests) { create_list(:merge_request, 2) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let(:issue) { create(:issue) } # rubocop:disable RSpec/FactoriesInMigrationSpecs let!(:events) do [ - create(:event, :created, author: user, target: merge_requests.first), - create(:event, :created, author: user, target: merge_requests.first), - create(:event, :updated, author: user, target: merge_requests.first), - create(:event, :created, author: user, target: merge_requests.second), - create(:event, :created, author: user, target: issue), - create(:event, :created, author: user, target: issue) + create(:event, :created, author: user, target: merge_requests.first), # rubocop:disable RSpec/FactoriesInMigrationSpecs + create(:event, :created, author: user, target: merge_requests.first), # rubocop:disable RSpec/FactoriesInMigrationSpecs + create(:event, :updated, author: user, target: merge_requests.first), # rubocop:disable RSpec/FactoriesInMigrationSpecs + create(:event, :created, author: user, target: merge_requests.second), # rubocop:disable RSpec/FactoriesInMigrationSpecs + create(:event, :created, author: user, target: issue), # rubocop:disable RSpec/FactoriesInMigrationSpecs + create(:event, :created, author: user, target: issue) # rubocop:disable RSpec/FactoriesInMigrationSpecs ] end diff --git a/spec/migrations/remove_project_labels_group_id_spec.rb b/spec/migrations/remove_project_labels_group_id_spec.rb index d80d61af20b..01b09e71d83 100644 --- a/spec/migrations/remove_project_labels_group_id_spec.rb +++ b/spec/migrations/remove_project_labels_group_id_spec.rb @@ -5,9 +5,9 @@ require Rails.root.join('db', 'post_migrate', '20180202111106_remove_project_lab describe RemoveProjectLabelsGroupId, :delete do let(:migration) { described_class.new } - let(:group) { create(:group) } - let!(:project_label) { create(:label, group_id: group.id) } - let!(:group_label) { create(:group_label) } + let(:group) { create(:group) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:project_label) { create(:label, group_id: group.id) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:group_label) { create(:group_label) } # rubocop:disable RSpec/FactoriesInMigrationSpecs describe '#up' do it 'updates the project labels group ID' do diff --git a/spec/migrations/remove_soft_removed_objects_spec.rb b/spec/migrations/remove_soft_removed_objects_spec.rb index ec089f9106d..fb70c284f5e 100644 --- a/spec/migrations/remove_soft_removed_objects_spec.rb +++ b/spec/migrations/remove_soft_removed_objects_spec.rb @@ -8,7 +8,7 @@ describe RemoveSoftRemovedObjects, :migration do create_with_deleted_at(:issue) end - regular_issue = create(:issue) + regular_issue = create(:issue) # rubocop:disable RSpec/FactoriesInMigrationSpecs run_migration @@ -28,7 +28,7 @@ describe RemoveSoftRemovedObjects, :migration do it 'removes routes of soft removed personal namespaces' do namespace = create_with_deleted_at(:namespace) - group = create(:group) + group = create(:group) # rubocop:disable RSpec/FactoriesInMigrationSpecs expect(Route.where(source: namespace).exists?).to eq(true) expect(Route.where(source: group).exists?).to eq(true) @@ -41,7 +41,7 @@ describe RemoveSoftRemovedObjects, :migration do it 'schedules the removal of soft removed groups' do group = create_with_deleted_at(:group) - admin = create(:user, admin: true) + admin = create(:user, admin: true) # rubocop:disable RSpec/FactoriesInMigrationSpecs expect_any_instance_of(GroupDestroyWorker) .to receive(:perform) @@ -67,7 +67,7 @@ describe RemoveSoftRemovedObjects, :migration do end def create_with_deleted_at(*args) - row = create(*args) + row = create(*args) # rubocop:disable RSpec/FactoriesInMigrationSpecs # We set "deleted_at" this way so we don't run into any column cache issues. row.class.where(id: row.id).update_all(deleted_at: 1.year.ago) diff --git a/spec/migrations/rename_more_reserved_project_names_spec.rb b/spec/migrations/rename_more_reserved_project_names_spec.rb index 75310075cc5..034e8a6a4e5 100644 --- a/spec/migrations/rename_more_reserved_project_names_spec.rb +++ b/spec/migrations/rename_more_reserved_project_names_spec.rb @@ -8,7 +8,7 @@ require Rails.root.join('db', 'post_migrate', '20170313133418_rename_more_reserv # around this we use the DELETE cleaning strategy. describe RenameMoreReservedProjectNames, :delete do let(:migration) { described_class.new } - let!(:project) { create(:project) } + let!(:project) { create(:project) } # rubocop:disable RSpec/FactoriesInMigrationSpecs before do project.path = 'artifacts' diff --git a/spec/migrations/rename_reserved_project_names_spec.rb b/spec/migrations/rename_reserved_project_names_spec.rb index 34336d705b1..592ac2b5fb9 100644 --- a/spec/migrations/rename_reserved_project_names_spec.rb +++ b/spec/migrations/rename_reserved_project_names_spec.rb @@ -12,7 +12,7 @@ require Rails.root.join('db', 'post_migrate', '20161221153951_rename_reserved_pr # Ideally, the test should not use factories and rely on the `table` helper instead. describe RenameReservedProjectNames, :migration, schema: :latest do let(:migration) { described_class.new } - let!(:project) { create(:project) } + let!(:project) { create(:project) } # rubocop:disable RSpec/FactoriesInMigrationSpecs before do project.path = 'projects' diff --git a/spec/migrations/rename_users_with_renamed_namespace_spec.rb b/spec/migrations/rename_users_with_renamed_namespace_spec.rb index cbc0ebeb44d..b8a4dc2b2c0 100644 --- a/spec/migrations/rename_users_with_renamed_namespace_spec.rb +++ b/spec/migrations/rename_users_with_renamed_namespace_spec.rb @@ -3,13 +3,13 @@ require Rails.root.join('db', 'post_migrate', '20170518200835_rename_users_with_ describe RenameUsersWithRenamedNamespace, :delete do it 'renames a user that had their namespace renamed to the namespace path' do - other_user = create(:user, username: 'kodingu') - other_user1 = create(:user, username: 'api0') + other_user = create(:user, username: 'kodingu') # rubocop:disable RSpec/FactoriesInMigrationSpecs + other_user1 = create(:user, username: 'api0') # rubocop:disable RSpec/FactoriesInMigrationSpecs - user = create(:user, username: "Users0") - user.update_attribute(:username, 'Users') - user1 = create(:user, username: "import0") - user1.update_attribute(:username, 'import') + user = create(:user, username: "Users0") # rubocop:disable RSpec/FactoriesInMigrationSpecs + user.update_column(:username, 'Users') + user1 = create(:user, username: "import0") # rubocop:disable RSpec/FactoriesInMigrationSpecs + user1.update_column(:username, 'import') described_class.new.up diff --git a/spec/migrations/schedule_build_stage_migration_spec.rb b/spec/migrations/reschedule_builds_stages_migration_spec.rb index e2ca35447fb..3bfd9dd9f6b 100644 --- a/spec/migrations/schedule_build_stage_migration_spec.rb +++ b/spec/migrations/reschedule_builds_stages_migration_spec.rb @@ -1,7 +1,8 @@ require 'spec_helper' -require Rails.root.join('db', 'post_migrate', '20180212101928_schedule_build_stage_migration') +require Rails.root.join('db', 'post_migrate', '20180405101928_reschedule_builds_stages_migration') -describe ScheduleBuildStageMigration, :sidekiq, :migration do +describe RescheduleBuildsStagesMigration, :sidekiq, :migration do + let(:namespaces) { table(:namespaces) } let(:projects) { table(:projects) } let(:pipelines) { table(:ci_pipelines) } let(:stages) { table(:ci_stages) } @@ -10,7 +11,8 @@ describe ScheduleBuildStageMigration, :sidekiq, :migration do before do stub_const("#{described_class}::BATCH_SIZE", 1) - projects.create!(id: 123, name: 'gitlab', path: 'gitlab-ce') + namespaces.create(id: 12, name: 'gitlab-org', path: 'gitlab-org') + projects.create!(id: 123, namespace_id: 12, name: 'gitlab', path: 'gitlab') pipelines.create!(id: 1, project_id: 123, ref: 'master', sha: 'adf43c3a') stages.create!(id: 1, project_id: 123, pipeline_id: 1, name: 'test') diff --git a/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb b/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb index 65ec07da31c..ed306fb3d62 100644 --- a/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb +++ b/spec/migrations/schedule_create_gpg_key_subkeys_from_gpg_keys_spec.rb @@ -3,8 +3,8 @@ require Rails.root.join('db', 'post_migrate', '20171005130944_schedule_create_gp describe ScheduleCreateGpgKeySubkeysFromGpgKeys, :migration, :sidekiq do before do - create(:gpg_key, id: 1, key: GpgHelpers::User1.public_key) - create(:gpg_key, id: 2, key: GpgHelpers::User3.public_key) + create(:gpg_key, id: 1, key: GpgHelpers::User1.public_key) # rubocop:disable RSpec/FactoriesInMigrationSpecs + create(:gpg_key, id: 2, key: GpgHelpers::User3.public_key) # rubocop:disable RSpec/FactoriesInMigrationSpecs # Delete all subkeys so they can be recreated GpgKeySubkey.destroy_all end diff --git a/spec/migrations/schedule_populate_merge_request_metrics_with_events_data_spec.rb b/spec/migrations/schedule_populate_merge_request_metrics_with_events_data_spec.rb index 7494624066a..578440cba20 100644 --- a/spec/migrations/schedule_populate_merge_request_metrics_with_events_data_spec.rb +++ b/spec/migrations/schedule_populate_merge_request_metrics_with_events_data_spec.rb @@ -8,7 +8,7 @@ describe SchedulePopulateMergeRequestMetricsWithEventsData, :migration, :sidekiq .to receive(:commits_count=).and_return(nil) end - let!(:mrs) { create_list(:merge_request, 3) } + let!(:mrs) { create_list(:merge_request, 3) } # rubocop:disable RSpec/FactoriesInMigrationSpecs it 'correctly schedules background migrations' do stub_const("#{described_class.name}::BATCH_SIZE", 2) diff --git a/spec/migrations/schedule_set_confidential_note_events_on_webhooks_spec.rb b/spec/migrations/schedule_set_confidential_note_events_on_webhooks_spec.rb new file mode 100644 index 00000000000..027f4a91c90 --- /dev/null +++ b/spec/migrations/schedule_set_confidential_note_events_on_webhooks_spec.rb @@ -0,0 +1,44 @@ +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20180104131052_schedule_set_confidential_note_events_on_webhooks.rb') + +describe ScheduleSetConfidentialNoteEventsOnWebhooks, :migration, :sidekiq do + let(:web_hooks_table) { table(:web_hooks) } + let(:migration_class) { Gitlab::BackgroundMigration::SetConfidentialNoteEventsOnWebhooks } + let(:migration_name) { migration_class.to_s.demodulize } + + let!(:web_hook_1) { web_hooks_table.create!(confidential_note_events: nil, note_events: true) } + let!(:web_hook_2) { web_hooks_table.create!(confidential_note_events: nil, note_events: true) } + let!(:web_hook_migrated) { web_hooks_table.create!(confidential_note_events: true, note_events: true) } + let!(:web_hook_skip) { web_hooks_table.create!(confidential_note_events: nil, note_events: false) } + let!(:web_hook_new) { web_hooks_table.create!(confidential_note_events: false, note_events: true) } + let!(:web_hook_4) { web_hooks_table.create!(confidential_note_events: nil, note_events: true) } + + before do + stub_const("#{described_class}::BATCH_SIZE", 1) + end + + it 'schedules background migrations at correct time' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migrate! + + expect(migration_name).to be_scheduled_delayed_migration(5.minutes, web_hook_1.id, web_hook_1.id) + expect(migration_name).to be_scheduled_delayed_migration(10.minutes, web_hook_2.id, web_hook_2.id) + expect(migration_name).to be_scheduled_delayed_migration(15.minutes, web_hook_4.id, web_hook_4.id) + expect(BackgroundMigrationWorker.jobs.size).to eq 3 + end + end + end + + it 'correctly processes web hooks' do + Sidekiq::Testing.inline! do + expect(web_hooks_table.where(confidential_note_events: nil).count).to eq 4 + expect(web_hooks_table.where(confidential_note_events: true).count).to eq 1 + + migrate! + + expect(web_hooks_table.where(confidential_note_events: nil).count).to eq 1 + expect(web_hooks_table.where(confidential_note_events: true).count).to eq 4 + end + end +end diff --git a/spec/migrations/schedule_stages_index_migration_spec.rb b/spec/migrations/schedule_stages_index_migration_spec.rb new file mode 100644 index 00000000000..710264da375 --- /dev/null +++ b/spec/migrations/schedule_stages_index_migration_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20180420080616_schedule_stages_index_migration') + +describe ScheduleStagesIndexMigration, :sidekiq, :migration do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:pipelines) { table(:ci_pipelines) } + let(:stages) { table(:ci_stages) } + + before do + stub_const("#{described_class}::BATCH_SIZE", 1) + + namespaces.create(id: 12, name: 'gitlab-org', path: 'gitlab-org') + projects.create!(id: 123, namespace_id: 12, name: 'gitlab', path: 'gitlab') + pipelines.create!(id: 1, project_id: 123, ref: 'master', sha: 'adf43c3a') + stages.create!(id: 121, project_id: 123, pipeline_id: 1, name: 'build') + stages.create!(id: 122, project_id: 123, pipeline_id: 1, name: 'test') + stages.create!(id: 123, project_id: 123, pipeline_id: 1, name: 'deploy') + end + + it 'schedules delayed background migrations in batches' do + Sidekiq::Testing.fake! do + Timecop.freeze do + expect(stages.all).to all(have_attributes(position: be_nil)) + + migrate! + + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(5.minutes, 121, 121) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(10.minutes, 122, 122) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(15.minutes, 123, 123) + expect(BackgroundMigrationWorker.jobs.size).to eq 3 + end + end + end +end diff --git a/spec/migrations/turn_nested_groups_into_regular_groups_for_mysql_spec.rb b/spec/migrations/turn_nested_groups_into_regular_groups_for_mysql_spec.rb index 528dc54781d..560409f08de 100644 --- a/spec/migrations/turn_nested_groups_into_regular_groups_for_mysql_spec.rb +++ b/spec/migrations/turn_nested_groups_into_regular_groups_for_mysql_spec.rb @@ -2,10 +2,10 @@ require 'spec_helper' require Rails.root.join('db', 'migrate', '20170503140202_turn_nested_groups_into_regular_groups_for_mysql.rb') describe TurnNestedGroupsIntoRegularGroupsForMysql do - let!(:parent_group) { create(:group) } - let!(:child_group) { create(:group, parent: parent_group) } - let!(:project) { create(:project, :legacy_storage, :empty_repo, namespace: child_group) } - let!(:member) { create(:user) } + let!(:parent_group) { create(:group) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:child_group) { create(:group, parent: parent_group) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:project) { create(:project, :legacy_storage, :empty_repo, namespace: child_group) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:member) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs let(:migration) { described_class.new } before do diff --git a/spec/migrations/update_retried_for_ci_build_spec.rb b/spec/migrations/update_retried_for_ci_build_spec.rb index ccb77766b84..637dcbb8e01 100644 --- a/spec/migrations/update_retried_for_ci_build_spec.rb +++ b/spec/migrations/update_retried_for_ci_build_spec.rb @@ -2,9 +2,9 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20170503004427_update_retried_for_ci_build.rb') describe UpdateRetriedForCiBuild, :delete do - let(:pipeline) { create(:ci_pipeline) } - let!(:build_old) { create(:ci_build, pipeline: pipeline, name: 'test') } - let!(:build_new) { create(:ci_build, pipeline: pipeline, name: 'test') } + let(:pipeline) { create(:ci_pipeline) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:build_old) { create(:ci_build, pipeline: pipeline, name: 'test') } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:build_new) { create(:ci_build, pipeline: pipeline, name: 'test') } # rubocop:disable RSpec/FactoriesInMigrationSpecs before do described_class.new.up |