debian-mirror-gitlab/spec/serializers/merge_request_user_entity_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

82 lines
2.4 KiB
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
2018-11-08 19:23:39 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe MergeRequestUserEntity do
2023-03-04 22:38:38 +05:30
let_it_be_with_reload(:user) { create(:user) }
2021-12-11 22:18:48 +05:30
let_it_be(:merge_request) { create(:merge_request, assignees: [user]) }
2021-04-29 21:17:54 +05:30
2021-04-17 20:07:23 +05:30
let(:request) { EntityRequest.new(project: merge_request.target_project, current_user: user) }
2018-11-08 19:23:39 +05:30
let(:entity) do
2021-04-17 20:07:23 +05:30
described_class.new(user, request: request, merge_request: merge_request)
2018-11-08 19:23:39 +05:30
end
2021-04-17 20:07:23 +05:30
describe '#as_json' do
2018-11-08 19:23:39 +05:30
subject { entity.as_json }
it 'exposes needed attributes' do
2021-04-17 20:07:23 +05:30
is_expected.to include(
:id, :name, :username, :state, :avatar_url, :web_url,
2022-08-27 11:52:29 +05:30
:can_merge, :can_update_merge_request, :reviewed, :approved
2021-04-17 20:07:23 +05:30
)
2018-11-08 19:23:39 +05:30
end
2021-03-11 19:13:27 +05:30
context 'when `status` is not preloaded' do
it 'does not expose the availability attribute' do
expect(subject).not_to include(:availability)
end
end
2021-04-17 20:07:23 +05:30
context 'when the user has not approved the merge-request' do
it 'exposes that the user has not approved the MR' do
expect(subject).to include(approved: false)
end
end
context 'when the user has approved the merge-request' do
before do
merge_request.approvals.create!(user: user)
end
it 'exposes that the user has approved the MR' do
expect(subject).to include(approved: true)
end
end
2021-03-11 19:13:27 +05:30
context 'when `status` is preloaded' do
before do
user.create_status!(availability: :busy)
user.status # make sure `status` is loaded
end
it 'exposes the availibility attribute' do
expect(subject[:availability]).to eq('busy')
end
end
2021-04-17 20:07:23 +05:30
describe 'performance' do
let_it_be(:user_a) { create(:user) }
let_it_be(:user_b) { create(:user) }
let_it_be(:merge_request_b) { create(:merge_request) }
it 'is linear in the number of merge requests' do
pending "See: https://gitlab.com/gitlab-org/gitlab/-/issues/322549"
baseline = ActiveRecord::QueryRecorder.new do
ent = described_class.new(user_a, request: request, merge_request: merge_request)
ent.as_json
end
expect do
a = described_class.new(user_a, request: request, merge_request: merge_request_b)
b = described_class.new(user_b, request: request, merge_request: merge_request_b)
a.as_json
b.as_json
end.not_to exceed_query_limit(baseline)
end
end
2018-11-08 19:23:39 +05:30
end
end