summaryrefslogtreecommitdiff
path: root/spec/serializers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-18 09:45:46 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-18 09:45:46 +0000
commita7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch)
tree7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/serializers
parentee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff)
downloadgitlab-ce-a7b3560714b4d9cc4ab32dffcd1f74a284b93580.tar.gz
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/build_details_entity_spec.rb2
-rw-r--r--spec/serializers/ci/lint/result_serializer_spec.rb4
-rw-r--r--spec/serializers/codequality_degradation_entity_spec.rb15
-rw-r--r--spec/serializers/deployment_cluster_entity_spec.rb6
-rw-r--r--spec/serializers/diff_file_base_entity_spec.rb2
-rw-r--r--spec/serializers/environment_serializer_spec.rb15
-rw-r--r--spec/serializers/group_child_entity_spec.rb19
-rw-r--r--spec/serializers/issue_sidebar_basic_entity_spec.rb74
-rw-r--r--spec/serializers/merge_request_poll_cached_widget_entity_spec.rb20
-rw-r--r--spec/serializers/merge_request_poll_widget_entity_spec.rb10
-rw-r--r--spec/serializers/runner_entity_spec.rb2
-rw-r--r--spec/serializers/test_case_entity_spec.rb12
-rw-r--r--spec/serializers/trigger_variable_entity_spec.rb2
13 files changed, 142 insertions, 41 deletions
diff --git a/spec/serializers/build_details_entity_spec.rb b/spec/serializers/build_details_entity_spec.rb
index a24841fe286..da2734feb51 100644
--- a/spec/serializers/build_details_entity_spec.rb
+++ b/spec/serializers/build_details_entity_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe BuildDetailsEntity do
describe '#as_json' do
let(:project) { create(:project, :repository) }
- let(:user) { project.owner }
+ let(:user) { project.first_owner }
let(:pipeline) { create(:ci_pipeline, project: project) }
let(:build) { create(:ci_build, :failed, pipeline: pipeline) }
let(:request) { double('request', project: project) }
diff --git a/spec/serializers/ci/lint/result_serializer_spec.rb b/spec/serializers/ci/lint/result_serializer_spec.rb
index a834ea05e14..3fdaba1808a 100644
--- a/spec/serializers/ci/lint/result_serializer_spec.rb
+++ b/spec/serializers/ci/lint/result_serializer_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Ci::Lint::ResultSerializer, :aggregate_failures do
let(:result) do
Gitlab::Ci::Lint
- .new(project: project, current_user: project.owner)
+ .new(project: project, current_user: project.first_owner)
.validate(yaml_content, dry_run: false)
end
@@ -64,7 +64,7 @@ RSpec.describe Ci::Lint::ResultSerializer, :aggregate_failures do
context 'when dry run is enabled' do
let(:result) do
Gitlab::Ci::Lint
- .new(project: project, current_user: project.owner)
+ .new(project: project, current_user: project.first_owner)
.validate(yaml_content, dry_run: true)
end
diff --git a/spec/serializers/codequality_degradation_entity_spec.rb b/spec/serializers/codequality_degradation_entity_spec.rb
index 315f00baa72..f56420bfdbd 100644
--- a/spec/serializers/codequality_degradation_entity_spec.rb
+++ b/spec/serializers/codequality_degradation_entity_spec.rb
@@ -30,6 +30,21 @@ RSpec.describe CodequalityDegradationEntity do
expect(subject[:line]).to eq(10)
end
end
+
+ context 'when severity is capitalized' do
+ let(:codequality_degradation) { build(:codequality_degradation_3) }
+
+ before do
+ codequality_degradation[:severity] = 'MINOR'
+ end
+
+ it 'lowercases severity', :aggregate_failures do
+ expect(subject[:description]).to eq("Avoid parameter lists longer than 5 parameters. [12/5]")
+ expect(subject[:severity]).to eq("minor")
+ expect(subject[:file_path]).to eq("file_b.rb")
+ expect(subject[:line]).to eq(10)
+ end
+ end
end
end
end
diff --git a/spec/serializers/deployment_cluster_entity_spec.rb b/spec/serializers/deployment_cluster_entity_spec.rb
index 95f2f8ce6fc..419ae746b74 100644
--- a/spec/serializers/deployment_cluster_entity_spec.rb
+++ b/spec/serializers/deployment_cluster_entity_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe DeploymentClusterEntity do
subject { described_class.new(deployment, request: request).as_json }
let(:maintainer) { create(:user) }
- let(:developer) { create(:user) }
+ let(:reporter) { create(:user) }
let(:current_user) { maintainer }
let(:request) { double(:request, current_user: current_user) }
let(:project) { create(:project) }
@@ -17,7 +17,7 @@ RSpec.describe DeploymentClusterEntity do
before do
project.add_maintainer(maintainer)
- project.add_developer(developer)
+ project.add_reporter(reporter)
end
it 'matches deployment_cluster entity schema' do
@@ -31,7 +31,7 @@ RSpec.describe DeploymentClusterEntity do
end
context 'when the user does not have permission to view the cluster' do
- let(:current_user) { developer }
+ let(:current_user) { reporter }
it 'does not include the path nor the namespace' do
expect(subject[:path]).to be_nil
diff --git a/spec/serializers/diff_file_base_entity_spec.rb b/spec/serializers/diff_file_base_entity_spec.rb
index 99dbaff4b7e..11ceb7991d7 100644
--- a/spec/serializers/diff_file_base_entity_spec.rb
+++ b/spec/serializers/diff_file_base_entity_spec.rb
@@ -142,7 +142,7 @@ RSpec.describe DiffFileBaseEntity do
end
context 'when source_project and target_project are different' do
- let(:target_project) { fork_project(source_project, source_project.owner, repository: true) }
+ let(:target_project) { fork_project(source_project, source_project.first_owner, repository: true) }
it 'returns the merge_request ide route with the target_project as param' do
expect(entity[:ide_edit_path]).to eq("#{expected_merge_request_path}?target_project=#{ERB::Util.url_encode(target_project.full_path)}")
diff --git a/spec/serializers/environment_serializer_spec.rb b/spec/serializers/environment_serializer_spec.rb
index 80b6f00d8c9..658062c9461 100644
--- a/spec/serializers/environment_serializer_spec.rb
+++ b/spec/serializers/environment_serializer_spec.rb
@@ -204,21 +204,6 @@ RSpec.describe EnvironmentSerializer do
json
end
-
- # Including for test coverage pipeline failure, remove along with feature flag.
- context 'when custom preload feature is disabled' do
- before do
- Feature.disable(:custom_preloader_for_deployments)
- end
-
- it 'avoids N+1 database queries' do
- control_count = ActiveRecord::QueryRecorder.new { json }.count
-
- create_environment_with_associations(project)
-
- expect { json }.not_to exceed_query_limit(control_count)
- end
- end
end
def create_environment_with_associations(project)
diff --git a/spec/serializers/group_child_entity_spec.rb b/spec/serializers/group_child_entity_spec.rb
index 59340181075..469189c0768 100644
--- a/spec/serializers/group_child_entity_spec.rb
+++ b/spec/serializers/group_child_entity_spec.rb
@@ -6,7 +6,8 @@ RSpec.describe GroupChildEntity do
include ExternalAuthorizationServiceHelpers
include Gitlab::Routing.url_helpers
- let(:user) { create(:user) }
+ let_it_be(:user) { create(:user) }
+
let(:request) { double('request') }
let(:entity) { described_class.new(object, request: request) }
@@ -103,6 +104,22 @@ RSpec.describe GroupChildEntity do
expect(json[:can_leave]).to be_truthy
end
+ it 'allows an owner to delete the group' do
+ expect(json[:can_remove]).to be_truthy
+ end
+
+ it 'allows admin to delete the group', :enable_admin_mode do
+ allow(request).to receive(:current_user).and_return(create(:admin))
+
+ expect(json[:can_remove]).to be_truthy
+ end
+
+ it 'disallows a maintainer to delete the group' do
+ object.add_maintainer(user)
+
+ expect(json[:can_remove]).to be_falsy
+ end
+
it 'has the correct edit path' do
expect(json[:edit_path]).to eq(edit_group_path(object))
end
diff --git a/spec/serializers/issue_sidebar_basic_entity_spec.rb b/spec/serializers/issue_sidebar_basic_entity_spec.rb
new file mode 100644
index 00000000000..da07290f349
--- /dev/null
+++ b/spec/serializers/issue_sidebar_basic_entity_spec.rb
@@ -0,0 +1,74 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe IssueSidebarBasicEntity do
+ let_it_be(:project) { create(:project, :repository) }
+ let_it_be(:user) { create(:user, developer_projects: [project]) }
+ let_it_be(:issue) { create(:issue, project: project, assignees: [user]) }
+
+ let(:serializer) { IssueSerializer.new(current_user: user, project: project) }
+
+ subject(:entity) { serializer.represent(issue, serializer: 'sidebar') }
+
+ it 'contains keys related to issuables' do
+ expect(entity).to include(
+ :id, :iid, :type, :author_id, :project_id, :discussion_locked, :reference, :milestone,
+ :labels, :current_user, :issuable_json_path, :namespace_path, :project_path,
+ :project_full_path, :project_issuables_path, :create_todo_path, :project_milestones_path,
+ :project_labels_path, :toggle_subscription_path, :move_issue_path, :projects_autocomplete_path,
+ :project_emails_disabled, :create_note_email, :supports_time_tracking, :supports_milestone,
+ :supports_severity, :supports_escalation
+ )
+ end
+
+ it 'contains attributes related to the issue' do
+ expect(entity).to include(:due_date, :confidential, :severity)
+ end
+
+ describe 'current_user' do
+ it 'contains attributes related to the current user' do
+ expect(entity[:current_user]).to include(
+ :id, :name, :username, :state, :avatar_url, :web_url, :todo,
+ :can_edit, :can_move, :can_admin_label
+ )
+ end
+
+ describe 'can_update_escalation_status' do
+ context 'for a standard issue' do
+ it 'is not present' do
+ expect(entity[:current_user]).not_to have_key(:can_update_escalation_status)
+ end
+ end
+
+ context 'for an incident issue' do
+ before do
+ issue.update!(issue_type: Issue.issue_types[:incident])
+ end
+
+ it 'is present and true' do
+ expect(entity[:current_user][:can_update_escalation_status]).to be(true)
+ end
+
+ context 'without permissions' do
+ let(:serializer) { IssueSerializer.new(current_user: create(:user), project: project) }
+
+ it 'is present and false' do
+ expect(entity[:current_user]).to have_key(:can_update_escalation_status)
+ expect(entity[:current_user][:can_update_escalation_status]).to be(false)
+ end
+ end
+
+ context 'with :incident_escalations feature flag disabled' do
+ before do
+ stub_feature_flags(incident_escalations: false)
+ end
+
+ it 'is not present' do
+ expect(entity[:current_user]).not_to include(:can_update_escalation_status)
+ end
+ end
+ 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 ecc93219b53..e9c1fe23855 100644
--- a/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb
+++ b/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb
@@ -21,12 +21,6 @@ RSpec.describe MergeRequestPollCachedWidgetEntity do
is_expected.to include(:target_branch_sha)
end
- it 'has public_merge_status as merge_status' do
- expect(resource).to receive(:public_merge_status).and_return('checking')
-
- expect(subject[:merge_status]).to eq 'checking'
- end
-
it 'has blob path data' do
allow(resource).to receive_messages(
base_pipeline: pipeline,
@@ -38,6 +32,20 @@ RSpec.describe MergeRequestPollCachedWidgetEntity do
expect(subject[:blob_path]).to include(:head_path)
end
+ describe 'merge_status' do
+ it 'calls for MergeRequest#check_mergeability' do
+ expect(resource).to receive(:check_mergeability).with(async: true)
+
+ subject[:merge_status]
+ end
+
+ it 'has public_merge_status as merge_status' do
+ expect(resource).to receive(:public_merge_status).and_return('checking')
+
+ expect(subject[:merge_status]).to eq 'checking'
+ end
+ end
+
describe 'diverged_commits_count' do
context 'when MR open and its diverging' do
it 'returns diverged commits count' do
diff --git a/spec/serializers/merge_request_poll_widget_entity_spec.rb b/spec/serializers/merge_request_poll_widget_entity_spec.rb
index 3aebe16438c..581efd331ef 100644
--- a/spec/serializers/merge_request_poll_widget_entity_spec.rb
+++ b/spec/serializers/merge_request_poll_widget_entity_spec.rb
@@ -180,16 +180,6 @@ RSpec.describe MergeRequestPollWidgetEntity do
it 'calculates mergeability and returns true' do
expect(subject[:mergeable]).to eq(true)
end
-
- context 'when check_mergeability_async_in_widget is disabled' do
- before do
- stub_feature_flags(check_mergeability_async_in_widget: false)
- end
-
- it 'calculates mergeability and returns true' do
- expect(subject[:mergeable]).to eq(true)
- end
- end
end
end
end
diff --git a/spec/serializers/runner_entity_spec.rb b/spec/serializers/runner_entity_spec.rb
index 39cac65c5ac..f34cb794834 100644
--- a/spec/serializers/runner_entity_spec.rb
+++ b/spec/serializers/runner_entity_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe RunnerEntity do
let(:runner) { create(:ci_runner, :project, projects: [project]) }
let(:entity) { described_class.new(runner, request: request, current_user: user) }
let(:request) { double('request') }
- let(:user) { project.owner }
+ let(:user) { project.first_owner }
before do
allow(request).to receive(:current_user).and_return(user)
diff --git a/spec/serializers/test_case_entity_spec.rb b/spec/serializers/test_case_entity_spec.rb
index cdeefd2fec5..03fb88bc6c3 100644
--- a/spec/serializers/test_case_entity_spec.rb
+++ b/spec/serializers/test_case_entity_spec.rb
@@ -41,6 +41,18 @@ RSpec.describe TestCaseEntity do
end
end
+ context 'when no test name is entered' do
+ let(:test_case) { build(:report_test_case, name: "") }
+
+ it 'contains correct test case details' do
+ expect(subject[:status]).to eq('success')
+ expect(subject[:name]).to eq('(No name)')
+ expect(subject[:classname]).to eq('trace')
+ expect(subject[:file]).to eq('spec/trace_spec.rb')
+ expect(subject[:execution_time]).to eq(1.23)
+ end
+ end
+
context 'when attachment is present' do
let(:test_case) { build(:report_test_case, :failed_with_attachment, job: job) }
diff --git a/spec/serializers/trigger_variable_entity_spec.rb b/spec/serializers/trigger_variable_entity_spec.rb
index e90bfc24f9f..deabbb9d54b 100644
--- a/spec/serializers/trigger_variable_entity_spec.rb
+++ b/spec/serializers/trigger_variable_entity_spec.rb
@@ -31,7 +31,7 @@ RSpec.describe TriggerVariableEntity do
end
context 'when user is owner' do
- let(:user) { project.owner }
+ let(:user) { project.first_owner }
it 'exposes the variable value' do
expect(subject).to include(:value)