diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-14 18:10:34 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-14 18:10:34 +0000 |
commit | 7d4b2ed7bf75d316577b718c71a9fdef19184539 (patch) | |
tree | d709e00c4f2ab60901749883f324f9069343037c /spec/models | |
parent | 7172fb10313a9a7790f8e033b347e77df4987154 (diff) | |
download | gitlab-ce-7d4b2ed7bf75d316577b718c71a9fdef19184539.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/analytics/cycle_analytics/project_stage_spec.rb | 1 | ||||
-rw-r--r-- | spec/models/analytics/cycle_analytics/project_value_stream_spec.rb | 39 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 3 | ||||
-rw-r--r-- | spec/models/user_spec.rb | 17 |
4 files changed, 58 insertions, 2 deletions
diff --git a/spec/models/analytics/cycle_analytics/project_stage_spec.rb b/spec/models/analytics/cycle_analytics/project_stage_spec.rb index fce31af619c..9efe90e7d41 100644 --- a/spec/models/analytics/cycle_analytics/project_stage_spec.rb +++ b/spec/models/analytics/cycle_analytics/project_stage_spec.rb @@ -17,6 +17,7 @@ RSpec.describe Analytics::CycleAnalytics::ProjectStage do end it_behaves_like 'value stream analytics stage' do + let(:factory) { :cycle_analytics_project_stage } let(:parent) { build(:project) } let(:parent_name) { :project } end diff --git a/spec/models/analytics/cycle_analytics/project_value_stream_spec.rb b/spec/models/analytics/cycle_analytics/project_value_stream_spec.rb new file mode 100644 index 00000000000..d84ecedc634 --- /dev/null +++ b/spec/models/analytics/cycle_analytics/project_value_stream_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Analytics::CycleAnalytics::ProjectValueStream, type: :model do + describe 'associations' do + it { is_expected.to belong_to(:project) } + it { is_expected.to have_many(:stages) } + end + + describe 'validations' do + it { is_expected.to validate_presence_of(:project) } + it { is_expected.to validate_presence_of(:name) } + it { is_expected.to validate_length_of(:name).is_at_most(100) } + + it 'validates uniqueness of name' do + project = create(:project) + create(:cycle_analytics_project_value_stream, name: 'test', project: project) + + value_stream = build(:cycle_analytics_project_value_stream, name: 'test', project: project) + + expect(value_stream).to be_invalid + expect(value_stream.errors.messages).to eq(name: [I18n.t('errors.messages.taken')]) + end + end + + it 'is not custom' do + expect(described_class.new).not_to be_custom + end + + describe '.build_default_value_stream' do + it 'builds the default value stream' do + project = build(:project) + + value_stream = described_class.build_default_value_stream(project) + expect(value_stream.name).to eq('default') + end + end +end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index e5ed8d89145..43cea0ddcd1 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -113,7 +113,8 @@ RSpec.describe Project, factory_default: :keep do it { is_expected.to have_many(:lfs_file_locks) } it { is_expected.to have_many(:project_deploy_tokens) } it { is_expected.to have_many(:deploy_tokens).through(:project_deploy_tokens) } - it { is_expected.to have_many(:cycle_analytics_stages) } + it { is_expected.to have_many(:cycle_analytics_stages).inverse_of(:project) } + it { is_expected.to have_many(:value_streams).inverse_of(:project) } it { is_expected.to have_many(:external_pull_requests) } it { is_expected.to have_many(:sourced_pipelines) } it { is_expected.to have_many(:source_pipelines) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 0c35b1265ba..cb34917f073 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -728,6 +728,7 @@ RSpec.describe User do let_it_be(:blocked_user) { create(:user, :blocked) } let_it_be(:ldap_blocked_user) { create(:omniauth_user, :ldap_blocked) } let_it_be(:blocked_pending_approval_user) { create(:user, :blocked_pending_approval) } + let_it_be(:banned_user) { create(:user, :banned) } describe '.blocked' do subject { described_class.blocked } @@ -738,7 +739,7 @@ RSpec.describe User do ldap_blocked_user ) - expect(subject).not_to include(active_user, blocked_pending_approval_user) + expect(subject).not_to include(active_user, blocked_pending_approval_user, banned_user) end end @@ -749,6 +750,14 @@ RSpec.describe User do expect(subject).to contain_exactly(blocked_pending_approval_user) end end + + describe '.banned' do + subject { described_class.banned } + + it 'returns only banned users' do + expect(subject).to contain_exactly(banned_user) + end + end end describe ".with_two_factor" do @@ -1934,6 +1943,12 @@ RSpec.describe User do expect(described_class.filter_items('blocked')).to include user end + it 'filters by banned' do + expect(described_class).to receive(:banned).and_return([user]) + + expect(described_class.filter_items('banned')).to include user + end + it 'filters by blocked pending approval' do expect(described_class).to receive(:blocked_pending_approval).and_return([user]) |