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

51 lines
1.3 KiB
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe MemberSerializer do
include MembersPresentation
let_it_be(:current_user) { create(:user) }
2021-04-29 21:17:54 +05:30
subject(:representation) do
described_class.new.represent(members, { current_user: current_user, group: group, source: source }).to_json
end
2021-03-08 18:12:59 +05:30
shared_examples 'members.json' do
2021-04-29 21:17:54 +05:30
it { is_expected.to match_schema('members') }
2021-03-08 18:12:59 +05:30
end
context 'group member' do
2021-04-29 21:17:54 +05:30
let_it_be(:group) { create(:group) }
let_it_be(:members) { present_members(create_list(:group_member, 1, group: group)) }
2021-03-11 19:13:27 +05:30
let(:source) { group }
2021-03-08 18:12:59 +05:30
it_behaves_like 'members.json'
2021-04-29 21:17:54 +05:30
it 'handles last group owner assignment' do
group_member = members.last
expect { representation }.to change(group_member, :last_owner)
.from(nil).to(true)
.and change(group_member, :last_blocked_owner).from(nil).to(false)
end
2021-03-08 18:12:59 +05:30
end
context 'project member' do
2021-04-29 21:17:54 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:members) { present_members(create_list(:project_member, 1, project: project)) }
2021-03-11 19:13:27 +05:30
let(:source) { project }
2021-03-08 18:12:59 +05:30
let(:group) { project.group }
it_behaves_like 'members.json'
2021-04-29 21:17:54 +05:30
it 'does not invoke group owner assignment' do
2021-09-04 01:27:46 +05:30
expect(LastGroupOwnerAssigner).not_to receive(:new)
2021-04-29 21:17:54 +05:30
representation
end
2021-03-08 18:12:59 +05:30
end
end