|
|
|
@ -30,14 +30,16 @@ 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" } |
|
|
|
|
|
|
|
|
@ -48,6 +50,9 @@ describe Groups::CleanupInheritedRolesService, 'integration', type: :model do |
|
|
|
|
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 |
|
|
|
|