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