diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 15:09:17 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-12 15:09:17 +0300 |
commit | cd52759ee33051b8ad7b88b02ba7954e4fad7018 (patch) | |
tree | f1096c68e457aef7f5201acd16e4a751ff538026 /spec/lib/gitlab/background_migration | |
parent | 18f7828977b74bf6e5153594a098ef90e773b3b7 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/background_migration')
-rw-r--r-- | spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb b/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb new file mode 100644 index 00000000000..42e446c07c1 --- /dev/null +++ b/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +require 'spec_helper' +require './db/post_migrate/20200211155539_migrate_merge_request_mentions_to_db' + +describe Gitlab::BackgroundMigration::UserMentions::CreateResourceUserMention, schema: 20200211155539 do + include MigrationsHelpers + + context 'when migrating data' do + let(:users) { table(:users) } + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:notes) { table(:notes) } + + let(:author) { users.create!(email: 'author@example.com', notification_email: 'author@example.com', name: 'author', username: 'author', projects_limit: 10, state: 'active') } + let(:member) { users.create!(email: 'member@example.com', notification_email: 'member@example.com', name: 'member', username: 'member', projects_limit: 10, state: 'active') } + let(:admin) { users.create!(email: 'administrator@example.com', notification_email: 'administrator@example.com', name: 'administrator', username: 'administrator', admin: 1, projects_limit: 10, state: 'active') } + let(:john_doe) { users.create!(email: 'john_doe@example.com', notification_email: 'john_doe@example.com', name: 'john_doe', username: 'john_doe', projects_limit: 10, state: 'active') } + let(:skipped) { users.create!(email: 'skipped@example.com', notification_email: 'skipped@example.com', name: 'skipped', username: 'skipped', projects_limit: 10, state: 'active') } + + let(:mentioned_users) { [author, member, admin, john_doe, skipped] } + let(:mentioned_users_refs) { mentioned_users.map { |u| "@#{u.username}" }.join(' ') } + + let(:group) { namespaces.create!(name: 'test1', path: 'test1', runners_token: 'my-token1', project_creation_level: 1, visibility_level: 20, type: 'Group') } + let(:inaccessible_group) { namespaces.create!(name: 'test2', path: 'test2', runners_token: 'my-token2', project_creation_level: 1, visibility_level: 0, type: 'Group') } + let(:project) { projects.create!(name: 'gitlab1', path: 'gitlab1', namespace_id: group.id, visibility_level: 0) } + + let(:mentioned_groups) { [group, inaccessible_group] } + let(:group_mentions) { [group, inaccessible_group].map { |gr| "@#{gr.path}" }.join(' ') } + let(:description_mentions) { "description with mentions #{mentioned_users_refs} and #{group_mentions}" } + + before do + # build personal namespaces and routes for users + mentioned_users.each { |u| u.becomes(User).save! } + + # build namespaces and routes for groups + mentioned_groups.each do |gr| + gr.name += '-org' + gr.path += '-org' + gr.becomes(Namespace).save! + end + end + + context 'migrate merge request mentions' do + let(:merge_requests) { table(:merge_requests) } + let(:merge_request_user_mentions) { table(:merge_request_user_mentions) } + + let!(:mr1) do + merge_requests.create!( + title: "title 1", state_id: 1, target_branch: 'feature1', source_branch: 'master', + source_project_id: project.id, target_project_id: project.id, author_id: author.id, + description: description_mentions + ) + end + + let!(:mr2) do + merge_requests.create!( + title: "title 2", state_id: 1, target_branch: 'feature2', source_branch: 'master', + source_project_id: project.id, target_project_id: project.id, author_id: author.id, + description: 'some description' + ) + end + + let!(:mr3) do + merge_requests.create!( + title: "title 3", state_id: 1, target_branch: 'feature3', source_branch: 'master', + source_project_id: project.id, target_project_id: project.id, author_id: author.id, + description: 'description with an email@example.com and some other @ char here.') + end + + let(:user_mentions) { merge_request_user_mentions } + let(:resource) { merge_request } + + it_behaves_like 'resource mentions migration', MigrateMergeRequestMentionsToDb, MergeRequest + end + end + + context 'checks no_quote_columns' do + it 'has correct no_quote_columns' do + expect(Gitlab::BackgroundMigration::UserMentions::Models::MergeRequest.no_quote_columns).to match([:note_id, :merge_request_id]) + end + end +end |