2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-16 14:30:17 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Todos::Destroy::ProjectPrivateService do
|
2018-08-06 04:42:51 -04:00
|
|
|
let(:group) { create(:group, :public) }
|
|
|
|
let(:project) { create(:project, :public, group: group) }
|
2018-07-16 14:30:17 -04:00
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project_member) { create(:user) }
|
2018-08-06 04:42:51 -04:00
|
|
|
let(:group_member) { create(:user) }
|
2018-07-16 14:30:17 -04:00
|
|
|
|
2018-08-06 04:42:51 -04:00
|
|
|
let!(:todo_non_member) { create(:todo, user: user, project: project) }
|
|
|
|
let!(:todo2_non_member) { create(:todo, user: user, project: project) }
|
|
|
|
let!(:todo_member) { create(:todo, user: project_member, project: project) }
|
|
|
|
let!(:todo_group_member) { create(:todo, user: group_member, project: project) }
|
2018-07-16 14:30:17 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
before do
|
|
|
|
project.add_developer(project_member)
|
2018-08-06 04:42:51 -04:00
|
|
|
group.add_developer(group_member)
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(project.id).execute }
|
|
|
|
|
|
|
|
context 'when a project set to private' do
|
|
|
|
before do
|
|
|
|
project.update!(visibility_level: Gitlab::VisibilityLevel::PRIVATE)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes issue todos for a user who is not a member' do
|
2018-08-06 04:42:51 -04:00
|
|
|
expect { subject }.to change { Todo.count }.from(4).to(2)
|
2018-07-16 14:30:17 -04:00
|
|
|
|
|
|
|
expect(user.todos).to be_empty
|
2018-08-06 04:42:51 -04:00
|
|
|
expect(project_member.todos).to match_array([todo_member])
|
|
|
|
expect(group_member.todos).to match_array([todo_group_member])
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project is not private' do
|
|
|
|
it 'does not remove any todos' do
|
|
|
|
expect { subject }.not_to change { Todo.count }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|