diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-25 15:11:32 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-25 15:11:32 +0300 |
commit | 975eac49924cf0e9c980d970458d14d2ddaa8b55 (patch) | |
tree | fc54fae4690daef41f2e44391fb659c7a4ea82f2 /spec | |
parent | 326b4d3216d107b40142ee847c06f2c41a1ef220 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/vue_mr_widget/components/states/__snapshots__/new_ready_to_merge_spec.js.snap | 37 | ||||
-rw-r--r-- | spec/frontend/vue_mr_widget/components/states/new_ready_to_merge_spec.js | 31 | ||||
-rw-r--r-- | spec/helpers/ci/runners_helper_spec.rb | 13 | ||||
-rw-r--r-- | spec/lib/gitlab/checks/changes_access_spec.rb | 58 | ||||
-rw-r--r-- | spec/lib/gitlab/git/commit_spec.rb | 36 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/commit_service_spec.rb | 35 | ||||
-rw-r--r-- | spec/models/issue/metrics_spec.rb | 18 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 23 | ||||
-rw-r--r-- | spec/services/git/base_hooks_service_spec.rb | 6 | ||||
-rw-r--r-- | spec/services/git/branch_hooks_service_spec.rb | 38 | ||||
-rw-r--r-- | spec/spec_helper.rb | 3 |
11 files changed, 227 insertions, 71 deletions
diff --git a/spec/frontend/vue_mr_widget/components/states/__snapshots__/new_ready_to_merge_spec.js.snap b/spec/frontend/vue_mr_widget/components/states/__snapshots__/new_ready_to_merge_spec.js.snap new file mode 100644 index 00000000000..a6c36764c41 --- /dev/null +++ b/spec/frontend/vue_mr_widget/components/states/__snapshots__/new_ready_to_merge_spec.js.snap @@ -0,0 +1,37 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`New ready to merge state component renders permission text if canMerge (false) is false 1`] = ` +<div + class="mr-widget-body media" +> + <status-icon-stub + status="success" + /> + + <p + class="media-body gl-m-0! gl-font-weight-bold" + > + + Ready to merge by members who can write to the target branch. + + </p> +</div> +`; + +exports[`New ready to merge state component renders permission text if canMerge (true) is false 1`] = ` +<div + class="mr-widget-body media" +> + <status-icon-stub + status="success" + /> + + <p + class="media-body gl-m-0! gl-font-weight-bold" + > + + Ready to merge! + + </p> +</div> +`; diff --git a/spec/frontend/vue_mr_widget/components/states/new_ready_to_merge_spec.js b/spec/frontend/vue_mr_widget/components/states/new_ready_to_merge_spec.js new file mode 100644 index 00000000000..5ec9654a4af --- /dev/null +++ b/spec/frontend/vue_mr_widget/components/states/new_ready_to_merge_spec.js @@ -0,0 +1,31 @@ +import { shallowMount } from '@vue/test-utils'; +import ReadyToMerge from '~/vue_merge_request_widget/components/states/new_ready_to_merge.vue'; + +let wrapper; + +function factory({ canMerge }) { + wrapper = shallowMount(ReadyToMerge, { + propsData: { + mr: {}, + }, + data() { + return { canMerge }; + }, + }); +} + +describe('New ready to merge state component', () => { + afterEach(() => { + wrapper.destroy(); + }); + + it.each` + canMerge + ${true} + ${false} + `('renders permission text if canMerge ($canMerge) is false', ({ canMerge }) => { + factory({ canMerge }); + + expect(wrapper.element).toMatchSnapshot(); + }); +}); diff --git a/spec/helpers/ci/runners_helper_spec.rb b/spec/helpers/ci/runners_helper_spec.rb index 40927d44e24..0f15f8be0a9 100644 --- a/spec/helpers/ci/runners_helper_spec.rb +++ b/spec/helpers/ci/runners_helper_spec.rb @@ -88,6 +88,19 @@ RSpec.describe Ci::RunnersHelper do end end + describe '#group_runners_data_attributes' do + let(:group) { create(:group) } + + it 'returns group data to render a runner list' do + data = group_runners_data_attributes(group) + + expect(data[:registration_token]).to eq(group.runners_token) + expect(data[:group_id]).to eq(group.id) + expect(data[:group_full_path]).to eq(group.full_path) + expect(data[:runner_install_help_page]).to eq('https://docs.gitlab.com/runner/install/') + end + end + describe '#toggle_shared_runners_settings_data' do let_it_be(:group) { create(:group) } diff --git a/spec/lib/gitlab/checks/changes_access_spec.rb b/spec/lib/gitlab/checks/changes_access_spec.rb index 4a74dfcec34..b6914a0a8f1 100644 --- a/spec/lib/gitlab/checks/changes_access_spec.rb +++ b/spec/lib/gitlab/checks/changes_access_spec.rb @@ -8,53 +8,35 @@ RSpec.describe Gitlab::Checks::ChangesAccess do subject { changes_access } describe '#validate!' do - shared_examples '#validate!' do - before do - allow(project).to receive(:lfs_enabled?).and_return(true) - end - - context 'without failed checks' do - it "doesn't raise an error" do - expect { subject.validate! }.not_to raise_error - end - - it 'calls lfs checks' do - expect_next_instance_of(Gitlab::Checks::LfsCheck) do |instance| - expect(instance).to receive(:validate!) - end + before do + allow(project).to receive(:lfs_enabled?).and_return(true) + end - subject.validate! - end + context 'without failed checks' do + it "doesn't raise an error" do + expect { subject.validate! }.not_to raise_error end - context 'when time limit was reached' do - it 'raises a TimeoutError' do - logger = Gitlab::Checks::TimedLogger.new(start_time: timeout.ago, timeout: timeout) - access = described_class.new(changes, - project: project, - user_access: user_access, - protocol: protocol, - logger: logger) - - expect { access.validate! }.to raise_error(Gitlab::Checks::TimedLogger::TimeoutError) + it 'calls lfs checks' do + expect_next_instance_of(Gitlab::Checks::LfsCheck) do |instance| + expect(instance).to receive(:validate!) end - end - end - context 'with batched commits enabled' do - before do - stub_feature_flags(changes_batch_commits: true) + subject.validate! end - - it_behaves_like '#validate!' end - context 'with batched commits disabled' do - before do - stub_feature_flags(changes_batch_commits: false) - end + context 'when time limit was reached' do + it 'raises a TimeoutError' do + logger = Gitlab::Checks::TimedLogger.new(start_time: timeout.ago, timeout: timeout) + access = described_class.new(changes, + project: project, + user_access: user_access, + protocol: protocol, + logger: logger) - it_behaves_like '#validate!' + expect { access.validate! }.to raise_error(Gitlab::Checks::TimedLogger::TimeoutError) + end end end diff --git a/spec/lib/gitlab/git/commit_spec.rb b/spec/lib/gitlab/git/commit_spec.rb index 174ed43bd40..f4dba5e8d58 100644 --- a/spec/lib/gitlab/git/commit_spec.rb +++ b/spec/lib/gitlab/git/commit_spec.rb @@ -364,12 +364,40 @@ RSpec.describe Gitlab::Git::Commit, :seed_helper do end describe '.between' do - subject do - commits = described_class.between(repository, SeedRepo::Commit::PARENT_ID, SeedRepo::Commit::ID) - commits.map { |c| c.id } + let(:limit) { nil } + let(:commit_ids) { commits.map(&:id) } + + subject(:commits) { described_class.between(repository, from, to, limit: limit) } + + context 'requesting a single commit' do + let(:from) { SeedRepo::Commit::PARENT_ID } + let(:to) { SeedRepo::Commit::ID } + + it { expect(commit_ids).to contain_exactly(to) } end - it { is_expected.to contain_exactly(SeedRepo::Commit::ID) } + context 'requesting a commit range' do + let(:from) { 'v1.0.0' } + let(:to) { 'v1.2.0' } + + let(:commits_in_range) do + %w[ + 570e7b2abdd848b95f2f578043fc23bd6f6fd24d + 5937ac0a7beb003549fc5fd26fc247adbce4a52e + eb49186cfa5c4338011f5f590fac11bd66c5c631 + ] + end + + context 'no limit' do + it { expect(commit_ids).to eq(commits_in_range) } + end + + context 'limited' do + let(:limit) { 2 } + + it { expect(commit_ids).to eq(commits_in_range.last(2)) } + end + end end describe '.shas_with_signatures' do diff --git a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb index a0e2d43cf45..554a91f2bc5 100644 --- a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb @@ -311,6 +311,10 @@ RSpec.describe Gitlab::GitalyClient::CommitService do end describe '#list_commits' do + let(:revisions) { 'master' } + let(:reverse) { false } + let(:pagination_params) { nil } + shared_examples 'a ListCommits request' do before do ::Gitlab::GitalyClient.clear_stubs! @@ -318,26 +322,35 @@ RSpec.describe Gitlab::GitalyClient::CommitService do it 'sends a list_commits message' do expect_next_instance_of(Gitaly::CommitService::Stub) do |service| - expect(service) - .to receive(:list_commits) - .with(gitaly_request_with_params(expected_params), kind_of(Hash)) - .and_return([]) + expected_request = gitaly_request_with_params( + Array.wrap(revisions), + reverse: reverse, + pagination_params: pagination_params + ) + + expect(service).to receive(:list_commits).with(expected_request, kind_of(Hash)).and_return([]) end - client.list_commits(revisions) + client.list_commits(revisions, reverse: reverse, pagination_params: pagination_params) end end - context 'with a single revision' do - let(:revisions) { 'master' } - let(:expected_params) { %w[master] } + it_behaves_like 'a ListCommits request' + + context 'with multiple revisions' do + let(:revisions) { %w[master --not --all] } + + it_behaves_like 'a ListCommits request' + end + + context 'with reverse: true' do + let(:reverse) { true } it_behaves_like 'a ListCommits request' end - context 'with multiple revisions' do - let(:revisions) { %w[master --not --all] } - let(:expected_params) { %w[master --not --all] } + context 'with pagination params' do + let(:pagination_params) { { limit: 1, page_token: 'foo' } } it_behaves_like 'a ListCommits request' end diff --git a/spec/models/issue/metrics_spec.rb b/spec/models/issue/metrics_spec.rb index 6e3ef69017b..2fdf1f09f80 100644 --- a/spec/models/issue/metrics_spec.rb +++ b/spec/models/issue/metrics_spec.rb @@ -34,7 +34,7 @@ RSpec.describe Issue::Metrics do end end - shared_examples "when recording the default set of issue metrics on issue save" do + context "when recording the default set of issue metrics on issue save" do context "milestones" do it "records the first time an issue is associated with a milestone" do time = Time.current @@ -81,20 +81,4 @@ RSpec.describe Issue::Metrics do end end end - - context 'when upsert_issue_metrics is enabled' do - before do - stub_feature_flags(upsert_issue_metrics: true) - end - - it_behaves_like 'when recording the default set of issue metrics on issue save' - end - - context 'when upsert_issue_metrics is disabled' do - before do - stub_feature_flags(upsert_issue_metrics: false) - end - - it_behaves_like 'when recording the default set of issue metrics on issue save' - end end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 064d793588f..949892beed5 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -470,6 +470,29 @@ RSpec.describe Repository do end end + describe '#commits_between' do + let(:commit) { project.commit } + + it 'delegates to Gitlab::Git::Commit#between, returning decorated commits' do + expect(Gitlab::Git::Commit) + .to receive(:between) + .with(repository.raw_repository, commit.parent_id, commit.id, limit: 5) + .and_call_original + + result = repository.commits_between(commit.parent_id, commit.id, limit: 5) + + expect(result).to contain_exactly(instance_of(Commit), instance_of(Commit)) + end + + it 'defaults to no limit' do + expect(Gitlab::Git::Commit) + .to receive(:between) + .with(repository.raw_repository, commit.parent_id, commit.id, limit: nil) + + repository.commits_between(commit.parent_id, commit.id) + end + end + describe '#find_commits_by_message' do it 'returns commits with messages containing a given string' do commit_ids = repository.find_commits_by_message('submodule').map(&:id) diff --git a/spec/services/git/base_hooks_service_spec.rb b/spec/services/git/base_hooks_service_spec.rb index 539c294a2e7..a8d753ff124 100644 --- a/spec/services/git/base_hooks_service_spec.rb +++ b/spec/services/git/base_hooks_service_spec.rb @@ -19,9 +19,13 @@ RSpec.describe Git::BaseHooksService do :push_hooks end - def commits + def limited_commits [] end + + def commits_count + 0 + end end end diff --git a/spec/services/git/branch_hooks_service_spec.rb b/spec/services/git/branch_hooks_service_spec.rb index a93f594b360..79c2cb1fca3 100644 --- a/spec/services/git/branch_hooks_service_spec.rb +++ b/spec/services/git/branch_hooks_service_spec.rb @@ -362,6 +362,9 @@ RSpec.describe Git::BranchHooksService, :clean_gitlab_redis_shared_state do end end + let(:commits_count) { service.send(:commits_count) } + let(:threshold_limit) { described_class::PROCESS_COMMIT_LIMIT + 1 } + let(:oldrev) { project.commit(commit_ids.first).parent_id } let(:newrev) { commit_ids.last } @@ -373,17 +376,31 @@ RSpec.describe Git::BranchHooksService, :clean_gitlab_redis_shared_state do let(:oldrev) { Gitlab::Git::BLANK_SHA } it 'processes a limited number of commit messages' do + expect(project.repository) + .to receive(:commits) + .with(newrev, limit: threshold_limit) + .and_call_original + expect(ProcessCommitWorker).to receive(:perform_async).twice service.execute + + expect(commits_count).to eq(project.repository.commit_count_for_ref(newrev)) end end context 'updating the default branch' do it 'processes a limited number of commit messages' do + expect(project.repository) + .to receive(:commits_between) + .with(oldrev, newrev, limit: threshold_limit) + .and_call_original + expect(ProcessCommitWorker).to receive(:perform_async).twice service.execute + + expect(commits_count).to eq(project.repository.count_commits_between(oldrev, newrev)) end end @@ -391,9 +408,13 @@ RSpec.describe Git::BranchHooksService, :clean_gitlab_redis_shared_state do let(:newrev) { Gitlab::Git::BLANK_SHA } it 'does not process commit messages' do + expect(project.repository).not_to receive(:commits) + expect(project.repository).not_to receive(:commits_between) expect(ProcessCommitWorker).not_to receive(:perform_async) service.execute + + expect(commits_count).to eq(0) end end @@ -402,9 +423,16 @@ RSpec.describe Git::BranchHooksService, :clean_gitlab_redis_shared_state do let(:oldrev) { Gitlab::Git::BLANK_SHA } it 'processes a limited number of commit messages' do + expect(project.repository) + .to receive(:commits_between) + .with(project.default_branch, newrev, limit: threshold_limit) + .and_call_original + expect(ProcessCommitWorker).to receive(:perform_async).twice service.execute + + expect(commits_count).to eq(project.repository.count_commits_between(project.default_branch, branch)) end end @@ -412,9 +440,15 @@ RSpec.describe Git::BranchHooksService, :clean_gitlab_redis_shared_state do let(:branch) { 'fix' } it 'processes a limited number of commit messages' do + expect(project.repository) + .to receive(:commits_between) + .with(oldrev, newrev, limit: threshold_limit) + .and_call_original + expect(ProcessCommitWorker).to receive(:perform_async).twice service.execute + expect(commits_count).to eq(project.repository.count_commits_between(oldrev, newrev)) end end @@ -423,9 +457,13 @@ RSpec.describe Git::BranchHooksService, :clean_gitlab_redis_shared_state do let(:newrev) { Gitlab::Git::BLANK_SHA } it 'does not process commit messages' do + expect(project.repository).not_to receive(:commits) + expect(project.repository).not_to receive(:commits_between) expect(ProcessCommitWorker).not_to receive(:perform_async) service.execute + + expect(commits_count).to eq(0) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b95b7fad5a0..2ed9786b216 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -260,6 +260,9 @@ RSpec.configure do |config| # tests, until we introduce it in user settings stub_feature_flags(forti_token_cloud: false) + # Disable for now whilst we add more states + stub_feature_flags(restructured_mr_widget: false) + # These feature flag are by default disabled and used in disaster recovery mode stub_feature_flags(ci_queueing_disaster_recovery_disable_fair_scheduling: false) stub_feature_flags(ci_queueing_disaster_recovery_disable_quota: false) |