From 8b93050bc88896f1fe1a8bb43d7778fccce276e0 Mon Sep 17 00:00:00 2001 From: amanbhargav <66465174+amanbhargav@users.noreply.github.com> Date: Sat, 20 Jul 2024 11:17:24 +0530 Subject: [PATCH 1/2] [4522] Fix items order in inventory adjustment dropdown. --- app/controllers/storage_locations_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 91961d696a..5b245b43c8 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -165,6 +165,7 @@ def inventory .includes(inventory_items: :item) .find(params[:id]) .inventory_items + .alphabetized .active @inventory_items += include_omitted_items(@inventory_items.collect(&:item_id)) if params[:include_omitted_items] == "true" From c57394751db75451501b61c4fae2d1c2de02b780 Mon Sep 17 00:00:00 2001 From: amanbhargav <66465174+amanbhargav@users.noreply.github.com> Date: Sat, 27 Jul 2024 19:33:51 +0000 Subject: [PATCH 2/2] Sort inventory items alphabetically and add corresponding test. --- app/controllers/storage_locations_controller.rb | 2 +- spec/requests/storage_locations_requests_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 5b245b43c8..2a679bea92 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -165,10 +165,10 @@ def inventory .includes(inventory_items: :item) .find(params[:id]) .inventory_items - .alphabetized .active @inventory_items += include_omitted_items(@inventory_items.collect(&:item_id)) if params[:include_omitted_items] == "true" + @inventory_items.to_a.sort_by! { |inventory_item| inventory_item.item.name.downcase } respond_to :json end end diff --git a/spec/requests/storage_locations_requests_spec.rb b/spec/requests/storage_locations_requests_spec.rb index b228d15376..ded6d9943d 100644 --- a/spec/requests/storage_locations_requests_spec.rb +++ b/spec/requests/storage_locations_requests_spec.rb @@ -395,6 +395,12 @@ def item_to_h(view_item) expect(response.parsed_body).to eq(items_at_storage_location) expect(response.parsed_body).to eq(inventory_items_at_storage_location) end + + it "returns items sorted alphabetically by item name" do + get inventory_storage_location_path(storage_location, format: :json) + sorted_items = inventory_items_at_storage_location.sort_by { |item| item['item_name'].downcase } + expect(response.parsed_body).to eq(sorted_items) + end end context "when also including inactive items" do