Commit 1ea531ad authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'issue_34247' into 'master'

Allow to order by blocking issues count

See merge request gitlab-org/gitlab!34665
parents 81e42621 71ed81e0
......@@ -17,6 +17,7 @@ module EE
include WeightEventable
include HealthStatus
scope :order_blocking_issues_desc, -> { reorder(blocking_issues_count: :desc) }
scope :order_weight_desc, -> { reorder ::Gitlab::Database.nulls_last_order('weight', 'DESC') }
scope :order_weight_asc, -> { reorder ::Gitlab::Database.nulls_last_order('weight') }
scope :no_epic, -> { left_outer_joins(:epic_issue).where(epic_issues: { epic_id: nil }) }
......@@ -204,6 +205,7 @@ module EE
override :sort_by_attribute
def sort_by_attribute(method, excluded_labels: [])
case method.to_s
when 'blocking_issues_desc' then order_blocking_issues_desc.with_order_id_desc
when 'weight', 'weight_asc' then order_weight_asc.with_order_id_desc
when 'weight_desc' then order_weight_desc.with_order_id_desc
else
......
......@@ -358,6 +358,18 @@ RSpec.describe Issue do
end
end
end
context 'by blocking issues' do
it 'orders by descending blocking issues count' do
issue_1 = create(:issue, blocking_issues_count: 3)
issue_2 = create(:issue, blocking_issues_count: 2)
results = described_class.sort_by_attribute('blocking_issues_desc')
expect(results.first).to eq(issue_1)
expect(results.second).to eq(issue_2)
end
end
end
describe '#weight' 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