2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-16 14:30:17 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe Todos::Destroy::ConfidentialIssueService do
|
2018-07-16 14:30:17 -04:00
|
|
|
let(:project) { create(:project, :public) }
|
|
|
|
let(:user) { create(:user) }
|
2018-07-26 10:53:50 -04:00
|
|
|
let(:author) { create(:user) }
|
|
|
|
let(:assignee) { create(:user) }
|
|
|
|
let(:guest) { create(:user) }
|
2018-07-16 14:30:17 -04:00
|
|
|
let(:project_member) { create(:user) }
|
2019-05-21 15:20:27 -04:00
|
|
|
let(:issue_1) { create(:issue, :confidential, project: project, author: author, assignees: [assignee]) }
|
2018-07-16 14:30:17 -04:00
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
before do
|
|
|
|
project.add_developer(project_member)
|
2018-07-26 10:53:50 -04:00
|
|
|
project.add_guest(guest)
|
2019-05-21 15:20:27 -04:00
|
|
|
|
|
|
|
# todos not to be deleted
|
|
|
|
create(:todo, user: project_member, target: issue_1, project: project)
|
|
|
|
create(:todo, user: author, target: issue_1, project: project)
|
|
|
|
create(:todo, user: assignee, target: issue_1, project: project)
|
|
|
|
create(:todo, user: user, project: project)
|
|
|
|
# Todos to be deleted
|
|
|
|
create(:todo, user: guest, target: issue_1, project: project)
|
|
|
|
create(:todo, user: user, target: issue_1, project: project)
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
|
2019-05-21 15:20:27 -04:00
|
|
|
subject { described_class.new(issue_id: issue_1.id).execute }
|
2018-07-16 14:30:17 -04:00
|
|
|
|
2019-05-21 15:20:27 -04:00
|
|
|
context 'when issue_id parameter is present' do
|
|
|
|
context 'when provided issue is confidential' do
|
|
|
|
it 'removes issue todos for users who can not access the confidential issue' do
|
|
|
|
expect { subject }.to change { Todo.count }.from(6).to(4)
|
|
|
|
end
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
|
2019-05-21 15:20:27 -04:00
|
|
|
context 'when provided issue is not confidential' do
|
|
|
|
it 'does not remove any todos' do
|
|
|
|
issue_1.update(confidential: false)
|
|
|
|
|
|
|
|
expect { subject }.not_to change { Todo.count }
|
|
|
|
end
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-21 15:20:27 -04:00
|
|
|
context 'when project_id parameter is present' do
|
|
|
|
subject { described_class.new(issue_id: nil, project_id: project.id).execute }
|
|
|
|
|
|
|
|
it 'removes issues todos for users that cannot access confidential issues' do
|
|
|
|
issue_2 = create(:issue, :confidential, project: project)
|
|
|
|
issue_3 = create(:issue, :confidential, project: project, author: author, assignees: [assignee])
|
|
|
|
issue_4 = create(:issue, project: project)
|
|
|
|
# Todos not to be deleted
|
|
|
|
create(:todo, user: guest, target: issue_1, project: project)
|
|
|
|
create(:todo, user: assignee, target: issue_1, project: project)
|
|
|
|
create(:todo, user: project_member, target: issue_2, project: project)
|
|
|
|
create(:todo, user: author, target: issue_3, project: project)
|
|
|
|
create(:todo, user: user, target: issue_4, project: project)
|
|
|
|
create(:todo, user: user, project: project)
|
|
|
|
# Todos to be deleted
|
|
|
|
create(:todo, user: user, target: issue_1, project: project)
|
|
|
|
create(:todo, user: guest, target: issue_2, project: project)
|
|
|
|
|
|
|
|
expect { subject }.to change { Todo.count }.from(14).to(10)
|
2018-07-16 14:30:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|