diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /spec/serializers | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'spec/serializers')
4 files changed, 138 insertions, 23 deletions
diff --git a/spec/serializers/member_entity_spec.rb b/spec/serializers/member_entity_spec.rb index dc7aa4611f2..370fa14b1e8 100644 --- a/spec/serializers/member_entity_spec.rb +++ b/spec/serializers/member_entity_spec.rb @@ -39,6 +39,10 @@ RSpec.describe MemberEntity do expect(entity_hash[:invite][:can_resend]).to be(true) end + + it 'exposes `invite.user_state` as empty string' do + expect(entity_hash[:invite][:user_state]).to eq('') + end end shared_examples 'is_direct_member' do @@ -59,6 +63,12 @@ RSpec.describe MemberEntity do end end + shared_examples 'user state is blocked_pending_approval' do + it 'displays proper user state' do + expect(entity_hash[:invite][:user_state]).to eq('blocked_pending_approval') + end + end + context 'group member' do let(:group) { create(:group) } let(:source) { group } @@ -79,6 +89,14 @@ RSpec.describe MemberEntity do it_behaves_like 'is_direct_member' end + + context 'new member user state is blocked_pending_approval' do + let(:user) { create(:user, :blocked_pending_approval) } + let(:group_member) { create(:group_member, :invited, group: group, invite_email: user.email) } + let(:member) { GroupMemberPresenter.new(GroupMember.with_invited_user_state.find(group_member.id), current_user: current_user) } + + it_behaves_like 'user state is blocked_pending_approval' + end end context 'project member' do @@ -102,5 +120,13 @@ RSpec.describe MemberEntity do it_behaves_like 'is_direct_member' end + + context 'new members user state is blocked_pending_approval' do + let(:user) { create(:user, :blocked_pending_approval) } + let(:project_member) { create(:project_member, :invited, project: project, invite_email: user.email) } + let(:member) { ProjectMemberPresenter.new(ProjectMember.with_invited_user_state.find(project_member.id), current_user: current_user) } + + it_behaves_like 'user state is blocked_pending_approval' + end end end diff --git a/spec/serializers/merge_request_metrics_helper_spec.rb b/spec/serializers/merge_request_metrics_helper_spec.rb new file mode 100644 index 00000000000..8f683df1faa --- /dev/null +++ b/spec/serializers/merge_request_metrics_helper_spec.rb @@ -0,0 +1,69 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe MergeRequestMetricsHelper do + let_it_be(:user) { create(:user) } + + let(:merge_request) { create(:merge_request) } + let(:helper) { Class.new.include(described_class).new } + + describe '#build_metrics' do + subject do + helper.build_metrics(merge_request) + end + + shared_examples 'does not rebuild the metrics' do + it 'does not call the merge request metrics class' do + expect(MergeRequest::Metrics).not_to receive(:new) + + subject + end + + it 'returns the metrics for the given merge request' do + expect(subject).to be_kind_of(MergeRequest::Metrics) + expect(subject[:merge_request_id]).to eq(merge_request.id) + end + end + + context 'when closed and metrics exists' do + before do + merge_request.close! + merge_request.metrics.update!(latest_closed_by: user) + end + + include_examples 'does not rebuild the metrics' + end + + context 'when merged and metrics exists' do + before do + merge_request.mark_as_merged! + merge_request.metrics.update!(merged_by: user) + end + + include_examples 'does not rebuild the metrics' + end + + context 'when merged and metrics do not exists' do + before do + merge_request.mark_as_merged! + merge_request.metrics.destroy! + merge_request.reload + end + + it 'rebuilds the merge request metrics' do + closed_event = merge_request.closed_event + merge_event = merge_request.merge_event + + expect(MergeRequest::Metrics).to receive(:new) + .with(latest_closed_at: closed_event&.updated_at, + latest_closed_by: closed_event&.author, + merged_at: merge_event&.updated_at, + merged_by: merge_event&.author) + .and_call_original + + subject + end + end + end +end diff --git a/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb b/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb index 5f4b734fcea..ecc93219b53 100644 --- a/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb +++ b/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb @@ -275,7 +275,7 @@ RSpec.describe MergeRequestPollCachedWidgetEntity do expect(subject[:merge_pipeline]).to be_nil end - context 'when is merged' do + context 'when is merged', :sidekiq_inline do let(:resource) { create(:merged_merge_request, source_project: project, merge_commit_sha: project.commit.id) } let(:pipeline) { create(:ci_empty_pipeline, project: project, ref: resource.target_branch, sha: resource.merge_commit_sha) } diff --git a/spec/serializers/merge_request_widget_entity_spec.rb b/spec/serializers/merge_request_widget_entity_spec.rb index 35846b0d4ea..fcfdbfc0967 100644 --- a/spec/serializers/merge_request_widget_entity_spec.rb +++ b/spec/serializers/merge_request_widget_entity_spec.rb @@ -283,28 +283,6 @@ RSpec.describe MergeRequestWidgetEntity do it 'provides a valid value for suggest pipeline feature id' do expect(subject[:suggest_pipeline_feature_id]).to eq described_class::SUGGEST_PIPELINE end - - it 'provides a valid value for if it is dismissed' do - expect(subject[:is_dismissed_suggest_pipeline]).to be(false) - end - - context 'when the suggest pipeline has been dismissed' do - before do - create(:user_callout, user: user, feature_name: described_class::SUGGEST_PIPELINE) - end - - it 'indicates suggest pipeline has been dismissed' do - expect(subject[:is_dismissed_suggest_pipeline]).to be(true) - end - end - - context 'when user is not logged in' do - let(:request) { double('request', current_user: nil, project: project) } - - it 'returns a blank is dismissed value' do - expect(subject[:is_dismissed_suggest_pipeline]).to be_nil - end - end end it 'has human access' do @@ -395,4 +373,46 @@ RSpec.describe MergeRequestWidgetEntity do end end end + + describe 'is_dismissed_suggest_pipeline' do + context 'when user is logged in' do + context 'when the suggest pipeline feature is enabled' do + before do + allow(Gitlab::CurrentSettings).to receive(:suggest_pipeline_enabled?).and_return(true) + end + + it 'is false' do + expect(subject[:is_dismissed_suggest_pipeline]).to be(false) + end + + context 'when suggest pipeline has been dismissed' do + before do + create(:user_callout, user: user, feature_name: described_class::SUGGEST_PIPELINE) + end + + it 'is true' do + expect(subject[:is_dismissed_suggest_pipeline]).to be(true) + end + end + end + + context 'when the suggest pipeline feature is disabled' do + before do + allow(Gitlab::CurrentSettings).to receive(:suggest_pipeline_enabled?).and_return(false) + end + + it 'is true' do + expect(subject[:is_dismissed_suggest_pipeline]).to be(true) + end + end + end + + context 'when user is not logged in' do + let(:request) { double('request', current_user: nil, project: project) } + + it 'is true' do + expect(subject[:is_dismissed_suggest_pipeline]).to be(true) + end + end + end end |