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

Filter out deleted issues

parent b9b273ac
...@@ -31,11 +31,11 @@ module RelatedIssues ...@@ -31,11 +31,11 @@ module RelatedIssues
<<-SQL.strip_heredoc <<-SQL.strip_heredoc
SELECT issues.*, related_issues.id as related_issues_id FROM issues SELECT issues.*, related_issues.id as related_issues_id FROM issues
INNER JOIN related_issues ON related_issues.related_issue_id = issues.id 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 UNION ALL
SELECT issues.*, related_issues.id as related_issues_id FROM issues SELECT issues.*, related_issues.id as related_issues_id FROM issues
INNER JOIN related_issues ON related_issues.issue_id = issues.id 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 ORDER BY related_issues_id
SQL SQL
) )
......
...@@ -37,7 +37,7 @@ describe RelatedIssues::ListService, service: true do ...@@ -37,7 +37,7 @@ describe RelatedIssues::ListService, service: true do
it 'verifies number of queries' do it 'verifies number of queries' do
recorded = ActiveRecord::QueryRecorder.new { subject } recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.count).to be_within(1).of(39) expect(recorded.count).to be_within(1).of(42)
end end
it 'returns related issues JSON' do it 'returns related issues JSON' do
...@@ -84,6 +84,47 @@ describe RelatedIssues::ListService, service: true do ...@@ -84,6 +84,47 @@ describe RelatedIssues::ListService, service: true do
end end
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 'user cannot see relations' do
context 'when user cannot see the referenced issue' do context 'when user cannot see the referenced issue' do
let!(:related_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