diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-03 00:09:18 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-03 00:09:18 +0300 |
commit | 68da8a6cb432996324a4c2fe4dca70ae260ce73f (patch) | |
tree | fbaa3dbc4d8caccdcfac29afff238dee0d8084e5 /spec | |
parent | e28bb9d18133611eef2a1357c57dc57ca97cfd5a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
11 files changed, 153 insertions, 29 deletions
diff --git a/spec/features/cycle_analytics_spec.rb b/spec/features/cycle_analytics_spec.rb index e843f37c6f1..7714783172f 100644 --- a/spec/features/cycle_analytics_spec.rb +++ b/spec/features/cycle_analytics_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe 'Value Stream Analytics', :js do + include CycleAnalyticsHelpers + let_it_be(:user) { create(:user) } let_it_be(:guest) { create(:user) } let_it_be(:stage_table_selector) { '[data-testid="vsa-stage-table"]' } diff --git a/spec/features/markdown/gitlab_flavored_markdown_spec.rb b/spec/features/markdown/gitlab_flavored_markdown_spec.rb index da4208318eb..e831d1be608 100644 --- a/spec/features/markdown/gitlab_flavored_markdown_spec.rb +++ b/spec/features/markdown/gitlab_flavored_markdown_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe "GitLab Flavored Markdown" do + include CycleAnalyticsHelpers + let(:user) { create(:user) } let(:project) { create(:project) } let(:issue) { create(:issue, project: project) } diff --git a/spec/features/search/user_searches_for_commits_spec.rb b/spec/features/search/user_searches_for_commits_spec.rb index 279db686aa9..2dceda09d7c 100644 --- a/spec/features/search/user_searches_for_commits_spec.rb +++ b/spec/features/search/user_searches_for_commits_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe 'User searches for commits', :js do + include CycleAnalyticsHelpers + let(:project) { create(:project, :repository) } let(:sha) { '6d394385cf567f80a8fd85055db1ab4c5295806f' } let(:user) { create(:user) } diff --git a/spec/frontend/vue_merge_request_widget/components/states/mr_widget_failed_to_merge_spec.js b/spec/frontend/vue_merge_request_widget/components/states/mr_widget_failed_to_merge_spec.js index a9c1d602a37..989aa76f09b 100644 --- a/spec/frontend/vue_merge_request_widget/components/states/mr_widget_failed_to_merge_spec.js +++ b/spec/frontend/vue_merge_request_widget/components/states/mr_widget_failed_to_merge_spec.js @@ -53,7 +53,31 @@ describe('MRWidgetFailedToMerge', () => { await nextTick(); - expect(wrapper.vm.mergeError).toBe('contains line breaks.'); + expect(wrapper.find('[data-testid="merge-error"]').text()).toBe('contains line breaks.'); + }); + + it('does not append an extra period', async () => { + createComponent({ mr: { mergeError: 'contains a period.' } }); + + await nextTick(); + + expect(wrapper.find('[data-testid="merge-error"]').text()).toBe('contains a period.'); + }); + + it('does not insert an extra space between the final character and the period', async () => { + createComponent({ mr: { mergeError: 'contains a <a href="http://example.com">link</a>.' } }); + + await nextTick(); + + expect(wrapper.find('[data-testid="merge-error"]').text()).toBe('contains a link.'); + }); + + it('removes extra spaces', async () => { + createComponent({ mr: { mergeError: 'contains a lot of spaces .' } }); + + await nextTick(); + + expect(wrapper.find('[data-testid="merge-error"]').text()).toBe('contains a lot of spaces.'); }); }); diff --git a/spec/helpers/ci/pipeline_editor_helper_spec.rb b/spec/helpers/ci/pipeline_editor_helper_spec.rb index 5d3837171d0..59f24e7ceb8 100644 --- a/spec/helpers/ci/pipeline_editor_helper_spec.rb +++ b/spec/helpers/ci/pipeline_editor_helper_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Ci::PipelineEditorHelper do + include CycleAnalyticsHelpers + let_it_be(:project) { create(:project) } describe 'can_view_pipeline_editor?' do diff --git a/spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb b/spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb index 7173ea43450..0e7d7f1efda 100644 --- a/spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb +++ b/spec/lib/gitlab/cycle_analytics/stage_summary_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe Gitlab::CycleAnalytics::StageSummary do + include CycleAnalyticsHelpers + let_it_be(:project) { create(:project, :repository) } let(:options) { { from: 1.day.ago } } diff --git a/spec/requests/projects/cycle_analytics_events_spec.rb b/spec/requests/projects/cycle_analytics_events_spec.rb index 89d46b64311..b092df4a116 100644 --- a/spec/requests/projects/cycle_analytics_events_spec.rb +++ b/spec/requests/projects/cycle_analytics_events_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe 'value stream analytics events' do + include CycleAnalyticsHelpers + let(:user) { create(:user) } let(:project) { create(:project, :repository, public_builds: false) } let(:issue) { create(:issue, project: project, created_at: 2.days.ago) } diff --git a/spec/services/branches/create_service_spec.rb b/spec/services/branches/create_service_spec.rb index 0d2f5838574..5904ef9b5cf 100644 --- a/spec/services/branches/create_service_spec.rb +++ b/spec/services/branches/create_service_spec.rb @@ -2,17 +2,130 @@ require 'spec_helper' -RSpec.describe Branches::CreateService do +RSpec.describe Branches::CreateService, :use_clean_rails_redis_caching do subject(:service) { described_class.new(project, user) } let_it_be(:project) { create(:project_empty_repo) } let_it_be(:user) { create(:user) } + describe '#bulk_create' do + subject { service.bulk_create(branches) } + + let_it_be(:project) { create(:project, :custom_repo, files: { 'foo/a.txt' => 'foo' }) } + + let(:branches) { { 'branch' => 'master', 'another_branch' => 'master' } } + + it 'creates two branches' do + expect(subject[:status]).to eq(:success) + expect(subject[:branches].map(&:name)).to match_array(%w[branch another_branch]) + + expect(project.repository.branch_exists?('branch')).to be_truthy + expect(project.repository.branch_exists?('another_branch')).to be_truthy + end + + context 'when branches are empty' do + let(:branches) { {} } + + it 'is successful' do + expect(subject[:status]).to eq(:success) + expect(subject[:branches]).to eq([]) + end + end + + context 'when incorrect reference is provided' do + let(:branches) { { 'new-feature' => 'unknown' } } + + before do + allow(project.repository).to receive(:add_branch).and_return(false) + end + + it 'returns an error with a reference name' do + err_msg = 'Failed to create branch \'new-feature\': invalid reference name \'unknown\'' + + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to match_array([err_msg]) + end + end + + context 'when branch already exists' do + let(:branches) { { 'master' => 'master' } } + + it 'returns an error' do + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to match_array(['Branch already exists']) + end + end + + context 'when an ambiguous branch name is provided' do + let(:branches) { { 'ambiguous/test' => 'master', 'ambiguous' => 'master' } } + + it 'returns an error that branch could not be created' do + err_msg = 'Failed to create branch \'ambiguous\': 13:reference is ambiguous.' + + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to match_array([err_msg]) + end + end + + context 'when PreReceiveError exception' do + let(:branches) { { 'error' => 'master' } } + + it 'logs and returns an error if there is a PreReceiveError exception' do + error_message = 'pre receive error' + raw_message = "GitLab: #{error_message}" + pre_receive_error = Gitlab::Git::PreReceiveError.new(raw_message) + + allow(project.repository).to receive(:add_branch).and_raise(pre_receive_error) + + expect(Gitlab::ErrorTracking).to receive(:log_exception).with( + pre_receive_error, + pre_receive_message: raw_message, + branch_name: 'error', + ref: 'master' + ) + + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to match_array([error_message]) + end + end + + context 'when multiple errors occur' do + let(:branches) { { 'master' => 'master', '' => 'master', 'failed_branch' => 'master' } } + + it 'returns all errors' do + allow(project.repository).to receive(:add_branch).with(user, 'failed_branch', 'master').and_return(false) + + expect(subject[:status]).to eq(:error) + expect(subject[:message]).to match_array( + [ + 'Branch already exists', + 'Branch name is invalid', + "Failed to create branch 'failed_branch': invalid reference name 'master'" + ] + ) + end + end + + context 'without N+1 for Redis cache' do + let(:branches) { { 'branch1' => 'master', 'branch2' => 'master', 'branch3' => 'master' } } + + it 'does not trigger Redis recreation' do + project.repository.expire_branches_cache + + control = RedisCommands::Recorder.new(pattern: ':branch_names:') { subject } + + expect(control.by_command(:sadd).count).to eq(1) + end + end + end + describe '#execute' do context 'when repository is empty' do it 'creates master branch' do - service.execute('my-feature', 'master') + result = service.execute('my-feature', 'master') + expect(result[:status]).to eq(:success) + expect(result[:branch].name).to eq('my-feature') expect(project.repository.branch_exists?('master')).to be_truthy end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 091627c8a38..7c4e2ec3ecc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -161,7 +161,6 @@ RSpec.configure do |config| config.include LicenseHelpers config.include ActiveJob::TestHelper config.include ActiveSupport::Testing::TimeHelpers - config.include CycleAnalyticsHelpers config.include FactoryBot::Syntax::Methods config.include FixtureHelpers config.include NonExistingRecordsHelpers diff --git a/spec/support/helpers/cycle_analytics_helpers.rb b/spec/support/helpers/cycle_analytics_helpers.rb index 044ec56b1cc..05e9a099a2b 100644 --- a/spec/support/helpers/cycle_analytics_helpers.rb +++ b/spec/support/helpers/cycle_analytics_helpers.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true module CycleAnalyticsHelpers - include GitHelpers - def toggle_value_stream_dropdown page.find('[data-testid="dropdown-value-streams"]').click end @@ -129,10 +127,6 @@ module CycleAnalyticsHelpers repository = project.repository oldrev = repository.commit(branch_name)&.sha || Gitlab::Git::BLANK_SHA - if Timecop.frozen? - mock_gitaly_multi_action_dates(repository, commit_time) - end - commit_shas = Array.new(count) do |index| commit_sha = repository.create_file(user, generate(:branch), "content", message: message, branch_name: branch_name) repository.commit(commit_sha) @@ -241,23 +235,4 @@ module CycleAnalyticsHelpers pipeline: dummy_pipeline(project), protected: false) end - - def mock_gitaly_multi_action_dates(repository, commit_time) - allow(repository.raw).to receive(:multi_action).and_wrap_original do |m, user, kargs| - new_date = commit_time || Time.now - branch_update = m.call(user, **kargs) - - if branch_update.newrev - commit = rugged_repo(repository).rev_parse(branch_update.newrev) - - branch_update.newrev = commit.amend( - update_ref: "#{Gitlab::Git::BRANCH_REF_PREFIX}#{kargs[:branch_name]}", - author: commit.author.merge(time: new_date), - committer: commit.committer.merge(time: new_date) - ) - end - - branch_update - end - end end diff --git a/spec/support/shared_contexts/fixtures/analytics_shared_context.rb b/spec/support/shared_contexts/fixtures/analytics_shared_context.rb index 13d3697a378..8e09cccee3e 100644 --- a/spec/support/shared_contexts/fixtures/analytics_shared_context.rb +++ b/spec/support/shared_contexts/fixtures/analytics_shared_context.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true RSpec.shared_context 'Analytics fixtures shared context' do + include CycleAnalyticsHelpers include JavaScriptFixturesHelpers let_it_be(:group) { create(:group) } |