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
diff options
context:
space:
mode:
Diffstat (limited to 'spec/serializers')
-rw-r--r--spec/serializers/ci/group_variable_entity_spec.rb6
-rw-r--r--spec/serializers/ci/variable_entity_spec.rb6
-rw-r--r--spec/serializers/deploy_keys/deploy_key_entity_spec.rb3
-rw-r--r--spec/serializers/entity_date_helper_spec.rb6
-rw-r--r--spec/serializers/issue_entity_spec.rb20
-rw-r--r--spec/serializers/linked_project_issue_entity_spec.rb10
-rw-r--r--spec/serializers/member_entity_spec.rb22
-rw-r--r--spec/serializers/merge_request_poll_cached_widget_entity_spec.rb4
-rw-r--r--spec/serializers/merge_request_user_entity_spec.rb2
-rw-r--r--spec/serializers/pipeline_details_entity_spec.rb8
-rw-r--r--spec/serializers/pipeline_serializer_spec.rb24
-rw-r--r--spec/serializers/prometheus_alert_entity_spec.rb4
-rw-r--r--spec/serializers/release_serializer_spec.rb11
13 files changed, 83 insertions, 43 deletions
diff --git a/spec/serializers/ci/group_variable_entity_spec.rb b/spec/serializers/ci/group_variable_entity_spec.rb
index 9b64e263992..42c4e940421 100644
--- a/spec/serializers/ci/group_variable_entity_spec.rb
+++ b/spec/serializers/ci/group_variable_entity_spec.rb
@@ -3,14 +3,16 @@
require 'spec_helper'
RSpec.describe Ci::GroupVariableEntity do
- let(:variable) { create(:ci_group_variable) }
+ let(:variable) { build(:ci_group_variable) }
let(:entity) { described_class.new(variable) }
describe '#as_json' do
subject { entity.as_json }
it 'contains required fields' do
- expect(subject).to include(:id, :key, :value, :protected, :variable_type, :environment_scope)
+ expect(subject.keys).to contain_exactly(
+ :id, :key, :value, :protected, :variable_type, :environment_scope, :raw, :masked
+ )
end
end
end
diff --git a/spec/serializers/ci/variable_entity_spec.rb b/spec/serializers/ci/variable_entity_spec.rb
index 38da0b16bbd..96111604028 100644
--- a/spec/serializers/ci/variable_entity_spec.rb
+++ b/spec/serializers/ci/variable_entity_spec.rb
@@ -3,14 +3,16 @@
require 'spec_helper'
RSpec.describe Ci::VariableEntity do
- let(:variable) { create(:ci_variable) }
+ let(:variable) { build(:ci_variable) }
let(:entity) { described_class.new(variable) }
describe '#as_json' do
subject { entity.as_json }
it 'contains required fields' do
- expect(subject).to include(:id, :key, :value, :protected, :environment_scope, :variable_type)
+ expect(subject.keys).to contain_exactly(
+ :id, :key, :value, :protected, :environment_scope, :variable_type, :raw, :masked
+ )
end
end
end
diff --git a/spec/serializers/deploy_keys/deploy_key_entity_spec.rb b/spec/serializers/deploy_keys/deploy_key_entity_spec.rb
index 7719cafae11..4302ed3a097 100644
--- a/spec/serializers/deploy_keys/deploy_key_entity_spec.rb
+++ b/spec/serializers/deploy_keys/deploy_key_entity_spec.rb
@@ -39,7 +39,8 @@ RSpec.describe DeployKeys::DeployKeyEntity do
id: project.id,
name: project.name,
full_path: project_path(project),
- full_name: project.full_name
+ full_name: project.full_name,
+ refs_url: refs_project_path(project)
}
}
]
diff --git a/spec/serializers/entity_date_helper_spec.rb b/spec/serializers/entity_date_helper_spec.rb
index a8c338675e2..5a4571339b3 100644
--- a/spec/serializers/entity_date_helper_spec.rb
+++ b/spec/serializers/entity_date_helper_spec.rb
@@ -48,7 +48,7 @@ RSpec.describe EntityDateHelper do
describe '#remaining_days_in_words' do
around do |example|
- Timecop.freeze(Time.utc(2017, 3, 17)) { example.run }
+ travel_to(Time.utc(2017, 3, 17)) { example.run }
end
context 'when less than 31 days remaining' do
@@ -75,7 +75,9 @@ RSpec.describe EntityDateHelper do
end
it 'returns 1 day remaining when queried mid-day' do
- Timecop.freeze(Time.utc(2017, 3, 17, 13, 10)) do
+ travel_back
+
+ travel_to(Time.utc(2017, 3, 17, 13, 10)) do
expect(milestone_remaining).to eq("<strong>1</strong> day remaining")
end
end
diff --git a/spec/serializers/issue_entity_spec.rb b/spec/serializers/issue_entity_spec.rb
index 6161d4d7ec2..9d53d8bb235 100644
--- a/spec/serializers/issue_entity_spec.rb
+++ b/spec/serializers/issue_entity_spec.rb
@@ -162,4 +162,24 @@ RSpec.describe IssueEntity do
end
it_behaves_like 'issuable entity current_user properties'
+
+ context 'when issue has email participants' do
+ before do
+ resource.issue_email_participants.create!(email: 'any@email.com')
+ end
+
+ context 'when issue is confidential' do
+ it 'returns email participants' do
+ resource.update!(confidential: true)
+
+ expect(subject[:issue_email_participants]).to match_array([{ email: "any@email.com" }])
+ end
+ end
+
+ context 'when issue is not confidential' do
+ it 'returns empty array' do
+ expect(subject[:issue_email_participants]).to be_empty
+ end
+ end
+ end
end
diff --git a/spec/serializers/linked_project_issue_entity_spec.rb b/spec/serializers/linked_project_issue_entity_spec.rb
index 523b89921b6..d415d1cbcb2 100644
--- a/spec/serializers/linked_project_issue_entity_spec.rb
+++ b/spec/serializers/linked_project_issue_entity_spec.rb
@@ -6,10 +6,10 @@ RSpec.describe LinkedProjectIssueEntity do
include Gitlab::Routing.url_helpers
let_it_be(:user) { create(:user) }
- let_it_be(:project) { create(:project) }
let_it_be(:issue_link) { create(:issue_link) }
let(:request) { double('request') }
+ let(:issue_type) { :task }
let(:related_issue) { issue_link.source.related_issues(user).first }
let(:entity) { described_class.new(related_issue, request: request, current_user: user) }
@@ -31,9 +31,7 @@ RSpec.describe LinkedProjectIssueEntity do
end
context 'when related issue is a task' do
- before do
- related_issue.update!(issue_type: :task, work_item_type: WorkItems::Type.default_by_type(:task))
- end
+ let_it_be(:issue_link) { create(:issue_link, target: create(:issue, :task)) }
it 'returns a work item issue type' do
expect(serialized_entity).to include(type: 'TASK')
@@ -47,9 +45,7 @@ RSpec.describe LinkedProjectIssueEntity do
end
context 'when related issue is a task' do
- before do
- related_issue.update!(issue_type: :task, work_item_type: WorkItems::Type.default_by_type(:task))
- end
+ let_it_be(:issue_link) { create(:issue_link, target: create(:issue, :task)) }
context 'when use_iid_in_work_items_path feature flag is disabled' do
before do
diff --git a/spec/serializers/member_entity_spec.rb b/spec/serializers/member_entity_spec.rb
index 370fa14b1e8..350355eb72d 100644
--- a/spec/serializers/member_entity_spec.rb
+++ b/spec/serializers/member_entity_spec.rb
@@ -90,6 +90,28 @@ RSpec.describe MemberEntity do
it_behaves_like 'is_direct_member'
end
+ context 'is_last_owner' do
+ context 'when member is last owner' do
+ before do
+ allow(member).to receive(:last_owner?).and_return(true)
+ end
+
+ it 'exposes `is_last_owner` as `true`' do
+ expect(entity_hash[:is_last_owner]).to be(true)
+ end
+ end
+
+ context 'when owner is not last owner' do
+ before do
+ allow(member).to receive(:last_owner?).and_return(false)
+ end
+
+ it 'exposes `is_last_owner` as `false`' do
+ expect(entity_hash[:is_last_owner]).to be(false)
+ end
+ end
+ 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) }
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 702c6d9fe98..f883156628a 100644
--- a/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb
+++ b/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb
@@ -152,10 +152,10 @@ RSpec.describe MergeRequestPollCachedWidgetEntity do
.to eq(closed_event.author_id)
expect(subject.dig(:metrics, :merged_at).to_s)
- .to eq(merge_event.updated_at.to_s)
+ .to eq(merge_event.updated_at.iso8601)
expect(subject.dig(:metrics, :closed_at).to_s)
- .to eq(closed_event.updated_at.to_s)
+ .to eq(closed_event.updated_at.iso8601)
end
end
diff --git a/spec/serializers/merge_request_user_entity_spec.rb b/spec/serializers/merge_request_user_entity_spec.rb
index 5c7120ab6a4..3e136f29247 100644
--- a/spec/serializers/merge_request_user_entity_spec.rb
+++ b/spec/serializers/merge_request_user_entity_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe MergeRequestUserEntity do
- let_it_be(:user) { create(:user) }
+ let_it_be_with_reload(:user) { create(:user) }
let_it_be(:merge_request) { create(:merge_request, assignees: [user]) }
let(:request) { EntityRequest.new(project: merge_request.target_project, current_user: user) }
diff --git a/spec/serializers/pipeline_details_entity_spec.rb b/spec/serializers/pipeline_details_entity_spec.rb
index ca38721cc7f..764d55e8b4a 100644
--- a/spec/serializers/pipeline_details_entity_spec.rb
+++ b/spec/serializers/pipeline_details_entity_spec.rb
@@ -11,16 +11,16 @@ RSpec.describe PipelineDetailsEntity do
described_class.represent(pipeline, request: request)
end
- it 'inherits from PipelineEntity' do
- expect(described_class).to be < Ci::PipelineEntity
- end
-
before do
stub_not_protect_default_branch
allow(request).to receive(:current_user).and_return(user)
end
+ it 'inherits from PipelineEntity' do
+ expect(described_class).to be < Ci::PipelineEntity
+ end
+
describe '#as_json' do
subject { entity.as_json }
diff --git a/spec/serializers/pipeline_serializer_spec.rb b/spec/serializers/pipeline_serializer_spec.rb
index 9caaeb3450b..33fee68a2f2 100644
--- a/spec/serializers/pipeline_serializer_spec.rb
+++ b/spec/serializers/pipeline_serializer_spec.rb
@@ -183,25 +183,25 @@ RSpec.describe PipelineSerializer do
context 'with triggered pipelines' do
before do
- pipeline_1 = create(:ci_pipeline)
+ pipeline_1 = create(:ci_pipeline, project: project)
build_1 = create(:ci_build, pipeline: pipeline_1)
create(:ci_sources_pipeline, source_job: build_1)
-
- pipeline_2 = create(:ci_pipeline)
- build_2 = create(:ci_build, pipeline: pipeline_2)
- create(:ci_sources_pipeline, source_job: build_2)
end
it 'verifies number of queries', :request_store do
- recorded = ActiveRecord::QueryRecorder.new { subject }
+ control = ActiveRecord::QueryRecorder.new do
+ serializer.represent(Ci::Pipeline.all, preload: true)
+ end
- # Existing numbers are high and require performance optimization
- # Ongoing issue:
- # https://gitlab.com/gitlab-org/gitlab/-/issues/225156
- expected_queries = Gitlab.ee? ? 78 : 74
+ pipeline_2 = create(:ci_pipeline, project: project)
+ build_2 = create(:ci_build, pipeline: pipeline_2)
+ create(:ci_sources_pipeline, source_job: build_2)
- expect(recorded.count).to be_within(2).of(expected_queries)
- expect(recorded.cached_count).to eq(0)
+ recorded = ActiveRecord::QueryRecorder.new do
+ serializer.represent(Ci::Pipeline.all, preload: true)
+ end
+
+ expect(recorded).not_to exceed_query_limit(control)
end
end
diff --git a/spec/serializers/prometheus_alert_entity_spec.rb b/spec/serializers/prometheus_alert_entity_spec.rb
index 91a1e3377c2..02da5a5bb88 100644
--- a/spec/serializers/prometheus_alert_entity_spec.rb
+++ b/spec/serializers/prometheus_alert_entity_spec.rb
@@ -3,8 +3,8 @@
require 'spec_helper'
RSpec.describe PrometheusAlertEntity do
- let(:user) { create(:user) }
- let(:prometheus_alert) { create(:prometheus_alert) }
+ let(:user) { build_stubbed(:user) }
+ let(:prometheus_alert) { build_stubbed(:prometheus_alert) }
let(:request) { double('prometheus_alert', current_user: user) }
let(:entity) { described_class.new(prometheus_alert, request: request) }
diff --git a/spec/serializers/release_serializer_spec.rb b/spec/serializers/release_serializer_spec.rb
index b31172c3a50..e9f56e3453e 100644
--- a/spec/serializers/release_serializer_spec.rb
+++ b/spec/serializers/release_serializer_spec.rb
@@ -3,18 +3,13 @@
require 'spec_helper'
RSpec.describe ReleaseSerializer do
- let(:user) { create(:user) }
- let(:project) { create :project }
+ let(:user) { build_stubbed(:user) }
subject { described_class.new.represent(resource, current_user: user) }
- before do
- project.add_developer(user)
- end
-
describe '#represent' do
context 'when a single object is being serialized' do
- let(:resource) { create(:release, project: project) }
+ let(:resource) { build_stubbed(:release) }
it 'serializes the label object' do
expect(subject[:tag]).to eq resource.tag
@@ -26,7 +21,7 @@ RSpec.describe ReleaseSerializer do
end
context 'when multiple objects are being serialized' do
- let(:resource) { create_list(:release, 3) }
+ let(:resource) { build_stubbed_list(:release, 3) }
it 'serializes the array of releases' do
expect(subject.size).to eq(3)