Cleanup global role associated with group when membership is deleted

It was already handled. Only tests were updated.
pull/10063/head
Christophe Bliard 3 years ago
parent 7d862d4cc8
commit e6d75f8756
No known key found for this signature in database
GPG Key ID: 2BC07603210C3FA4
  1. 28
      spec/services/groups/cleanup_inherited_roles_service_integration_spec.rb

@ -30,24 +30,29 @@ require 'spec_helper'
describe Groups::CleanupInheritedRolesService, 'integration', type: :model do
subject(:service_call) do
member.destroy
members.destroy_all
instance.call(params)
end
let(:project) { create :project }
let(:role) { create :role }
let(:global_role) { create :global_role }
let(:current_user) { create :admin }
let(:roles) { [role] }
let(:global_roles) { [global_role] }
let(:params) { { message: message } }
let(:message) { "Some message" }
let!(:group) do
create(:group,
members: users).tap do |group|
members: users).tap do |group|
create(:member,
project: project,
principal: group,
roles: roles)
project: project,
principal: group,
roles: roles)
create(:global_member,
principal: group,
roles: global_roles)
::Groups::AddUsersService
.new(group, current_user: User.system, contract_class: EmptyContract)
@ -55,7 +60,7 @@ describe Groups::CleanupInheritedRolesService, 'integration', type: :model do
end
end
let(:users) { create_list :user, 2 }
let(:member) { Member.find_by(principal: group) }
let(:members) { Member.where(principal: group) }
let(:instance) do
described_class.new(group, current_user: current_user)
@ -104,10 +109,12 @@ describe Groups::CleanupInheritedRolesService, 'integration', type: :model do
context 'when also having own roles' do
let(:another_role) { create(:role) }
let(:another_global_role) { create(:global_role) }
let!(:first_user_member) do
group
Member.find_by(principal: users.first).tap do |m|
m.roles << another_role
m.roles << another_global_role
end
end
@ -130,7 +137,7 @@ describe Groups::CleanupInheritedRolesService, 'integration', type: :model do
.not_to eql(Member.find_by(id: first_user_member.id).updated_at)
expect(first_user_member.reload.roles)
.to match_array([another_role])
.to match_array([another_role, another_global_role])
end
it 'sends a notification on the kept membership' do
@ -144,11 +151,12 @@ describe Groups::CleanupInheritedRolesService, 'integration', type: :model do
end
end
context 'when the user has had the role added by the group before' do
context 'when the user has had the roles added by the group before' do
let(:another_role) { create(:role) }
let!(:first_user_member) do
Member.find_by(principal: users.first).tap do |m|
m.member_roles.create(role: role)
m.member_roles.create(role: global_role)
end
end
@ -171,7 +179,7 @@ describe Groups::CleanupInheritedRolesService, 'integration', type: :model do
.not_to eql(Member.find_by(id: first_user_member.id).updated_at)
expect(first_user_member.reload.roles)
.to match_array([role])
.to match_array([role, global_role])
end
it 'sends a notification on the kept membership' do
@ -191,7 +199,7 @@ describe Groups::CleanupInheritedRolesService, 'integration', type: :model do
.where(member_id: Member.where(principal: users.first))
.pluck(:id)
end
let(:params) { { member_role_ids: member_role_ids} }
let(:params) { { member_role_ids: member_role_ids } }
it 'is successful' do
expect(service_call)

Loading…
Cancel
Save