summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-10 00:15:43 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-10 00:15:43 +0000
commitdd28adcbf0a6eea094968826799a24bbaac12262 (patch)
tree888829c0baea614dcf50d31d9887ee9e35836012 /spec
parent2744f5f9d735d892fad519329ba61544455e5279 (diff)
downloadgitlab-ce-dd28adcbf0a6eea094968826799a24bbaac12262.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/frontend/environments/deployment_spec.js30
-rw-r--r--spec/lib/extracts_path_spec.rb17
-rw-r--r--spec/lib/extracts_ref_spec.rb15
-rw-r--r--spec/lib/gitlab/path_regex_spec.rb12
-rw-r--r--spec/requests/api/commits_spec.rb8
-rw-r--r--spec/requests/api/graphql/mutations/work_items/update_spec.rb11
-rw-r--r--spec/support/shared_examples/path_extraction_shared_examples.rb5
7 files changed, 84 insertions, 14 deletions
diff --git a/spec/frontend/environments/deployment_spec.js b/spec/frontend/environments/deployment_spec.js
index 6ce0b76d98e..8936eb8fd64 100644
--- a/spec/frontend/environments/deployment_spec.js
+++ b/spec/frontend/environments/deployment_spec.js
@@ -209,6 +209,36 @@ describe('~/environments/components/deployment.vue', () => {
const username = wrapper.findByRole('link', { name: `@${deployment.user.username}` });
expect(username.attributes('href')).toBe(deployment.user.path);
+ const job = wrapper.findByRole('link', { name: deployment.deployable.name });
+ expect(job.attributes('href')).toBe(deployment.deployable.buildPath);
+ const apiBadge = wrapper.findByText(__('API'));
+ expect(apiBadge.exists()).toBe(false);
+ });
+ });
+ describe('with API deployment', () => {
+ beforeEach(async () => {
+ wrapper = createWrapper({ propsData: { deployment: { ...deployment, deployable: null } } });
+ await wrapper.findComponent({ ref: 'details-toggle' }).trigger('click');
+ });
+
+ it('shows API instead of a job name', () => {
+ const apiBadge = wrapper.findByText(__('API'));
+ expect(apiBadge.exists()).toBe(true);
+ });
+ });
+ describe('without a job path', () => {
+ beforeEach(async () => {
+ wrapper = createWrapper({
+ propsData: {
+ deployment: { ...deployment, deployable: { name: deployment.deployable.name } },
+ },
+ });
+ await wrapper.findComponent({ ref: 'details-toggle' }).trigger('click');
+ });
+
+ it('shows a span instead of a link', () => {
+ const job = wrapper.findByText(deployment.deployable.name);
+ expect(job.attributes('href')).toBeUndefined();
});
});
});
diff --git a/spec/lib/extracts_path_spec.rb b/spec/lib/extracts_path_spec.rb
index 13b607452e1..5db2fbd923e 100644
--- a/spec/lib/extracts_path_spec.rb
+++ b/spec/lib/extracts_path_spec.rb
@@ -32,7 +32,7 @@ RSpec.describe ExtractsPath do
describe '#assign_ref_vars' do
let(:ref) { sample_commit[:id] }
let(:path) { sample_commit[:line_code_path] }
- let(:params) { { path: path, ref: ref } }
+ let(:params) { ActionController::Parameters.new(path: path, ref: ref) }
it_behaves_like 'assigns ref vars'
@@ -54,7 +54,8 @@ RSpec.describe ExtractsPath do
context 'ref only exists without .atom suffix' do
context 'with a path' do
- let(:params) { { ref: 'v1.0.0.atom', path: 'README.md' } }
+ let(:ref) { 'v1.0.0.atom' }
+ let(:path) { 'README.md' }
it 'renders a 404' do
expect(self).to receive(:render_404)
@@ -64,7 +65,8 @@ RSpec.describe ExtractsPath do
end
context 'without a path' do
- let(:params) { { ref: 'v1.0.0.atom' } }
+ let(:ref) { 'v1.0.0.atom' }
+ let(:path) { nil }
before do
assign_ref_vars
@@ -82,7 +84,8 @@ RSpec.describe ExtractsPath do
context 'ref exists with .atom suffix' do
context 'with a path' do
- let(:params) { { ref: 'master.atom', path: 'README.md' } }
+ let(:ref) { 'master.atom' }
+ let(:path) { 'README.md' }
before do
repository = @project.repository
@@ -102,7 +105,8 @@ RSpec.describe ExtractsPath do
end
context 'without a path' do
- let(:params) { { ref: 'master.atom' } }
+ let(:ref) { 'master.atom' }
+ let(:path) { nil }
before do
repository = @project.repository
@@ -125,7 +129,8 @@ RSpec.describe ExtractsPath do
end
context 'ref and path are nil' do
- let(:params) { { path: nil, ref: nil } }
+ let(:path) { nil }
+ let(:ref) { nil }
it 'does not set commit' do
expect(container.repository).not_to receive(:commit).with('')
diff --git a/spec/lib/extracts_ref_spec.rb b/spec/lib/extracts_ref_spec.rb
index 3cdce150de9..3e9a7499fdd 100644
--- a/spec/lib/extracts_ref_spec.rb
+++ b/spec/lib/extracts_ref_spec.rb
@@ -10,7 +10,8 @@ RSpec.describe ExtractsRef do
let_it_be(:container) { create(:snippet, :repository, author: owner) }
let(:ref) { sample_commit[:id] }
- let(:params) { { path: sample_commit[:line_code_path], ref: ref } }
+ let(:path) { sample_commit[:line_code_path] }
+ let(:params) { ActionController::Parameters.new(path: path, ref: ref) }
before do
ref_names = ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0', 'release/app', 'release/app/v1.0.0']
@@ -23,7 +24,8 @@ RSpec.describe ExtractsRef do
it_behaves_like 'assigns ref vars'
context 'ref and path are nil' do
- let(:params) { { path: nil, ref: nil } }
+ let(:ref) { nil }
+ let(:path) { nil }
it 'does not set commit' do
expect(container.repository).not_to receive(:commit).with('')
@@ -33,6 +35,15 @@ RSpec.describe ExtractsRef do
expect(@commit).to be_nil
end
end
+
+ context 'when ref and path have incorrect format' do
+ let(:ref) { { wrong: :format } }
+ let(:path) { { also: :wrong } }
+
+ it 'does not raise an exception' do
+ expect { assign_ref_vars }.not_to raise_error
+ end
+ end
end
it_behaves_like 'extracts refs'
diff --git a/spec/lib/gitlab/path_regex_spec.rb b/spec/lib/gitlab/path_regex_spec.rb
index f0ba0f0459d..adabfe6890f 100644
--- a/spec/lib/gitlab/path_regex_spec.rb
+++ b/spec/lib/gitlab/path_regex_spec.rb
@@ -530,6 +530,18 @@ RSpec.describe Gitlab::PathRegex do
it { is_expected.not_to match('snippets/1.wiki.git') }
end
+ describe '.git_reference_regex' do
+ subject { %r{\A#{described_class.git_reference_regex}\z} }
+
+ it { is_expected.to match('main') }
+ it { is_expected.to match('v1.2.3') }
+ it { is_expected.to match('refs/heads/main') }
+ it { is_expected.to match('1-2-3') }
+ it { is_expected.to match('1-----') }
+ it { is_expected.not_to match('-main') }
+ it { is_expected.not_to match('') }
+ end
+
describe '.full_snippets_repository_path_regex' do
subject { described_class.full_snippets_repository_path_regex }
diff --git a/spec/requests/api/commits_spec.rb b/spec/requests/api/commits_spec.rb
index 156a4cf5ff3..96231b40ee0 100644
--- a/spec/requests/api/commits_spec.rb
+++ b/spec/requests/api/commits_spec.rb
@@ -127,6 +127,14 @@ RSpec.describe API::Commits do
it_behaves_like 'project commits'
end
+ context 'with incorrect ref_name parameter' do
+ let(:route) { "/projects/#{project_id}/repository/commits?ref_name=-main" }
+
+ it_behaves_like '400 response' do
+ let(:request) { get api(route, user) }
+ end
+ end
+
context "path optional parameter" do
it "returns project commits matching provided path parameter" do
path = 'files/ruby/popen.rb'
diff --git a/spec/requests/api/graphql/mutations/work_items/update_spec.rb b/spec/requests/api/graphql/mutations/work_items/update_spec.rb
index e34a1153fb1..f3a9f8dd49c 100644
--- a/spec/requests/api/graphql/mutations/work_items/update_spec.rb
+++ b/spec/requests/api/graphql/mutations/work_items/update_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe 'Update a work item' do
let_it_be(:work_item, refind: true) { create(:work_item, project: project) }
let(:work_item_event) { 'CLOSE' }
- let(:input) { { 'stateEvent' => work_item_event } }
+ let(:input) { { 'stateEvent' => work_item_event, 'title' => 'updated title' } }
let(:mutation) { graphql_mutation(:workItemUpdate, input.merge('id' => work_item.to_global_id.to_s)) }
@@ -26,15 +26,18 @@ RSpec.describe 'Update a work item' do
let(:current_user) { developer }
context 'when the work item is open' do
- it 'closes the work item' do
+ it 'closes and updates the work item' do
expect do
post_graphql_mutation(mutation, current_user: current_user)
work_item.reload
- end.to change(work_item, :state).from('opened').to('closed')
+ end.to change(work_item, :state).from('opened').to('closed').and(
+ change(work_item, :title).from(work_item.title).to('updated title')
+ )
expect(response).to have_gitlab_http_status(:success)
expect(mutation_response['workItem']).to include(
- 'state' => 'CLOSED'
+ 'state' => 'CLOSED',
+ 'title' => 'updated title'
)
end
end
diff --git a/spec/support/shared_examples/path_extraction_shared_examples.rb b/spec/support/shared_examples/path_extraction_shared_examples.rb
index 39c7c1f2a94..d76348aa26a 100644
--- a/spec/support/shared_examples/path_extraction_shared_examples.rb
+++ b/spec/support/shared_examples/path_extraction_shared_examples.rb
@@ -40,12 +40,13 @@ RSpec.shared_examples 'assigns ref vars' do
end
context 'path contains space' do
- let(:params) { { path: 'with space', ref: '38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e' } }
+ let(:ref) { '38008cb17ce1466d8fec2dfa6f6ab8dcfe5cf49e' }
+ let(:path) { 'with space' }
it 'is not converted to %20 in @path' do
assign_ref_vars
- expect(@path).to eq(params[:path])
+ expect(@path).to eq(path)
end
end