Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-03 00:11:07 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-03 00:11:07 +0300
commiteb1755b2d90efcc161774f66ccd2317ad4c471de (patch)
tree9404125b4bec27588f2a479470e46a27043d94f0 /spec
parentbf2439c21308c74e437b872180046b39a61734b5 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/import/bulk_imports_controller_spec.rb2
-rw-r--r--spec/controllers/projects_controller_spec.rb2
-rw-r--r--spec/frontend/experiment_tracking_spec.js11
-rw-r--r--spec/frontend/pipelines/graph_shared/links_layer_spec.js18
-rw-r--r--spec/frontend/projects/upload_file_experiment_spec.js14
-rw-r--r--spec/lib/expand_variables_spec.rb7
-rw-r--r--spec/lib/gitlab/ci/build/context/build_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/build/context/global_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/build/policy/variables_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/build/rules/rule_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/build/rules_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb17
-rw-r--r--spec/lib/gitlab/ci/variables/collection_spec.rb28
-rw-r--r--spec/lib/gitlab/hook_data/project_member_builder_spec.rb58
-rw-r--r--spec/lib/gitlab/word_diff/chunk_collection_spec.rb44
-rw-r--r--spec/lib/gitlab/word_diff/line_processor_spec.rb46
-rw-r--r--spec/lib/gitlab/word_diff/parser_spec.rb67
-rw-r--r--spec/lib/gitlab/word_diff/positions_counter_spec.rb35
-rw-r--r--spec/lib/gitlab/word_diff/segments/chunk_spec.rb53
-rw-r--r--spec/lib/gitlab/word_diff/segments/diff_hunk_spec.rb51
-rw-r--r--spec/lib/gitlab/word_diff/segments/newline_spec.rb13
-rw-r--r--spec/models/ci/bridge_spec.rb6
-rw-r--r--spec/models/ci/build_spec.rb52
-rw-r--r--spec/presenters/ci/build_runner_presenter_spec.rb24
-rw-r--r--spec/rubocop/cop/graphql/authorize_types_spec.rb30
-rw-r--r--spec/services/ci/create_pipeline_service/rules_spec.rb6
-rw-r--r--spec/services/system_hooks_service_spec.rb3
27 files changed, 522 insertions, 81 deletions
diff --git a/spec/controllers/import/bulk_imports_controller_spec.rb b/spec/controllers/import/bulk_imports_controller_spec.rb
index 70ed7c5812b..b450318f6f7 100644
--- a/spec/controllers/import/bulk_imports_controller_spec.rb
+++ b/spec/controllers/import/bulk_imports_controller_spec.rb
@@ -123,7 +123,7 @@ RSpec.describe Import::BulkImportsController do
it 'denies network request' do
get :status
- expect(controller).to redirect_to(new_group_path)
+ expect(controller).to redirect_to(new_group_path(anchor: 'import-group-pane'))
expect(flash[:alert]).to eq('Specified URL cannot be used: "Only allowed schemes are http, https"')
end
end
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb
index 281b69af605..1ae4bfdb843 100644
--- a/spec/controllers/projects_controller_spec.rb
+++ b/spec/controllers/projects_controller_spec.rb
@@ -231,7 +231,7 @@ RSpec.describe ProjectsController do
get :show, params: { namespace_id: empty_project.namespace, id: empty_project }
- expect_snowplow_event(category: 'empty_repo_upload', action: 'view_project_show', context: [{ schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/0-3-0', data: anything }])
+ expect_snowplow_event(category: 'empty_repo_upload', action: 'view_project_show', context: [{ schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/0-3-0', data: anything }], property: 'empty')
end
end
diff --git a/spec/frontend/experiment_tracking_spec.js b/spec/frontend/experiment_tracking_spec.js
index ac05419cecd..db209b783cb 100644
--- a/spec/frontend/experiment_tracking_spec.js
+++ b/spec/frontend/experiment_tracking_spec.js
@@ -5,13 +5,14 @@ jest.mock('~/tracking');
const oldGon = window.gon;
+let newGon = {};
let experimentTracking;
let label;
-let newGon = {};
+let property;
const setup = () => {
window.gon = newGon;
- experimentTracking = new ExperimentTracking('sidebar_experiment', label);
+ experimentTracking = new ExperimentTracking('sidebar_experiment', { label, property });
};
beforeEach(() => {
@@ -22,6 +23,7 @@ afterEach(() => {
window.gon = oldGon;
Tracking.mockClear();
label = undefined;
+ property = undefined;
});
describe('event', () => {
@@ -32,7 +34,8 @@ describe('event', () => {
});
describe('when providing options', () => {
- label = { label: 'sidebar-drawer' };
+ label = 'sidebar-drawer';
+ property = 'dark-mode';
it('passes them to the tracking call', () => {
experimentTracking.event('click_sidebar_close');
@@ -40,6 +43,7 @@ describe('event', () => {
expect(Tracking.event).toHaveBeenCalledTimes(1);
expect(Tracking.event).toHaveBeenCalledWith('issues-page', 'click_sidebar_close', {
label: 'sidebar-drawer',
+ property: 'dark-mode',
context: {
schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0',
data: 'experiment-data',
@@ -53,7 +57,6 @@ describe('event', () => {
expect(Tracking.event).toHaveBeenCalledTimes(1);
expect(Tracking.event).toHaveBeenCalledWith('issues-page', 'click_sidebar_trigger', {
- label: undefined,
context: {
schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0',
data: 'experiment-data',
diff --git a/spec/frontend/pipelines/graph_shared/links_layer_spec.js b/spec/frontend/pipelines/graph_shared/links_layer_spec.js
index 0ff8583fbff..43d8fe28893 100644
--- a/spec/frontend/pipelines/graph_shared/links_layer_spec.js
+++ b/spec/frontend/pipelines/graph_shared/links_layer_spec.js
@@ -79,6 +79,24 @@ describe('links layer component', () => {
});
});
+ describe('with width or height measurement at 0', () => {
+ beforeEach(() => {
+ createComponent({ props: { containerMeasurements: { width: 0, height: 100 } } });
+ });
+
+ it('renders the default slot', () => {
+ expect(wrapper.html()).toContain(slotContent);
+ });
+
+ it('does not render the alert component', () => {
+ expect(findAlert().exists()).toBe(false);
+ });
+
+ it('does not render the inner links component', () => {
+ expect(findLinksInner().exists()).toBe(false);
+ });
+ });
+
describe('interactions', () => {
beforeEach(() => {
createComponent({ mountFn: mount, props: { pipelineData: tooManyStages } });
diff --git a/spec/frontend/projects/upload_file_experiment_spec.js b/spec/frontend/projects/upload_file_experiment_spec.js
index 57abce779a5..8cad49425f4 100644
--- a/spec/frontend/projects/upload_file_experiment_spec.js
+++ b/spec/frontend/projects/upload_file_experiment_spec.js
@@ -8,7 +8,7 @@ jest.mock('~/experiment_tracking', () =>
})),
);
-const fixture = `<a class='js-upload-file-experiment-trigger' data-toggle='modal' data-target='#modal-upload-blob'></a><div id='modal-upload-blob'></div>`;
+const fixture = `<a class='js-upload-file-experiment-trigger' data-toggle='modal' data-target='#modal-upload-blob'></a><div id='modal-upload-blob'></div><div class='project-home-panel empty-project'></div>`;
const findModal = () => document.querySelector('[aria-modal="true"]');
const findTrigger = () => document.querySelector('.js-upload-file-experiment-trigger');
@@ -29,9 +29,21 @@ describe('trackUploadFileFormSubmitted', () => {
expect(ExperimentTracking).toHaveBeenCalledWith('empty_repo_upload', {
label: 'blob-upload-modal',
+ property: 'empty',
});
expect(mockExperimentTrackingEvent).toHaveBeenCalledWith('click_upload_modal_form_submit');
});
+
+ it('initializes ExperimentTracking with the correct arguments when the project is not empty', () => {
+ document.querySelector('.empty-project').remove();
+
+ UploadFileExperiment.trackUploadFileFormSubmitted();
+
+ expect(ExperimentTracking).toHaveBeenCalledWith('empty_repo_upload', {
+ label: 'blob-upload-modal',
+ property: 'nonempty',
+ });
+ });
});
describe('initUploadFileTrigger', () => {
diff --git a/spec/lib/expand_variables_spec.rb b/spec/lib/expand_variables_spec.rb
index b603325cdb8..407187ea05f 100644
--- a/spec/lib/expand_variables_spec.rb
+++ b/spec/lib/expand_variables_spec.rb
@@ -82,6 +82,13 @@ RSpec.describe ExpandVariables do
value: 'key$variable',
result: 'keyvalue',
variables: -> { [{ key: 'variable', value: 'value' }] }
+ },
+ "simple expansion using Collection": {
+ value: 'key$variable',
+ result: 'keyvalue',
+ variables: Gitlab::Ci::Variables::Collection.new([
+ { key: 'variable', value: 'value' }
+ ])
}
}
end
diff --git a/spec/lib/gitlab/ci/build/context/build_spec.rb b/spec/lib/gitlab/ci/build/context/build_spec.rb
index 61ca8e759b5..46447231424 100644
--- a/spec/lib/gitlab/ci/build/context/build_spec.rb
+++ b/spec/lib/gitlab/ci/build/context/build_spec.rb
@@ -9,7 +9,9 @@ RSpec.describe Gitlab::Ci::Build::Context::Build do
let(:context) { described_class.new(pipeline, seed_attributes) }
describe '#variables' do
- subject { context.variables }
+ subject { context.variables.to_hash }
+
+ it { expect(context.variables).to be_instance_of(Gitlab::Ci::Variables::Collection) }
it { is_expected.to include('CI_COMMIT_REF_NAME' => 'master') }
it { is_expected.to include('CI_PIPELINE_IID' => pipeline.iid.to_s) }
diff --git a/spec/lib/gitlab/ci/build/context/global_spec.rb b/spec/lib/gitlab/ci/build/context/global_spec.rb
index 7394708f9b6..61f2b90426d 100644
--- a/spec/lib/gitlab/ci/build/context/global_spec.rb
+++ b/spec/lib/gitlab/ci/build/context/global_spec.rb
@@ -9,7 +9,9 @@ RSpec.describe Gitlab::Ci::Build::Context::Global do
let(:context) { described_class.new(pipeline, yaml_variables: yaml_variables) }
describe '#variables' do
- subject { context.variables }
+ subject { context.variables.to_hash }
+
+ it { expect(context.variables).to be_instance_of(Gitlab::Ci::Variables::Collection) }
it { is_expected.to include('CI_COMMIT_REF_NAME' => 'master') }
it { is_expected.to include('CI_PIPELINE_IID' => pipeline.iid.to_s) }
diff --git a/spec/lib/gitlab/ci/build/policy/variables_spec.rb b/spec/lib/gitlab/ci/build/policy/variables_spec.rb
index f692aa6146e..6c8c968dc0c 100644
--- a/spec/lib/gitlab/ci/build/policy/variables_spec.rb
+++ b/spec/lib/gitlab/ci/build/policy/variables_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe Gitlab::Ci::Build::Policy::Variables do
let(:seed) do
double('build seed',
to_resource: ci_build,
- variables: ci_build.scoped_variables_hash
+ variables: ci_build.scoped_variables
)
end
@@ -91,7 +91,7 @@ RSpec.describe Gitlab::Ci::Build::Policy::Variables do
let(:seed) do
double('bridge seed',
to_resource: bridge,
- variables: ci_build.scoped_variables_hash
+ variables: ci_build.scoped_variables
)
end
diff --git a/spec/lib/gitlab/ci/build/rules/rule_spec.rb b/spec/lib/gitlab/ci/build/rules/rule_spec.rb
index 5694cd5d0a0..6f3c9278677 100644
--- a/spec/lib/gitlab/ci/build/rules/rule_spec.rb
+++ b/spec/lib/gitlab/ci/build/rules/rule_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe Gitlab::Ci::Build::Rules::Rule do
let(:seed) do
double('build seed',
to_resource: ci_build,
- variables: ci_build.scoped_variables_hash
+ variables: ci_build.scoped_variables
)
end
diff --git a/spec/lib/gitlab/ci/build/rules_spec.rb b/spec/lib/gitlab/ci/build/rules_spec.rb
index 0b50def05d4..1d5bdf30278 100644
--- a/spec/lib/gitlab/ci/build/rules_spec.rb
+++ b/spec/lib/gitlab/ci/build/rules_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Gitlab::Ci::Build::Rules do
let(:seed) do
double('build seed',
to_resource: ci_build,
- variables: ci_build.scoped_variables_hash
+ variables: ci_build.scoped_variables
)
end
diff --git a/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb b/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
index cf3644c9ad5..ec7eebdc056 100644
--- a/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
+++ b/spec/lib/gitlab/ci/pipeline/expression/statement_spec.rb
@@ -3,17 +3,16 @@
require 'spec_helper'
RSpec.describe Gitlab::Ci::Pipeline::Expression::Statement do
- subject do
- described_class.new(text, variables)
+ let(:variables) do
+ Gitlab::Ci::Variables::Collection.new
+ .append(key: 'PRESENT_VARIABLE', value: 'my variable')
+ .append(key: 'PATH_VARIABLE', value: 'a/path/variable/value')
+ .append(key: 'FULL_PATH_VARIABLE', value: '/a/full/path/variable/value')
+ .append(key: 'EMPTY_VARIABLE', value: '')
end
- let(:variables) do
- {
- 'PRESENT_VARIABLE' => 'my variable',
- 'PATH_VARIABLE' => 'a/path/variable/value',
- 'FULL_PATH_VARIABLE' => '/a/full/path/variable/value',
- 'EMPTY_VARIABLE' => ''
- }
+ subject do
+ described_class.new(text, variables)
end
describe '.new' do
diff --git a/spec/lib/gitlab/ci/variables/collection_spec.rb b/spec/lib/gitlab/ci/variables/collection_spec.rb
index 7a275b69fd8..16ba3c32fc4 100644
--- a/spec/lib/gitlab/ci/variables/collection_spec.rb
+++ b/spec/lib/gitlab/ci/variables/collection_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection do
end
it 'can be initialized without an argument' do
- expect(subject).to be_none
+ is_expected.to be_none
end
end
@@ -21,13 +21,13 @@ RSpec.describe Gitlab::Ci::Variables::Collection do
it 'appends a hash' do
subject.append(key: 'VARIABLE', value: 'something')
- expect(subject).to be_one
+ is_expected.to be_one
end
it 'appends a Ci::Variable' do
subject.append(build(:ci_variable))
- expect(subject).to be_one
+ is_expected.to be_one
end
it 'appends an internal resource' do
@@ -35,7 +35,7 @@ RSpec.describe Gitlab::Ci::Variables::Collection do
subject.append(collection.first)
- expect(subject).to be_one
+ is_expected.to be_one
end
it 'returns self' do
@@ -210,4 +210,24 @@ RSpec.describe Gitlab::Ci::Variables::Collection do
end
end
end
+
+ describe '#reject' do
+ let(:collection) do
+ described_class.new
+ .append(key: 'CI_JOB_NAME', value: 'test-1')
+ .append(key: 'CI_BUILD_ID', value: '1')
+ .append(key: 'TEST1', value: 'test-3')
+ end
+
+ subject { collection.reject { |var| var[:key] =~ /\ACI_(JOB|BUILD)/ } }
+
+ it 'returns a Collection instance' do
+ is_expected.to be_an_instance_of(described_class)
+ end
+
+ it 'returns correctly filtered Collection' do
+ comp = collection.to_runner_variables.reject { |var| var[:key] =~ /\ACI_(JOB|BUILD)/ }
+ expect(subject.to_runner_variables).to eq(comp)
+ end
+ end
end
diff --git a/spec/lib/gitlab/hook_data/project_member_builder_spec.rb b/spec/lib/gitlab/hook_data/project_member_builder_spec.rb
new file mode 100644
index 00000000000..3fb84223581
--- /dev/null
+++ b/spec/lib/gitlab/hook_data/project_member_builder_spec.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::HookData::ProjectMemberBuilder do
+ let_it_be(:project) { create(:project, :internal, name: 'gitlab') }
+ let_it_be(:user) { create(:user, name: 'John Doe', username: 'johndoe', email: 'john@example.com') }
+ let_it_be(:project_member) { create(:project_member, :developer, user: user, project: project) }
+
+ describe '#build' do
+ let(:data) { described_class.new(project_member).build(event) }
+ let(:event_name) { data[:event_name] }
+ let(:attributes) do
+ [
+ :event_name, :created_at, :updated_at, :project_name, :project_path, :project_path_with_namespace, :project_id, :user_username, :user_name, :user_email, :user_id, :access_level, :project_visibility
+ ]
+ end
+
+ context 'data' do
+ shared_examples_for 'includes the required attributes' do
+ it 'includes the required attributes' do
+ expect(data).to include(*attributes)
+ expect(data[:project_name]).to eq('gitlab')
+ expect(data[:project_path]).to eq(project.path)
+ expect(data[:project_path_with_namespace]).to eq(project.full_path)
+ expect(data[:project_id]).to eq(project.id)
+ expect(data[:user_username]).to eq('johndoe')
+ expect(data[:user_name]).to eq('John Doe')
+ expect(data[:user_id]).to eq(user.id)
+ expect(data[:user_email]).to eq('john@example.com')
+ expect(data[:access_level]).to eq('Developer')
+ expect(data[:project_visibility]).to eq('internal')
+ end
+ end
+
+ context 'on create' do
+ let(:event) { :create }
+
+ it { expect(event_name).to eq('user_add_to_team') }
+ it_behaves_like 'includes the required attributes'
+ end
+
+ context 'on update' do
+ let(:event) { :update }
+
+ it { expect(event_name).to eq('user_update_for_team') }
+ it_behaves_like 'includes the required attributes'
+ end
+
+ context 'on destroy' do
+ let(:event) { :destroy }
+
+ it { expect(event_name).to eq('user_remove_from_team') }
+ it_behaves_like 'includes the required attributes'
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/word_diff/chunk_collection_spec.rb b/spec/lib/gitlab/word_diff/chunk_collection_spec.rb
new file mode 100644
index 00000000000..aa837f760c1
--- /dev/null
+++ b/spec/lib/gitlab/word_diff/chunk_collection_spec.rb
@@ -0,0 +1,44 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::WordDiff::ChunkCollection do
+ subject(:collection) { described_class.new }
+
+ describe '#add' do
+ it 'adds elements to the chunk collection' do
+ collection.add('Hello')
+ collection.add(' World')
+
+ expect(collection.content).to eq('Hello World')
+ end
+ end
+
+ describe '#content' do
+ subject { collection.content }
+
+ context 'when no elements in the collection' do
+ it { is_expected.to eq('') }
+ end
+
+ context 'when elements exist' do
+ before do
+ collection.add('Hi')
+ collection.add(' GitLab!')
+ end
+
+ it { is_expected.to eq('Hi GitLab!') }
+ end
+ end
+
+ describe '#reset' do
+ it 'clears the collection' do
+ collection.add('1')
+ collection.add('2')
+
+ collection.reset
+
+ expect(collection.content).to eq('')
+ end
+ end
+end
diff --git a/spec/lib/gitlab/word_diff/line_processor_spec.rb b/spec/lib/gitlab/word_diff/line_processor_spec.rb
new file mode 100644
index 00000000000..f448f5b5eb6
--- /dev/null
+++ b/spec/lib/gitlab/word_diff/line_processor_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::WordDiff::LineProcessor do
+ subject(:line_processor) { described_class.new(line) }
+
+ describe '#extract' do
+ subject(:segment) { line_processor.extract }
+
+ context 'when line is a diff hunk' do
+ let(:line) { "@@ -1,14 +1,13 @@\n" }
+
+ it 'returns DiffHunk segment' do
+ expect(segment).to be_a(Gitlab::WordDiff::Segments::DiffHunk)
+ expect(segment.to_s).to eq('@@ -1,14 +1,13 @@')
+ end
+ end
+
+ context 'when line has a newline delimiter' do
+ let(:line) { "~\n" }
+
+ it 'returns Newline segment' do
+ expect(segment).to be_a(Gitlab::WordDiff::Segments::Newline)
+ expect(segment.to_s).to eq('')
+ end
+ end
+
+ context 'when line has only space' do
+ let(:line) { " \n" }
+
+ it 'returns nil' do
+ is_expected.to be_nil
+ end
+ end
+
+ context 'when line has content' do
+ let(:line) { "+New addition\n" }
+
+ it 'returns Chunk segment' do
+ expect(segment).to be_a(Gitlab::WordDiff::Segments::Chunk)
+ expect(segment.to_s).to eq('New addition')
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/word_diff/parser_spec.rb b/spec/lib/gitlab/word_diff/parser_spec.rb
new file mode 100644
index 00000000000..3aeefb57a02
--- /dev/null
+++ b/spec/lib/gitlab/word_diff/parser_spec.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::WordDiff::Parser do
+ subject(:parser) { described_class.new }
+
+ describe '#parse' do
+ subject { parser.parse(diff.lines).to_a }
+
+ let(:diff) do
+ <<~EOF
+ @@ -1,14 +1,13 @@
+ ~
+ Unchanged line
+ ~
+ ~
+ -Old change
+ +New addition
+ unchanged content
+ ~
+ @@ -50,14 +50,13 @@
+ +First change
+ same same same_
+ -removed_
+ +added_
+ end of the line
+ ~
+ ~
+ EOF
+ end
+
+ it 'returns a collection of lines' do
+ diff_lines = subject
+
+ aggregate_failures do
+ expect(diff_lines.count).to eq(7)
+
+ expect(diff_lines.map(&:to_hash)).to match_array(
+ [
+ a_hash_including(index: 0, old_pos: 1, new_pos: 1, text: '', type: nil),
+ a_hash_including(index: 1, old_pos: 2, new_pos: 2, text: 'Unchanged line', type: nil),
+ a_hash_including(index: 2, old_pos: 3, new_pos: 3, text: '', type: nil),
+ a_hash_including(index: 3, old_pos: 4, new_pos: 4, text: 'Old changeNew addition unchanged content', type: nil),
+ a_hash_including(index: 4, old_pos: 50, new_pos: 50, text: '@@ -50,14 +50,13 @@', type: 'match'),
+ a_hash_including(index: 5, old_pos: 50, new_pos: 50, text: 'First change same same same_removed_added_end of the line', type: nil),
+ a_hash_including(index: 6, old_pos: 51, new_pos: 51, text: '', type: nil)
+ ]
+ )
+ end
+ end
+
+ it 'restarts object index after several calls to Enumerator' do
+ enumerator = parser.parse(diff.lines)
+
+ 2.times do
+ expect(enumerator.first.index).to eq(0)
+ end
+ end
+
+ context 'when diff is empty' do
+ let(:diff) { '' }
+
+ it { is_expected.to eq([]) }
+ end
+ end
+end
diff --git a/spec/lib/gitlab/word_diff/positions_counter_spec.rb b/spec/lib/gitlab/word_diff/positions_counter_spec.rb
new file mode 100644
index 00000000000..e2c246f6801
--- /dev/null
+++ b/spec/lib/gitlab/word_diff/positions_counter_spec.rb
@@ -0,0 +1,35 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::WordDiff::PositionsCounter do
+ subject(:counter) { described_class.new }
+
+ describe 'Initial state' do
+ it 'starts with predefined values' do
+ expect(counter.pos_old).to eq(1)
+ expect(counter.pos_new).to eq(1)
+ expect(counter.line_obj_index).to eq(0)
+ end
+ end
+
+ describe '#increase_pos_num' do
+ it 'increases old and new positions' do
+ expect { counter.increase_pos_num }.to change { counter.pos_old }.from(1).to(2)
+ .and change { counter.pos_new }.from(1).to(2)
+ end
+ end
+
+ describe '#increase_obj_index' do
+ it 'increases object index' do
+ expect { counter.increase_obj_index }.to change { counter.line_obj_index }.from(0).to(1)
+ end
+ end
+
+ describe '#set_pos_num' do
+ it 'sets old and new positions' do
+ expect { counter.set_pos_num(old: 10, new: 12) }.to change { counter.pos_old }.from(1).to(10)
+ .and change { counter.pos_new }.from(1).to(12)
+ end
+ end
+end
diff --git a/spec/lib/gitlab/word_diff/segments/chunk_spec.rb b/spec/lib/gitlab/word_diff/segments/chunk_spec.rb
new file mode 100644
index 00000000000..797cc42a03c
--- /dev/null
+++ b/spec/lib/gitlab/word_diff/segments/chunk_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::WordDiff::Segments::Chunk do
+ subject(:chunk) { described_class.new(line) }
+
+ let(:line) { ' Hello' }
+
+ describe '#removed?' do
+ subject { chunk.removed? }
+
+ it { is_expected.to be_falsey }
+
+ context 'when line starts with "-"' do
+ let(:line) { '-Removed' }
+
+ it { is_expected.to be_truthy }
+ end
+ end
+
+ describe '#added?' do
+ subject { chunk.added? }
+
+ it { is_expected.to be_falsey }
+
+ context 'when line starts with "+"' do
+ let(:line) { '+Added' }
+
+ it { is_expected.to be_truthy }
+ end
+ end
+
+ describe '#to_s' do
+ subject { chunk.to_s }
+
+ it 'removes lead string modifier' do
+ is_expected.to eq('Hello')
+ end
+
+ context 'when chunk is empty' do
+ let(:line) { '' }
+
+ it { is_expected.to eq('') }
+ end
+ end
+
+ describe '#length' do
+ subject { chunk.length }
+
+ it { is_expected.to eq('Hello'.length) }
+ end
+end
diff --git a/spec/lib/gitlab/word_diff/segments/diff_hunk_spec.rb b/spec/lib/gitlab/word_diff/segments/diff_hunk_spec.rb
new file mode 100644
index 00000000000..5250e6d73c2
--- /dev/null
+++ b/spec/lib/gitlab/word_diff/segments/diff_hunk_spec.rb
@@ -0,0 +1,51 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::WordDiff::Segments::DiffHunk do
+ subject(:diff_hunk) { described_class.new(line) }
+
+ let(:line) { '@@ -3,14 +4,13 @@' }
+
+ describe '#pos_old' do
+ subject { diff_hunk.pos_old }
+
+ it { is_expected.to eq 3 }
+
+ context 'when diff hunk is broken' do
+ let(:line) { '@@ ??? @@' }
+
+ it { is_expected.to eq 0 }
+ end
+ end
+
+ describe '#pos_new' do
+ subject { diff_hunk.pos_new }
+
+ it { is_expected.to eq 4 }
+
+ context 'when diff hunk is broken' do
+ let(:line) { '@@ ??? @@' }
+
+ it { is_expected.to eq 0 }
+ end
+ end
+
+ describe '#first_line?' do
+ subject { diff_hunk.first_line? }
+
+ it { is_expected.to be_falsey }
+
+ context 'when diff hunk located on the first line' do
+ let(:line) { '@@ -1,14 +1,13 @@' }
+
+ it { is_expected.to be_truthy }
+ end
+ end
+
+ describe '#to_s' do
+ subject { diff_hunk.to_s }
+
+ it { is_expected.to eq(line) }
+ end
+end
diff --git a/spec/lib/gitlab/word_diff/segments/newline_spec.rb b/spec/lib/gitlab/word_diff/segments/newline_spec.rb
new file mode 100644
index 00000000000..ed5054844f1
--- /dev/null
+++ b/spec/lib/gitlab/word_diff/segments/newline_spec.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::WordDiff::Segments::Newline do
+ subject(:newline) { described_class.new }
+
+ describe '#to_s' do
+ subject { newline.to_s }
+
+ it { is_expected.to eq '' }
+ end
+end
diff --git a/spec/models/ci/bridge_spec.rb b/spec/models/ci/bridge_spec.rb
index b50e4204e0a..f3029598b02 100644
--- a/spec/models/ci/bridge_spec.rb
+++ b/spec/models/ci/bridge_spec.rb
@@ -41,7 +41,7 @@ RSpec.describe Ci::Bridge do
end
end
- describe '#scoped_variables_hash' do
+ describe '#scoped_variables' do
it 'returns a hash representing variables' do
variables = %w[
CI_JOB_NAME CI_JOB_STAGE CI_COMMIT_SHA CI_COMMIT_SHORT_SHA
@@ -53,7 +53,7 @@ RSpec.describe Ci::Bridge do
CI_COMMIT_TIMESTAMP
]
- expect(bridge.scoped_variables_hash.keys).to include(*variables)
+ expect(bridge.scoped_variables.map { |v| v[:key] }).to include(*variables)
end
context 'when bridge has dependency which has dotenv variable' do
@@ -63,7 +63,7 @@ RSpec.describe Ci::Bridge do
let!(:job_variable) { create(:ci_job_variable, :dotenv_source, job: test) }
it 'includes inherited variable' do
- expect(bridge.scoped_variables_hash).to include(job_variable.key => job_variable.value)
+ expect(bridge.scoped_variables.to_hash).to include(job_variable.key => job_variable.value)
end
end
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index dd816101f0c..945446ea816 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -2440,7 +2440,8 @@ RSpec.describe Ci::Build do
build.yaml_variables = []
end
- it { is_expected.to eq(predefined_variables) }
+ it { is_expected.to be_instance_of(Gitlab::Ci::Variables::Collection) }
+ it { expect(subject.to_runner_variables).to eq(predefined_variables) }
context 'when ci_job_jwt feature flag is disabled' do
before do
@@ -2495,7 +2496,7 @@ RSpec.describe Ci::Build do
end
it 'returns variables in order depending on resource hierarchy' do
- is_expected.to eq(
+ expect(subject.to_runner_variables).to eq(
[dependency_proxy_var,
job_jwt_var,
build_pre_var,
@@ -2525,7 +2526,7 @@ RSpec.describe Ci::Build do
end
it 'matches explicit variables ordering' do
- received_variables = subject.map { |variable| variable.fetch(:key) }
+ received_variables = subject.map { |variable| variable[:key] }
expect(received_variables).to eq expected_variables
end
@@ -2618,7 +2619,7 @@ RSpec.describe Ci::Build do
it_behaves_like 'containing environment variables'
it 'puts $CI_ENVIRONMENT_URL in the last so all other variables are available to be used when runners are trying to expand it' do
- expect(subject.last).to eq(environment_variables.last)
+ expect(subject.to_runner_variables.last).to eq(environment_variables.last)
end
end
end
@@ -2951,7 +2952,7 @@ RSpec.describe Ci::Build do
end
it 'overrides YAML variable using a pipeline variable' do
- variables = subject.reverse.uniq { |variable| variable[:key] }.reverse
+ variables = subject.to_runner_variables.reverse.uniq { |variable| variable[:key] }.reverse
expect(variables)
.not_to include(key: 'MYVAR', value: 'myvar', public: true, masked: false)
@@ -3248,47 +3249,6 @@ RSpec.describe Ci::Build do
end
end
- describe '#scoped_variables_hash' do
- context 'when overriding CI variables' do
- before do
- project.variables.create!(key: 'MY_VAR', value: 'my value 1')
- pipeline.variables.create!(key: 'MY_VAR', value: 'my value 2')
- end
-
- it 'returns a regular hash created using valid ordering' do
- expect(build.scoped_variables_hash).to include('MY_VAR': 'my value 2')
- expect(build.scoped_variables_hash).not_to include('MY_VAR': 'my value 1')
- end
- end
-
- context 'when overriding user-provided variables' do
- let(:build) do
- create(:ci_build, pipeline: pipeline, yaml_variables: [{ key: 'MY_VAR', value: 'myvar', public: true }])
- end
-
- before do
- pipeline.variables.build(key: 'MY_VAR', value: 'pipeline value')
- end
-
- it 'returns a hash including variable with higher precedence' do
- expect(build.scoped_variables_hash).to include('MY_VAR': 'pipeline value')
- expect(build.scoped_variables_hash).not_to include('MY_VAR': 'myvar')
- end
- end
-
- context 'when overriding CI instance variables' do
- before do
- create(:ci_instance_variable, key: 'MY_VAR', value: 'my value 1')
- group.variables.create!(key: 'MY_VAR', value: 'my value 2')
- end
-
- it 'returns a regular hash created using valid ordering' do
- expect(build.scoped_variables_hash).to include('MY_VAR': 'my value 2')
- expect(build.scoped_variables_hash).not_to include('MY_VAR': 'my value 1')
- end
- end
- end
-
describe '#any_unmet_prerequisites?' do
let(:build) { create(:ci_build, :created) }
diff --git a/spec/presenters/ci/build_runner_presenter_spec.rb b/spec/presenters/ci/build_runner_presenter_spec.rb
index 43b677483ce..1eecc9d1ce6 100644
--- a/spec/presenters/ci/build_runner_presenter_spec.rb
+++ b/spec/presenters/ci/build_runner_presenter_spec.rb
@@ -271,4 +271,28 @@ RSpec.describe Ci::BuildRunnerPresenter do
end
end
end
+
+ describe '#variables' do
+ subject { presenter.variables }
+
+ let(:build) { create(:ci_build) }
+
+ it 'returns a Collection' do
+ is_expected.to be_an_instance_of(Gitlab::Ci::Variables::Collection)
+ end
+ end
+
+ describe '#runner_variables' do
+ subject { presenter.runner_variables }
+
+ let(:build) { create(:ci_build) }
+
+ it 'returns an array' do
+ is_expected.to be_an_instance_of(Array)
+ end
+
+ it 'returns the expected variables' do
+ is_expected.to eq(presenter.variables.to_runner_variables)
+ end
+ end
end
diff --git a/spec/rubocop/cop/graphql/authorize_types_spec.rb b/spec/rubocop/cop/graphql/authorize_types_spec.rb
index 9242b865b20..cd376bf458c 100644
--- a/spec/rubocop/cop/graphql/authorize_types_spec.rb
+++ b/spec/rubocop/cop/graphql/authorize_types_spec.rb
@@ -63,4 +63,34 @@ RSpec.describe RuboCop::Cop::Graphql::AuthorizeTypes do
end
TYPE
end
+
+ it 'does not add an offense for subtypes of BaseUnion' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class AType < BaseUnion
+ possible_types Types::Foo, Types::Bar
+ end
+ end
+ TYPE
+ end
+
+ it 'does not add an offense for subtypes of BaseInputObject' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class AType < BaseInputObject
+ argument :a_thing
+ end
+ end
+ TYPE
+ end
+
+ it 'does not add an offense for InputTypes' do
+ expect_no_offenses(<<~TYPE)
+ module Types
+ class AInputType < SomeObjectType
+ argument :a_thing
+ end
+ end
+ TYPE
+ end
end
diff --git a/spec/services/ci/create_pipeline_service/rules_spec.rb b/spec/services/ci/create_pipeline_service/rules_spec.rb
index 8025443d4ae..e97e74c1515 100644
--- a/spec/services/ci/create_pipeline_service/rules_spec.rb
+++ b/spec/services/ci/create_pipeline_service/rules_spec.rb
@@ -174,7 +174,7 @@ RSpec.describe Ci::CreatePipelineService do
let(:ref) { 'refs/heads/master' }
it 'overrides VAR1' do
- variables = job.scoped_variables_hash
+ variables = job.scoped_variables.to_hash
expect(variables['VAR1']).to eq('overridden var 1')
expect(variables['VAR2']).to eq('my var 2')
@@ -186,7 +186,7 @@ RSpec.describe Ci::CreatePipelineService do
let(:ref) { 'refs/heads/feature' }
it 'overrides VAR2 and adds VAR3' do
- variables = job.scoped_variables_hash
+ variables = job.scoped_variables.to_hash
expect(variables['VAR1']).to eq('my var 1')
expect(variables['VAR2']).to eq('overridden var 2')
@@ -198,7 +198,7 @@ RSpec.describe Ci::CreatePipelineService do
let(:ref) { 'refs/heads/wip' }
it 'does not affect vars' do
- variables = job.scoped_variables_hash
+ variables = job.scoped_variables.to_hash
expect(variables['VAR1']).to eq('my var 1')
expect(variables['VAR2']).to eq('my var 2')
diff --git a/spec/services/system_hooks_service_spec.rb b/spec/services/system_hooks_service_spec.rb
index 1ec5237370f..446325e5f71 100644
--- a/spec/services/system_hooks_service_spec.rb
+++ b/spec/services/system_hooks_service_spec.rb
@@ -149,9 +149,6 @@ RSpec.describe SystemHooksService do
it { expect(event_name(project, :rename)).to eq "project_rename" }
it { expect(event_name(project, :transfer)).to eq "project_transfer" }
it { expect(event_name(project, :update)).to eq "project_update" }
- it { expect(event_name(project_member, :create)).to eq "user_add_to_team" }
- it { expect(event_name(project_member, :destroy)).to eq "user_remove_from_team" }
- it { expect(event_name(project_member, :update)).to eq "user_update_for_team" }
it { expect(event_name(key, :create)).to eq 'key_create' }
it { expect(event_name(key, :destroy)).to eq 'key_destroy' }
end