2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-02 10:16:58 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Todos::Destroy::GroupPrivateService do
|
2018-08-06 04:42:51 -04:00
|
|
|
let(:group) { create(:group, :public) }
|
|
|
|
let(:project) { create(:project, group: group) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:group_member) { create(:user) }
|
|
|
|
let(:project_member) { create(:user) }
|
2018-08-02 10:16:58 -04:00
|
|
|
|
2018-08-06 04:42:51 -04:00
|
|
|
let!(:todo_non_member) { create(:todo, user: user, group: group) }
|
2018-08-02 10:16:58 -04:00
|
|
|
let!(:todo_another_non_member) { create(:todo, user: user, group: group) }
|
2018-08-06 04:42:51 -04:00
|
|
|
let!(:todo_group_member) { create(:todo, user: group_member, group: group) }
|
|
|
|
let!(:todo_project_member) { create(:todo, user: project_member, group: group) }
|
2018-08-02 10:16:58 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
before do
|
|
|
|
group.add_developer(group_member)
|
2018-08-06 04:42:51 -04:00
|
|
|
project.add_developer(project_member)
|
2018-08-02 10:16:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(group.id).execute }
|
|
|
|
|
2018-08-06 04:42:51 -04:00
|
|
|
context 'when a group set to private' do
|
2018-08-02 10:16:58 -04:00
|
|
|
before do
|
|
|
|
group.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
end
|
|
|
|
|
2018-08-06 04:42:51 -04:00
|
|
|
it 'removes todos only for users who are not group users' do
|
|
|
|
expect { subject }.to change { Todo.count }.from(4).to(2)
|
2018-08-02 10:16:58 -04:00
|
|
|
|
|
|
|
expect(user.todos).to be_empty
|
2018-08-06 04:42:51 -04:00
|
|
|
expect(group_member.todos).to match_array([todo_group_member])
|
|
|
|
expect(project_member.todos).to match_array([todo_project_member])
|
|
|
|
end
|
|
|
|
|
2019-07-24 05:20:54 -04:00
|
|
|
context 'with nested groups' do
|
2018-08-06 04:42:51 -04:00
|
|
|
let(:parent_group) { create(:group) }
|
|
|
|
let(:subgroup) { create(:group, :private, parent: group) }
|
|
|
|
let(:subproject) { create(:project, group: subgroup) }
|
|
|
|
|
|
|
|
let(:parent_member) { create(:user) }
|
|
|
|
let(:subgroup_member) { create(:user) }
|
2019-01-16 07:09:29 -05:00
|
|
|
let(:subgproject_member) { create(:user) }
|
2018-08-06 04:42:51 -04:00
|
|
|
|
|
|
|
let!(:todo_parent_member) { create(:todo, user: parent_member, group: group) }
|
|
|
|
let!(:todo_subgroup_member) { create(:todo, user: subgroup_member, group: group) }
|
|
|
|
let!(:todo_subproject_member) { create(:todo, user: subgproject_member, group: group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
group.update!(parent: parent_group)
|
|
|
|
|
|
|
|
parent_group.add_developer(parent_member)
|
|
|
|
subgroup.add_developer(subgroup_member)
|
|
|
|
subproject.add_developer(subgproject_member)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes todos only for users who are not group users' do
|
|
|
|
expect { subject }.to change { Todo.count }.from(7).to(5)
|
|
|
|
end
|
2018-08-02 10:16:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when group is not private' do
|
|
|
|
it 'does not remove any todos' do
|
|
|
|
expect { subject }.not_to change { Todo.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|