Skip to content

Commit fd683f1

Browse files
committed
order backlog bucket work packages by position
1 parent 08876ca commit fd683f1

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

modules/backlogs/app/models/agile/backlog_bucket.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Agile::BacklogBucket < ApplicationRecord
3232
self.table_name = "backlog_buckets"
3333

3434
belongs_to :project
35-
has_many :work_packages, inverse_of: :backlog_bucket, dependent: :nullify
35+
has_many :work_packages, -> { order_by_position }, inverse_of: :backlog_bucket, dependent: :nullify
3636

3737
validates :name, :project, presence: true
3838
end

modules/backlogs/spec/models/agile/backlog_bucket_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,13 @@
6060
backlog_bucket.destroy!
6161
expect(WorkPackage.find(work_package_id).backlog_bucket_id).to be_nil
6262
end
63+
64+
it "orders work packages by position" do
65+
work_package_nil = create(:work_package, project:, backlog_bucket:).tap { it.update_columns(position: nil) }
66+
work_package2 = create(:work_package, project:, backlog_bucket:, position: 2)
67+
work_package1 = create(:work_package, project:, backlog_bucket:, position: 1)
68+
69+
expect(backlog_bucket.work_packages.reload.to_a).to eq([work_package1, work_package2, work_package_nil])
70+
end
6371
end
6472
end

0 commit comments

Comments
 (0)