Commit 08492fdc authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Filter out deleted issues

parent b9b273ac
......@@ -31,11 +31,11 @@ module RelatedIssues
<<-SQL.strip_heredoc
SELECT issues.*, related_issues.id as related_issues_id FROM issues
INNER JOIN related_issues ON related_issues.related_issue_id = issues.id
WHERE related_issues.issue_id = #{@issue.id}
WHERE related_issues.issue_id = #{@issue.id} AND issues.deleted_at IS NULL
UNION ALL
SELECT issues.*, related_issues.id as related_issues_id FROM issues
INNER JOIN related_issues ON related_issues.issue_id = issues.id
WHERE related_issues.related_issue_id = #{@issue.id}
WHERE related_issues.related_issue_id = #{@issue.id} AND issues.deleted_at IS NULL
ORDER BY related_issues_id
SQL
)
......
......@@ -37,7 +37,7 @@ describe RelatedIssues::ListService, service: true do
it 'verifies number of queries' do
recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.count).to be_within(1).of(39)
expect(recorded.count).to be_within(1).of(42)
end
it 'returns related issues JSON' do
......@@ -84,6 +84,47 @@ describe RelatedIssues::ListService, service: true do
end
end
context 'referencing issue with removed relationships' do
context 'when referenced a deleted issue' do
let(:issue_b) { create :issue, project: project }
let!(:related_issue) do
create(:related_issue, issue: issue, related_issue: issue_b)
end
it 'ignores issue' do
issue_b.destroy!
is_expected.to eq([])
end
end
context 'when referenced an issue with deleted project' do
let(:issue_b) { create :issue, project: project }
let!(:related_issue) do
create(:related_issue, issue: issue, related_issue: issue_b)
end
it 'ignores issue' do
project.destroy!
is_expected.to eq([])
end
end
context 'when referenced an issue with deleted namespace' do
let(:issue_b) { create :issue, project: project }
let!(:related_issue) do
create(:related_issue, issue: issue, related_issue: issue_b)
end
it 'ignores issue' do
project.namespace.destroy!
is_expected.to eq([])
end
end
end
context 'user cannot see relations' do
context 'when user cannot see the referenced issue' do
let!(:related_issue) do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment