summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-11 12:06:23 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-11 12:06:23 +0000
commit16bd8409bcb61d2331227d1df539c40683b6bda3 (patch)
tree6d9ede1b4d8f4c9e743758a6f4d7b78a684a6da9 /spec
parent4a45f0eff2a25c64bdd83926e35a8894a4f0469f (diff)
downloadgitlab-ce-16bd8409bcb61d2331227d1df539c40683b6bda3.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/javascripts/vue_shared/components/icon_spec.js13
-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/config/entry/rules/rule_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/config/entry/rules_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/status/composite_spec.rb2
-rw-r--r--spec/lib/gitlab/ci/trace/stream_spec.rb10
-rw-r--r--spec/support/shared_examples/cycle_analytics_event_shared_examples.rb3
-rw-r--r--spec/support/shared_examples/cycle_analytics_stage_shared_examples.rb137
9 files changed, 160 insertions, 13 deletions
diff --git a/spec/javascripts/vue_shared/components/icon_spec.js b/spec/javascripts/vue_shared/components/icon_spec.js
index 7390798afa8..ecaef414464 100644
--- a/spec/javascripts/vue_shared/components/icon_spec.js
+++ b/spec/javascripts/vue_shared/components/icon_spec.js
@@ -1,6 +1,7 @@
import Vue from 'vue';
import Icon from '~/vue_shared/components/icon.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
+import { mount } from '@vue/test-utils';
describe('Sprite Icon Component', function() {
describe('Initialization', function() {
@@ -57,4 +58,16 @@ describe('Sprite Icon Component', function() {
expect(Icon.props.name.validator('commit')).toBe(true);
});
});
+
+ it('should call registered listeners when they are triggered', () => {
+ const clickHandler = jasmine.createSpy('clickHandler');
+ const wrapper = mount(Icon, {
+ propsData: { name: 'commit' },
+ listeners: { click: clickHandler },
+ });
+
+ wrapper.find('svg').trigger('click');
+
+ expect(clickHandler).toHaveBeenCalled();
+ });
});
diff --git a/spec/lib/gitlab/ci/build/rules/rule_spec.rb b/spec/lib/gitlab/ci/build/rules/rule_spec.rb
index 99852bd4228..e0f341461fb 100644
--- a/spec/lib/gitlab/ci/build/rules/rule_spec.rb
+++ b/spec/lib/gitlab/ci/build/rules/rule_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Gitlab::Ci::Build::Rules::Rule do
diff --git a/spec/lib/gitlab/ci/build/rules_spec.rb b/spec/lib/gitlab/ci/build/rules_spec.rb
index d7793ebc806..b783bbb8287 100644
--- a/spec/lib/gitlab/ci/build/rules_spec.rb
+++ b/spec/lib/gitlab/ci/build/rules_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Gitlab::Ci::Build::Rules do
diff --git a/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb b/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb
index 9d4f7153cd0..1f54f6ec537 100644
--- a/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/rules/rule_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'fast_spec_helper'
require 'gitlab_chronic_duration'
require 'support/helpers/stub_feature_flags'
diff --git a/spec/lib/gitlab/ci/config/entry/rules_spec.rb b/spec/lib/gitlab/ci/config/entry/rules_spec.rb
index 291e7373daf..926d3fd1678 100644
--- a/spec/lib/gitlab/ci/config/entry/rules_spec.rb
+++ b/spec/lib/gitlab/ci/config/entry/rules_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'fast_spec_helper'
require 'support/helpers/stub_feature_flags'
require_dependency 'active_model'
diff --git a/spec/lib/gitlab/ci/status/composite_spec.rb b/spec/lib/gitlab/ci/status/composite_spec.rb
index 1725d954b92..857483a9e0a 100644
--- a/spec/lib/gitlab/ci/status/composite_spec.rb
+++ b/spec/lib/gitlab/ci/status/composite_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Gitlab::Ci::Status::Composite do
diff --git a/spec/lib/gitlab/ci/trace/stream_spec.rb b/spec/lib/gitlab/ci/trace/stream_spec.rb
index 1baea13299b..45b59541ce6 100644
--- a/spec/lib/gitlab/ci/trace/stream_spec.rb
+++ b/spec/lib/gitlab/ci/trace/stream_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require 'spec_helper'
describe Gitlab::Ci::Trace::Stream, :clean_gitlab_redis_cache do
@@ -100,7 +102,7 @@ describe Gitlab::Ci::Trace::Stream, :clean_gitlab_redis_cache do
describe '#append' do
shared_examples_for 'appends' do
it "truncates and append content" do
- stream.append("89", 4)
+ stream.append(+"89", 4)
stream.seek(0)
expect(stream.size).to eq(6)
@@ -108,7 +110,7 @@ describe Gitlab::Ci::Trace::Stream, :clean_gitlab_redis_cache do
end
it 'appends in binary mode' do
- '😺'.force_encoding('ASCII-8BIT').each_char.with_index do |byte, offset|
+ (+'😺').force_encoding('ASCII-8BIT').each_char.with_index do |byte, offset|
stream.append(byte, offset)
end
@@ -154,7 +156,7 @@ describe Gitlab::Ci::Trace::Stream, :clean_gitlab_redis_cache do
describe '#set' do
shared_examples_for 'sets' do
before do
- stream.set("8901")
+ stream.set(+"8901")
end
it "overwrite content" do
@@ -168,7 +170,7 @@ describe Gitlab::Ci::Trace::Stream, :clean_gitlab_redis_cache do
context 'when stream is StringIO' do
let(:stream) do
described_class.new do
- StringIO.new("12345678")
+ StringIO.new(+"12345678")
end
end
diff --git a/spec/support/shared_examples/cycle_analytics_event_shared_examples.rb b/spec/support/shared_examples/cycle_analytics_event_shared_examples.rb
index dce1dbe1cd1..028b8da94a6 100644
--- a/spec/support/shared_examples/cycle_analytics_event_shared_examples.rb
+++ b/spec/support/shared_examples/cycle_analytics_event_shared_examples.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true
shared_examples_for 'cycle analytics event' do
- let(:instance) { described_class.new({}) }
+ let(:params) { {} }
+ let(:instance) { described_class.new(params) }
it { expect(described_class.name).to be_a_kind_of(String) }
it { expect(described_class.identifier).to be_a_kind_of(Symbol) }
diff --git a/spec/support/shared_examples/cycle_analytics_stage_shared_examples.rb b/spec/support/shared_examples/cycle_analytics_stage_shared_examples.rb
index afa035d039a..c781f72ff11 100644
--- a/spec/support/shared_examples/cycle_analytics_stage_shared_examples.rb
+++ b/spec/support/shared_examples/cycle_analytics_stage_shared_examples.rb
@@ -10,6 +10,11 @@ shared_examples_for 'cycle analytics stage' do
}
end
+ describe 'associations' do
+ it { is_expected.to belong_to(:end_event_label) }
+ it { is_expected.to belong_to(:start_event_label) }
+ end
+
describe 'validation' do
it 'is valid' do
expect(described_class.new(valid_params)).to be_valid
@@ -18,22 +23,22 @@ shared_examples_for 'cycle analytics stage' do
it 'validates presence of parent' do
stage = described_class.new(valid_params.except(:parent))
- expect(stage).not_to be_valid
- expect(stage.errors.details[parent_name]).to eq([{ error: :blank }])
+ expect(stage).to be_invalid
+ expect(stage.errors[parent_name]).to include("can't be blank")
end
it 'validates presence of start_event_identifier' do
stage = described_class.new(valid_params.except(:start_event_identifier))
- expect(stage).not_to be_valid
- expect(stage.errors.details[:start_event_identifier]).to eq([{ error: :blank }])
+ expect(stage).to be_invalid
+ expect(stage.errors[:start_event_identifier]).to include("can't be blank")
end
it 'validates presence of end_event_identifier' do
stage = described_class.new(valid_params.except(:end_event_identifier))
- expect(stage).not_to be_valid
- expect(stage.errors.details[:end_event_identifier]).to eq([{ error: :blank }])
+ expect(stage).to be_invalid
+ expect(stage.errors[:end_event_identifier]).to include("can't be blank")
end
it 'is invalid when end_event is not allowed for the given start_event' do
@@ -43,8 +48,8 @@ shared_examples_for 'cycle analytics stage' do
)
stage = described_class.new(invalid_params)
- expect(stage).not_to be_valid
- expect(stage.errors.details[:end_event]).to eq([{ error: :not_allowed_for_the_given_start_event }])
+ expect(stage).to be_invalid
+ expect(stage.errors[:end_event]).to include(s_('CycleAnalytics|not allowed for the given start event'))
end
context 'disallows default stage names when creating custom stage' do
@@ -105,3 +110,119 @@ shared_examples_for 'cycle analytics stage' do
end
end
end
+
+shared_examples_for 'cycle analytics label based stage' do
+ context 'when creating label based event' do
+ context 'when the label id is not passed' do
+ it 'returns validation error when `start_event_label_id` is missing' do
+ stage = described_class.new({
+ name: 'My Stage',
+ parent: parent,
+ start_event_identifier: :issue_label_added,
+ end_event_identifier: :issue_closed
+ })
+
+ expect(stage).to be_invalid
+ expect(stage.errors[:start_event_label]).to include("can't be blank")
+ end
+
+ it 'returns validation error when `end_event_label_id` is missing' do
+ stage = described_class.new({
+ name: 'My Stage',
+ parent: parent,
+ start_event_identifier: :issue_closed,
+ end_event_identifier: :issue_label_added
+ })
+
+ expect(stage).to be_invalid
+ expect(stage.errors[:end_event_label]).to include("can't be blank")
+ end
+ end
+
+ context 'when group label is defined on the root group' do
+ it 'succeeds' do
+ stage = described_class.new({
+ name: 'My Stage',
+ parent: parent,
+ start_event_identifier: :issue_label_added,
+ start_event_label: group_label,
+ end_event_identifier: :issue_closed
+ })
+
+ expect(stage).to be_valid
+ end
+ end
+
+ context 'when subgroup is given' do
+ it 'succeeds' do
+ stage = described_class.new({
+ name: 'My Stage',
+ parent: parent_in_subgroup,
+ start_event_identifier: :issue_label_added,
+ start_event_label: group_label,
+ end_event_identifier: :issue_closed
+ })
+
+ expect(stage).to be_valid
+ end
+ end
+
+ context 'when label is defined for a different group' do
+ let(:error_message) { s_('CycleAnalyticsStage|is not available for the selected group') }
+
+ it 'returns validation for `start_event_label`' do
+ stage = described_class.new({
+ name: 'My Stage',
+ parent: parent_outside_of_group_label_scope,
+ start_event_identifier: :issue_label_added,
+ start_event_label: group_label,
+ end_event_identifier: :issue_closed
+ })
+
+ expect(stage).to be_invalid
+ expect(stage.errors[:start_event_label]).to include(error_message)
+ end
+
+ it 'returns validation for `end_event_label`' do
+ stage = described_class.new({
+ name: 'My Stage',
+ parent: parent_outside_of_group_label_scope,
+ start_event_identifier: :issue_closed,
+ end_event_identifier: :issue_label_added,
+ end_event_label: group_label
+ })
+
+ expect(stage).to be_invalid
+ expect(stage.errors[:end_event_label]).to include(error_message)
+ end
+ end
+
+ context 'when `ProjectLabel is given' do
+ let_it_be(:label) { create(:label) }
+
+ it 'raises error when `ProjectLabel` is given for `start_event_label`' do
+ params = {
+ name: 'My Stage',
+ parent: parent,
+ start_event_identifier: :issue_label_added,
+ start_event_label: label,
+ end_event_identifier: :issue_closed
+ }
+
+ expect { described_class.new(params) }.to raise_error(ActiveRecord::AssociationTypeMismatch)
+ end
+
+ it 'raises error when `ProjectLabel` is given for `end_event_label`' do
+ params = {
+ name: 'My Stage',
+ parent: parent,
+ start_event_identifier: :issue_closed,
+ end_event_identifier: :issue_label_added,
+ end_event_label: label
+ }
+
+ expect { described_class.new(params) }.to raise_error(ActiveRecord::AssociationTypeMismatch)
+ end
+ end
+ end
+end