From 9916e0f67cc911bf6d748962577e93381c60c365 Mon Sep 17 00:00:00 2001 From: amanbhargav <66465174+amanbhargav@users.noreply.github.com> Date: Thu, 1 Aug 2024 05:50:40 +0530 Subject: [PATCH] [4522] Fix items order in inventory adjustment dropdown. (#4541) * [4522] Fix items order in inventory adjustment dropdown. * Sort inventory items alphabetically and add corresponding test. --- app/controllers/storage_locations_controller.rb | 1 + spec/requests/storage_locations_requests_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 91961d696a..2a679bea92 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -168,6 +168,7 @@ def inventory .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