From 1b6cfb60a114e35967203de2f309d90037c61275 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 2 Dec 2021 11:47:05 +0100 Subject: [PATCH] Searching variants should order results by variants display name --- .../scope_variants_to_search_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/lib/open_food_network/scope_variants_to_search_spec.rb b/spec/lib/open_food_network/scope_variants_to_search_spec.rb index 0e698012ee..d96f97d8d9 100644 --- a/spec/lib/open_food_network/scope_variants_to_search_spec.rb +++ b/spec/lib/open_food_network/scope_variants_to_search_spec.rb @@ -61,5 +61,20 @@ describe OpenFoodNetwork::ScopeVariantsForSearch do expect(result).to_not include v1, v2, v3 end end + + context "searching products starting with the same 3 caracters" do + let(:params) { { q: "pro" } } + it "returns variants ordered by display_name" do + v1.display_name = "Product 1 - b" + v2.display_name = "Product 1 - a" + v3.display_name = "Product 1 - c" + v4.display_name = "Product 1" + v1.save! + v2.save! + v3.save! + v4.save! + expect(result.map(&:display_name)).to eq ["Product 1", "Product 1 - a", "Product 1 - b", "Product 1 - c"] + end + end end end