Commit 71ed81e0 authored by Felipe Artur's avatar Felipe Artur

Allow to order by blocking issues count

Allow to order issues by the number of other
issues they are blocking.
parent e4695080
...@@ -17,6 +17,7 @@ module EE ...@@ -17,6 +17,7 @@ module EE
include WeightEventable include WeightEventable
include HealthStatus 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_desc, -> { reorder ::Gitlab::Database.nulls_last_order('weight', 'DESC') }
scope :order_weight_asc, -> { reorder ::Gitlab::Database.nulls_last_order('weight') } 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 }) } scope :no_epic, -> { left_outer_joins(:epic_issue).where(epic_issues: { epic_id: nil }) }
...@@ -204,6 +205,7 @@ module EE ...@@ -204,6 +205,7 @@ module EE
override :sort_by_attribute override :sort_by_attribute
def sort_by_attribute(method, excluded_labels: []) def sort_by_attribute(method, excluded_labels: [])
case method.to_s 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', 'weight_asc' then order_weight_asc.with_order_id_desc
when 'weight_desc' then order_weight_desc.with_order_id_desc when 'weight_desc' then order_weight_desc.with_order_id_desc
else else
......
...@@ -358,6 +358,18 @@ RSpec.describe Issue do ...@@ -358,6 +358,18 @@ RSpec.describe Issue do
end end
end 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 end
describe '#weight' do 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