diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-11 12:10:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-01-11 12:10:46 +0300 |
commit | c2dcc63e6db8e9ee3365c45356451d8144eb0c23 (patch) | |
tree | ebca0b4d04f037de3c8a2722990fbcf7e123eb30 /spec | |
parent | 990b7413bc68bab8aea2aac06c45e31264e26b22 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
12 files changed, 179 insertions, 103 deletions
diff --git a/spec/frontend/clusters/components/applications_spec.js b/spec/frontend/clusters/components/applications_spec.js index de3588cff1a..cf89246c1a5 100644 --- a/spec/frontend/clusters/components/applications_spec.js +++ b/spec/frontend/clusters/components/applications_spec.js @@ -16,7 +16,7 @@ describe('Applications', () => { gon.features = gon.features || {}; }); - const createApp = ({ applications, type, props } = {}, isShallow) => { + const createApp = ({ applications, type, propsData } = {}, isShallow) => { const mountMethod = isShallow ? shallowMount : mount; wrapper = mountMethod(Applications, { @@ -24,7 +24,7 @@ describe('Applications', () => { propsData: { type, applications: { ...APPLICATIONS_MOCK_STATE, ...applications }, - ...props, + ...propsData, }, }); }; @@ -544,7 +544,7 @@ describe('Applications', () => { describe('Cilium application', () => { it('shows the correct description', () => { - createApp({ props: { ciliumHelpPath: 'cilium-help-path' } }); + createApp({ propsData: { ciliumHelpPath: 'cilium-help-path' } }); expect(findByTestId('ciliumDescription').element).toMatchSnapshot(); }); }); diff --git a/spec/frontend/ide/components/panes/collapsible_sidebar_spec.js b/spec/frontend/ide/components/panes/collapsible_sidebar_spec.js index 571509ae426..c3da2a46858 100644 --- a/spec/frontend/ide/components/panes/collapsible_sidebar_spec.js +++ b/spec/frontend/ide/components/panes/collapsible_sidebar_spec.js @@ -47,7 +47,7 @@ describe('ide/components/panes/collapsible_sidebar.vue', () => { beforeEach(() => { const FakeComponent = localVue.component(fakeComponentName, { - render: () => {}, + render: () => null, }); fakeView = { diff --git a/spec/frontend/projects/experiment_new_project_creation/components/app_spec.js b/spec/frontend/projects/experiment_new_project_creation/components/app_spec.js index a422dd3c259..9a5f200f5a9 100644 --- a/spec/frontend/projects/experiment_new_project_creation/components/app_spec.js +++ b/spec/frontend/projects/experiment_new_project_creation/components/app_spec.js @@ -53,6 +53,28 @@ describe('Experimental new project creation app', () => { }); }); + describe('display custom new project guideline text', () => { + beforeEach(() => { + window.location.hash = '#blank_project'; + }); + + it('does not render new project guideline if undefined', () => { + createComponent(); + expect(wrapper.find('div#new-project-guideline').exists()).toBe(false); + }); + + it('render new project guideline if defined', () => { + const guidelineSelector = 'div#new-project-guideline'; + + createComponent({ + newProjectGuidelines: '<h4>Internal Guidelines</h4><p>lorem ipsum</p>', + }); + expect(wrapper.find(guidelineSelector).exists()).toBe(true); + expect(wrapper.find(guidelineSelector).html()).toContain('<h4>Internal Guidelines</h4>'); + expect(wrapper.find(guidelineSelector).html()).toContain('<p>lorem ipsum</p>'); + }); + }); + it('renders relevant container when hash changes', () => { createComponent(); expect(wrapper.find(WelcomePage).exists()).toBe(true); diff --git a/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb index 27bc4310200..d920f260cce 100644 --- a/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb @@ -71,4 +71,28 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl let(:action) { described_class::MR_REOPEN_ACTION } end end + + describe '.track_create_comment_action' do + subject { described_class.track_create_comment_action(user: user) } + + it_behaves_like 'a tracked merge request unique event' do + let(:action) { described_class::MR_CREATE_COMMENT_ACTION } + end + end + + describe '.track_edit_comment_action' do + subject { described_class.track_edit_comment_action(user: user) } + + it_behaves_like 'a tracked merge request unique event' do + let(:action) { described_class::MR_EDIT_COMMENT_ACTION } + end + end + + describe '.track_remove_comment_action' do + subject { described_class.track_remove_comment_action(user: user) } + + it_behaves_like 'a tracked merge request unique event' do + let(:action) { described_class::MR_REMOVE_COMMENT_ACTION } + end + end end diff --git a/spec/mailers/emails/merge_requests_spec.rb b/spec/mailers/emails/merge_requests_spec.rb index 412cdff3aba..34665d943ab 100644 --- a/spec/mailers/emails/merge_requests_spec.rb +++ b/spec/mailers/emails/merge_requests_spec.rb @@ -64,7 +64,7 @@ RSpec.describe Emails::MergeRequests do } end - it { expect(subject).to have_content('This attachment has been truncated to avoid exceeding the maximum allowed attachment size of 15MB.') } + it { expect(subject).to have_content('attachment has been truncated to avoid exceeding the maximum allowed attachment size of 15 MB.') } end end end diff --git a/spec/services/issues/export_csv_service_spec.rb b/spec/services/issues/export_csv_service_spec.rb index 8072b7a478e..fd1bcf82ccd 100644 --- a/spec/services/issues/export_csv_service_spec.rb +++ b/spec/services/issues/export_csv_service_spec.rb @@ -20,7 +20,9 @@ RSpec.describe Issues::ExportCsvService do end it 'renders with a target filesize' do - expect(subject.csv_builder).to receive(:render).with(described_class::TARGET_FILESIZE) + expect_next_instance_of(CsvBuilder) do |csv_builder| + expect(csv_builder).to receive(:render).with(described_class::TARGET_FILESIZE).once + end subject.email(user) end diff --git a/spec/services/notes/create_service_spec.rb b/spec/services/notes/create_service_spec.rb index 3118956951e..451615c6f53 100644 --- a/spec/services/notes/create_service_spec.rb +++ b/spec/services/notes/create_service_spec.rb @@ -78,6 +78,12 @@ RSpec.describe Notes::CreateService do end.to change { counter.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) }.by(1) end + it 'does not track merge request usage data' do + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).not_to receive(:track_create_comment_action) + + described_class.new(project, user, opts).execute + end + context 'in a merge request' do let_it_be(:project_with_repo) { create(:project, :repository) } let_it_be(:merge_request) do @@ -85,18 +91,6 @@ RSpec.describe Notes::CreateService do target_project: project_with_repo) end - context 'issue comment usage data' do - let(:opts) do - { note: 'Awesome comment', noteable_type: 'MergeRequest', noteable_id: merge_request.id } - end - - it 'does not track' do - expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_comment_added_action) - - described_class.new(project, user, opts).execute - end - end - context 'noteable highlight cache clearing' do let(:position) do Gitlab::Diff::Position.new(old_path: "files/ruby/popen.rb", @@ -119,6 +113,18 @@ RSpec.describe Notes::CreateService do .to receive(:unfolded_diff?) { true } end + it 'does not track issue comment usage data' do + expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_comment_added_action) + + described_class.new(project_with_repo, user, new_opts).execute + end + + it 'tracks merge request usage data' do + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).to receive(:track_create_comment_action).with(user: user) + + described_class.new(project_with_repo, user, new_opts).execute + end + it 'clears noteable diff cache when it was unfolded for the note position' do expect_any_instance_of(Gitlab::Diff::HighlightCache).to receive(:clear) diff --git a/spec/services/notes/destroy_service_spec.rb b/spec/services/notes/destroy_service_spec.rb index 0859c28cbe7..a19840af7a7 100644 --- a/spec/services/notes/destroy_service_spec.rb +++ b/spec/services/notes/destroy_service_spec.rb @@ -35,6 +35,14 @@ RSpec.describe Notes::DestroyService do end.to change { counter.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) }.by(1) end + it 'tracks merge request usage data' do + mr = create(:merge_request, source_project: project) + note = create(:note, project: project, noteable: mr) + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).to receive(:track_remove_comment_action).with(user: user) + + described_class.new(project, user).execute(note) + end + context 'in a merge request' do let_it_be(:repo_project) { create(:project, :repository) } let_it_be(:merge_request) do diff --git a/spec/services/notes/update_service_spec.rb b/spec/services/notes/update_service_spec.rb index e2f51c9af67..2ebf0c29686 100644 --- a/spec/services/notes/update_service_spec.rb +++ b/spec/services/notes/update_service_spec.rb @@ -49,11 +49,12 @@ RSpec.describe Notes::UpdateService do it 'does not track usage data when params is blank' do expect(Gitlab::UsageDataCounters::IssueActivityUniqueCounter).not_to receive(:track_issue_comment_edited_action) + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).not_to receive(:track_edit_comment_action) update_note({}) end - it 'tracks usage data', :clean_gitlab_redis_shared_state do + it 'tracks issue usage data', :clean_gitlab_redis_shared_state do event = Gitlab::UsageDataCounters::IssueActivityUniqueCounter::ISSUE_COMMENT_EDITED counter = Gitlab::UsageDataCounters::HLLRedisCounter @@ -63,6 +64,17 @@ RSpec.describe Notes::UpdateService do end.to change { counter.unique_events(event_names: event, start_date: 1.day.ago, end_date: 1.day.from_now) }.by(1) end + context 'when the notable is a merge request' do + let(:merge_request) { create(:merge_request, source_project: project) } + let(:note) { create(:note, project: project, noteable: merge_request, author: user, note: "Old note #{user2.to_reference}") } + + it 'tracks merge request usage data' do + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter).to receive(:track_edit_comment_action).with(user: user) + + update_note(note: 'new text') + end + end + context 'with system note' do before do note.update_column(:system, true) diff --git a/spec/tasks/gitlab/git_rake_spec.rb b/spec/tasks/gitlab/git_rake_spec.rb index 4bc1b460d9b..4d89b126c9e 100644 --- a/spec/tasks/gitlab/git_rake_spec.rb +++ b/spec/tasks/gitlab/git_rake_spec.rb @@ -19,4 +19,38 @@ RSpec.describe 'gitlab:git rake tasks' do expect { run_rake_task('gitlab:git:fsck') }.to output(/Performed integrity check for/).to_stdout end end + + describe 'checksum_projects' do + it 'outputs the checksum for a repo' do + expected = /#{project.id},#{project.repository.checksum}/ + + expect { run_rake_task('gitlab:git:checksum_projects') }.to output(expected).to_stdout + end + + it 'outputs blank checksum for no repo' do + no_repo = create(:project) + + expected = /#{no_repo.id},$/ + + expect { run_rake_task('gitlab:git:checksum_projects') }.to output(expected).to_stdout + end + + it 'outputs zeroes for empty repo' do + empty_repo = create(:project, :empty_repo) + + expected = /#{empty_repo.id},0000000000000000000000000000000000000000/ + + expect { run_rake_task('gitlab:git:checksum_projects') }.to output(expected).to_stdout + end + + it 'outputs errors' do + allow_next_found_instance_of(Project) do |project| + allow(project).to receive(:repo_exists?).and_raise('foo') + end + + expected = /#{project.id},Ignored error: foo/ + + expect { run_rake_task('gitlab:git:checksum_projects') }.to output(expected).to_stdout + end + end end diff --git a/spec/workers/jira_connect/sync_branch_worker_spec.rb b/spec/workers/jira_connect/sync_branch_worker_spec.rb index c8453064b0d..7c715f36fb4 100644 --- a/spec/workers/jira_connect/sync_branch_worker_spec.rb +++ b/spec/workers/jira_connect/sync_branch_worker_spec.rb @@ -13,82 +13,67 @@ RSpec.describe JiraConnect::SyncBranchWorker do let(:project_id) { project.id } let(:branch_name) { 'master' } let(:commit_shas) { %w(b83d6e3 5a62481) } - - subject { described_class.new.perform(project_id, branch_name, commit_shas) } + let(:update_sequence_id) { 1 } def expect_jira_sync_service_execute(args) - expect_next_instance_of(JiraConnect::SyncService) do |instance| - expect(instance).to receive(:execute).with(args.merge(update_sequence_id: nil)) + expect_next_instances_of(JiraConnect::SyncService, IdempotentWorkerHelper::WORKER_EXEC_TIMES) do |instance| + expect(instance).to receive(:execute).with(args) end end - it 'calls JiraConnect::SyncService#execute' do - expect_jira_sync_service_execute( - branches: [instance_of(Gitlab::Git::Branch)], - commits: project.commits_by(oids: commit_shas) - ) - - subject - end + it_behaves_like 'an idempotent worker' do + let(:job_args) { [project_id, branch_name, commit_shas, update_sequence_id] } - context 'without branch name' do - let(:branch_name) { nil } - - it 'calls JiraConnect::SyncService#execute' do - expect_jira_sync_service_execute( - branches: nil, - commits: project.commits_by(oids: commit_shas) - ) - - subject + before do + stub_request(:post, 'https://sample.atlassian.net/rest/devinfo/0.10/bulk').to_return(status: 200, body: '', headers: {}) end - end - - context 'without commits' do - let(:commit_shas) { nil } it 'calls JiraConnect::SyncService#execute' do expect_jira_sync_service_execute( branches: [instance_of(Gitlab::Git::Branch)], - commits: nil + commits: project.commits_by(oids: commit_shas), + update_sequence_id: update_sequence_id ) subject end - end - context 'when project no longer exists' do - let(:project_id) { non_existing_record_id } + context 'without branch name' do + let(:branch_name) { nil } - it 'does not call JiraConnect::SyncService' do - expect(JiraConnect::SyncService).not_to receive(:new) + it 'calls JiraConnect::SyncService#execute' do + expect_jira_sync_service_execute( + branches: nil, + commits: project.commits_by(oids: commit_shas), + update_sequence_id: update_sequence_id + ) - subject + subject + end end - end - context 'with update_sequence_id' do - let(:update_sequence_id) { 1 } - let(:request_path) { '/rest/devinfo/0.10/bulk' } - let(:request_body) do - { - repositories: [ - Atlassian::JiraConnect::Serializers::RepositoryEntity.represent( - project, - commits: project.commits_by(oids: commit_shas), - branches: [project.repository.find_branch(branch_name)], - update_sequence_id: update_sequence_id - ) - ] - } + context 'without commits' do + let(:commit_shas) { nil } + + it 'calls JiraConnect::SyncService#execute' do + expect_jira_sync_service_execute( + branches: [instance_of(Gitlab::Git::Branch)], + commits: nil, + update_sequence_id: update_sequence_id + ) + + subject + end end - subject { described_class.new.perform(project_id, branch_name, commit_shas, update_sequence_id) } + context 'when project no longer exists' do + let(:project_id) { non_existing_record_id } - it 'sends the reqeust with custom update_sequence_id' do - expect_next(Atlassian::JiraConnect::Client).to receive(:post).with(request_path, request_body) + it 'does not call JiraConnect::SyncService' do + expect(JiraConnect::SyncService).not_to receive(:new) - subject + subject + end end end end diff --git a/spec/workers/jira_connect/sync_merge_request_worker_spec.rb b/spec/workers/jira_connect/sync_merge_request_worker_spec.rb index 1a40aa2b3ad..6a0a0744f6f 100644 --- a/spec/workers/jira_connect/sync_merge_request_worker_spec.rb +++ b/spec/workers/jira_connect/sync_merge_request_worker_spec.rb @@ -12,48 +12,31 @@ RSpec.describe JiraConnect::SyncMergeRequestWorker do let_it_be(:merge_request) { create(:merge_request, source_project: project) } let(:merge_request_id) { merge_request.id } + let(:update_sequence_id) { 1 } - subject { described_class.new.perform(merge_request_id) } + it_behaves_like 'an idempotent worker' do + let(:job_args) { [merge_request_id, update_sequence_id] } - it 'calls JiraConnect::SyncService#execute' do - expect_next_instance_of(JiraConnect::SyncService) do |service| - expect(service).to receive(:execute).with(merge_requests: [merge_request], update_sequence_id: nil) + before do + stub_request(:post, 'https://sample.atlassian.net/rest/devinfo/0.10/bulk').to_return(status: 200, body: '', headers: {}) end - subject - end - - context 'when MR no longer exists' do - let(:merge_request_id) { non_existing_record_id } - - it 'does not call JiraConnect::SyncService' do - expect(JiraConnect::SyncService).not_to receive(:new) + it 'calls JiraConnect::SyncService#execute' do + expect_next_instances_of(JiraConnect::SyncService, IdempotentWorkerHelper::WORKER_EXEC_TIMES) do |service| + expect(service).to receive(:execute).with(merge_requests: [merge_request], update_sequence_id: update_sequence_id) + end subject end - end - context 'with update_sequence_id' do - let(:update_sequence_id) { 1 } - let(:request_path) { '/rest/devinfo/0.10/bulk' } - let(:request_body) do - { - repositories: [ - Atlassian::JiraConnect::Serializers::RepositoryEntity.represent( - project, - merge_requests: [merge_request], - update_sequence_id: update_sequence_id - ) - ] - } - end - - subject { described_class.new.perform(merge_request_id, update_sequence_id) } + context 'when MR no longer exists' do + let(:merge_request_id) { non_existing_record_id } - it 'sends the request with custom update_sequence_id' do - expect_next(Atlassian::JiraConnect::Client).to receive(:post).with(request_path, request_body) + it 'does not call JiraConnect::SyncService' do + expect(JiraConnect::SyncService).not_to receive(:new) - subject + subject + end end end end |