diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-28 12:09:01 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-28 12:09:01 +0300 |
commit | 67cdfd2683b89bce260600fa8925eefdcdf9e3e5 (patch) | |
tree | 5d01075e0ef7bc62bb27459f75d79ef138aec660 /spec | |
parent | ca2a7ed5bd43483f10fd74f46f31e32614889738 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
7 files changed, 263 insertions, 15 deletions
diff --git a/spec/frontend/labels_select_spec.js b/spec/frontend/labels_select_spec.js index d54e0eab845..59116b64298 100644 --- a/spec/frontend/labels_select_spec.js +++ b/spec/frontend/labels_select_spec.js @@ -41,29 +41,29 @@ describe('LabelsSelect', () => { }); it('generated label item template has correct label URL', () => { - expect($labelEl.attr('href')).toBe('/foo/bar?label_name[]=Foo%20Label'); + expect($labelEl.find('a').attr('href')).toBe('/foo/bar?label_name[]=Foo%20Label'); }); it('generated label item template has correct label title', () => { - expect($labelEl.find('span.label').text()).toBe(label.title); + expect($labelEl.find('span.gl-label-text').text()).toBe(label.title); }); it('generated label item template has label description as title attribute', () => { - expect($labelEl.find('span.label').attr('title')).toBe(label.description); + expect($labelEl.find('a').attr('title')).toBe(label.description); }); it('generated label item template has correct label styles', () => { - expect($labelEl.find('span.label').attr('style')).toBe( + expect($labelEl.find('span.gl-label-text').attr('style')).toBe( `background-color: ${label.color}; color: ${label.text_color};`, ); }); - it('generated label item has a badge class', () => { - expect($labelEl.find('span').hasClass('badge')).toEqual(true); + it('generated label item has a gl-label-text class', () => { + expect($labelEl.find('span').hasClass('gl-label-text')).toEqual(true); }); - it('generated label item template does not have scoped-label class', () => { - expect($labelEl.find('.scoped-label')).toHaveLength(0); + it('generated label item template does not have gl-label-icon class', () => { + expect($labelEl.find('.gl-label-icon')).toHaveLength(0); }); }); @@ -87,29 +87,31 @@ describe('LabelsSelect', () => { }); it('generated label item template has correct label title', () => { - expect($labelEl.find('span.label').text()).toBe(label.title); + const scopedTitle = label.title.split('::'); + expect($labelEl.find('span.gl-label-text').text()).toContain(scopedTitle[0]); + expect($labelEl.find('span.gl-label-text').text()).toContain(scopedTitle[1]); }); it('generated label item template has html flag as true', () => { - expect($labelEl.find('span.label').attr('data-html')).toBe('true'); + expect($labelEl.find('a').attr('data-html')).toBe('true'); }); it('generated label item template has question icon', () => { expect($labelEl.find('i.fa-question-circle')).toHaveLength(1); }); - it('generated label item template has scoped-label class', () => { - expect($labelEl.find('.scoped-label')).toHaveLength(1); + it('generated label item template has gl-label-icon class', () => { + expect($labelEl.find('.gl-label-icon')).toHaveLength(1); }); it('generated label item template has correct label styles', () => { - expect($labelEl.find('span.label').attr('style')).toBe( + expect($labelEl.find('span.gl-label-text').attr('style')).toBe( `background-color: ${label.color}; color: ${label.text_color};`, ); }); it('generated label item has a badge class', () => { - expect($labelEl.find('span').hasClass('badge')).toEqual(true); + expect($labelEl.find('span').hasClass('gl-label-text')).toEqual(true); }); }); }); 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..9c085b3cef8 --- /dev/null +++ b/spec/lib/gitlab/background_migration/user_mentions/create_resource_user_mention_spec.rb @@ -0,0 +1,77 @@ +# frozen_string_literal: true + +require 'spec_helper' +require './db/post_migrate/20200127131953_migrate_snippet_mentions_to_db' +require './db/post_migrate/20200127151953_migrate_snippet_notes_mentions_to_db' + +describe Gitlab::BackgroundMigration::UserMentions::CreateResourceUserMention, schema: 20200127151953 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 snippet mentions' do + let(:snippets) { table(:snippets) } + let(:snippet_user_mentions) { table(:snippet_user_mentions) } + + let!(:snippet1) { snippets.create!(project_id: project.id, author_id: author.id, title: 'title1', description: description_mentions) } + let!(:snippet2) { snippets.create!(project_id: project.id, author_id: author.id, title: 'title2', description: 'some description') } + let!(:snippet3) { snippets.create!(project_id: project.id, author_id: author.id, title: 'title3', description: 'description with an email@example.com and some other @ char here.') } + + let(:user_mentions) { snippet_user_mentions } + let(:resource) { snippet1 } + + it_behaves_like 'resource mentions migration', MigrateSnippetMentionsToDb, Snippet + + context 'mentions in note' do + let!(:note1) { notes.create!(noteable_id: snippet1.id, noteable_type: 'Snippet', project_id: project.id, author_id: author.id, note: description_mentions) } + let!(:note2) { notes.create!(noteable_id: snippet1.id, noteable_type: 'Snippet', project_id: project.id, author_id: author.id, note: 'sample note') } + let!(:note3) { notes.create!(noteable_id: snippet1.id, noteable_type: 'Snippet', project_id: project.id, author_id: author.id, note: description_mentions, system: true) } + # this not does not have actual mentions + let!(:note4) { notes.create!(noteable_id: snippet1.id, noteable_type: 'Snippet', project_id: project.id, author_id: author.id, note: 'note3 for an email@somesite.com and some other rando @ ref' ) } + # this note points to an innexistent noteable record in snippets table + let!(:note5) { notes.create!(noteable_id: snippets.maximum(:id) + 10, noteable_type: 'Snippet', project_id: project.id, author_id: author.id, note: description_mentions) } + + it_behaves_like 'resource notes mentions migration', MigrateSnippetNotesMentionsToDb, Snippet + end + end + end + + context 'checks no_quote_columns' do + it 'has correct no_quote_columns' do + expect(Gitlab::BackgroundMigration::UserMentions::Models::Snippet.no_quote_columns).to match([:note_id, :snippet_id]) + end + end +end diff --git a/spec/migrations/cleanup_empty_snippet_user_mentions_spec.rb b/spec/migrations/cleanup_empty_snippet_user_mentions_spec.rb new file mode 100644 index 00000000000..d229f0b2b59 --- /dev/null +++ b/spec/migrations/cleanup_empty_snippet_user_mentions_spec.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200127111953_cleanup_empty_snippet_user_mentions') + +describe CleanupEmptySnippetUserMentions, :migration, :sidekiq do + let(:users) { table(:users) } + let(:projects) { table(:projects) } + let(:namespaces) { table(:namespaces) } + let(:snippets) { table(:snippets) } + let(:snippet_user_mentions) { table(:snippet_user_mentions) } + let(:notes) { table(:notes) } + + let(:user) { users.create!(name: 'root', email: 'root@example.com', username: 'root', projects_limit: 0) } + let(:group) { namespaces.create!(name: 'group1', path: 'group1', owner_id: user.id) } + let(:project) { projects.create!(name: 'gitlab1', path: 'gitlab1', namespace_id: group.id, visibility_level: 0) } + let(:snippet) { snippets.create!(title: "title1", title_html: 'title1', description: 'snippet description with @root mention', project_id: project.id, author_id: user.id) } + + let!(:resource1) { notes.create!(note: 'note for @root to check', noteable_id: snippet.id, noteable_type: 'Snippet') } + let!(:resource2) { notes.create!(note: 'note for @root to check', noteable_id: snippet.id, noteable_type: 'Snippet', system: true) } + let!(:resource3) { notes.create!(note: 'note for @root to check', noteable_id: snippet.id, noteable_type: 'Snippet') } + + # non-migrateable resources + # this note is already migrated, as it has a record in the snippet_user_mentions table + let!(:resource4) { notes.create!(note: 'note for @root to check', noteable_id: snippet.id, noteable_type: 'Snippet') } + let!(:user_mention) { snippet_user_mentions.create!(snippet_id: snippet.id, note_id: resource4.id, mentioned_users_ids: [1]) } + # this note points to an innexistent noteable record + let!(:resource5) { notes.create!(note: 'note for @root to check', noteable_id: snippets.maximum(:id) + 10, noteable_type: 'Snippet') } + + # these should get cleanup, by the migration + let!(:blank_snippet_user_mention1) { snippet_user_mentions.create!(snippet_id: snippet.id, note_id: resource1.id)} + let!(:blank_snippet_user_mention2) { snippet_user_mentions.create!(snippet_id: snippet.id, note_id: resource2.id)} + let!(:blank_snippet_user_mention3) { snippet_user_mentions.create!(snippet_id: snippet.id, note_id: resource3.id)} + + it 'cleanups blank user mentions' do + expect(snippet_user_mentions.count).to eq 4 + + migrate! + + expect(snippet_user_mentions.count).to eq 1 + end +end diff --git a/spec/migrations/migrate_snippet_mentions_to_db_spec.rb b/spec/migrations/migrate_snippet_mentions_to_db_spec.rb new file mode 100644 index 00000000000..6644329fc11 --- /dev/null +++ b/spec/migrations/migrate_snippet_mentions_to_db_spec.rb @@ -0,0 +1,28 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200127131953_migrate_snippet_mentions_to_db') + +describe MigrateSnippetMentionsToDb, :migration, :sidekiq do + let(:users) { table(:users) } + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:snippets) { table(:snippets) } + let(:snippet_user_mentions) { table(:snippet_user_mentions) } + + let(:user) { users.create!(name: 'root', email: 'root@example.com', username: 'root', projects_limit: 0) } + let(:group) { namespaces.create!(name: 'group1', path: 'group1', owner_id: user.id) } + let(:project) { projects.create!(name: 'gitlab1', path: 'gitlab1', namespace_id: group.id, visibility_level: 0) } + let!(:resource1) { snippets.create!(title: "title1", title_html: 'title1', description: 'snippet description with @root mention', project_id: project.id, author_id: user.id) } + let!(:resource2) { snippets.create!(title: "title2", title_html: "title2", description: 'snippet description with @group mention', project_id: project.id, author_id: user.id) } + let!(:resource3) { snippets.create!(title: "title3", title_html: "title3", description: 'snippet description with @project mention', project_id: project.id, author_id: user.id) } + + # non-migrateable resources + # this snippet is already migrated, as it has a record in the snippet_user_mentions table + let!(:resource4) { snippets.create!(title: "title4", title_html: "title4", description: 'snippet description with @project mention', project_id: project.id, author_id: user.id) } + let!(:user_mention) { snippet_user_mentions.create!(snippet_id: resource4.id, mentioned_users_ids: [1]) } + # this snippet has no mentions so should be filtered out + let!(:resource5) { snippets.create!(title: "title5", title_html: "title5", description: 'snippet description with no mention', project_id: project.id, author_id: user.id) } + + it_behaves_like 'schedules resource mentions migration', Snippet, false +end diff --git a/spec/migrations/migrate_snippet_notes_mentions_to_db_spec.rb b/spec/migrations/migrate_snippet_notes_mentions_to_db_spec.rb new file mode 100644 index 00000000000..2ebe80e6ae3 --- /dev/null +++ b/spec/migrations/migrate_snippet_notes_mentions_to_db_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200127151953_migrate_snippet_notes_mentions_to_db') + +describe MigrateSnippetNotesMentionsToDb, :migration, :sidekiq do + let(:users) { table(:users) } + let(:projects) { table(:projects) } + let(:namespaces) { table(:namespaces) } + let(:snippets) { table(:snippets) } + let(:snippet_user_mentions) { table(:snippet_user_mentions) } + let(:notes) { table(:notes) } + + let(:user) { users.create!(name: 'root', email: 'root@example.com', username: 'root', projects_limit: 0) } + let(:group) { namespaces.create!(name: 'group1', path: 'group1', owner_id: user.id) } + let(:project) { projects.create!(name: 'gitlab1', path: 'gitlab1', namespace_id: group.id, visibility_level: 0) } + let(:snippet) { snippets.create!(title: "title1", title_html: 'title1', description: 'snippet description with @root mention', project_id: project.id, author_id: user.id) } + + let!(:resource1) { notes.create!(note: 'note for @root to check', noteable_id: snippet.id, noteable_type: 'Snippet') } + let!(:resource2) { notes.create!(note: 'note for @root to check', noteable_id: snippet.id, noteable_type: 'Snippet', system: true) } + let!(:resource3) { notes.create!(note: 'note for @root to check', noteable_id: snippet.id, noteable_type: 'Snippet') } + + # non-migrateable resources + # this note is already migrated, as it has a record in the snippet_user_mentions table + let!(:resource4) { notes.create!(note: 'note for @root to check', noteable_id: snippet.id, noteable_type: 'Snippet') } + let!(:user_mention) { snippet_user_mentions.create!(snippet_id: snippet.id, note_id: resource4.id, mentioned_users_ids: [1]) } + # this note points to an innexistent noteable record + let!(:resource5) { notes.create!(note: 'note for @root to check', noteable_id: snippets.maximum(:id) + 10, noteable_type: 'Snippet') } + + it_behaves_like 'schedules resource mentions migration', Snippet, true +end diff --git a/spec/migrations/schedule_migrate_security_scans_spec.rb b/spec/migrations/schedule_migrate_security_scans_spec.rb new file mode 100644 index 00000000000..ae066e8f91c --- /dev/null +++ b/spec/migrations/schedule_migrate_security_scans_spec.rb @@ -0,0 +1,68 @@ +# frozen_string_literal: true + +require 'spec_helper' +require Rails.root.join('db', 'post_migrate', '20200217225719_schedule_migrate_security_scans.rb') + +# rubocop: disable RSpec/FactoriesInMigrationSpecs +describe ScheduleMigrateSecurityScans, :migration, :sidekiq do + let(:migration) { described_class.new } + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:builds) { table(:ci_builds) } + let(:job_artifacts) { table(:ci_job_artifacts) } + + let(:namespace) { namespaces.create!(name: "foo", path: "bar") } + let(:project) { projects.create!(namespace_id: namespace.id) } + let(:build) { builds.create! } + + before do + stub_const("#{described_class.name}::BATCH_SIZE", 1) + stub_const("#{described_class.name}::INTERVAL", 5.minutes.to_i) + end + + context 'no security job artifacts' do + before do + table(:ci_job_artifacts) + end + + it 'does not schedule migration' do + Sidekiq::Testing.fake! do + migrate! + + expect(BackgroundMigrationWorker.jobs).to be_empty + end + end + end + + context 'has security job artifacts' do + let!(:job_artifact_1) { job_artifacts.create!(project_id: project.id, job_id: build.id, file_type: 5) } + let!(:job_artifact_2) { job_artifacts.create!(project_id: project.id, job_id: build.id, file_type: 8) } + + it 'schedules migration of security scans' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migration.up + + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(5.minutes, job_artifact_1.id, job_artifact_1.id) + expect(described_class::MIGRATION).to be_scheduled_delayed_migration(10.minutes, job_artifact_2.id, job_artifact_2.id) + expect(BackgroundMigrationWorker.jobs.size).to eq(2) + end + end + end + end + + context 'has non-security job artifacts' do + let!(:job_artifact_1) { job_artifacts.create!(project_id: project.id, job_id: build.id, file_type: 4) } + let!(:job_artifact_2) { job_artifacts.create!(project_id: project.id, job_id: build.id, file_type: 9) } + + it 'schedules migration of security scans' do + Sidekiq::Testing.fake! do + Timecop.freeze do + migration.up + + expect(BackgroundMigrationWorker.jobs).to be_empty + end + end + end + end +end diff --git a/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb index 8f5bfdacc3a..f5b889ef720 100644 --- a/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb +++ b/spec/support/shared_examples/lib/gitlab/background_migration/mentions_migration_shared_examples.rb @@ -72,7 +72,7 @@ shared_examples 'schedules resource mentions migration' do |resource_class, is_f it 'schedules background migrations' do Sidekiq::Testing.fake! do Timecop.freeze do - resource_count = is_for_notes ? Note.count : resource_class.count + resource_count = is_for_notes ? Note.where(noteable_type: resource_class.to_s).count : resource_class.count expect(resource_count).to eq 5 migrate! |