mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Update ScopeVariantsForSearch logic to match both product and variant SKUs
This commit is contained in:
@@ -28,7 +28,7 @@ module Spree
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
searchable_attributes :supplier_id, :primary_taxon_id, :meta_keywords
|
||||
searchable_attributes :supplier_id, :primary_taxon_id, :meta_keywords, :sku
|
||||
searchable_associations :supplier, :properties, :primary_taxon, :variants
|
||||
searchable_scopes :active, :with_properties
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ module OpenFoodNetwork
|
||||
attr_reader :params
|
||||
|
||||
def search_params
|
||||
{ product_name_cont: params[:q], sku_cont: params[:q] }
|
||||
{ product_name_cont: params[:q], sku_cont: params[:q], product_sku_cont: params[:q] }
|
||||
end
|
||||
|
||||
def query_scope
|
||||
|
||||
@@ -30,8 +30,17 @@ describe OpenFoodNetwork::ScopeVariantsForSearch do
|
||||
let(:params) { { q: "product 1" } }
|
||||
|
||||
it "returns all products whose names or SKUs match the query" do
|
||||
expect(result).to include v1
|
||||
expect(result).to_not include v2, v3, v4
|
||||
expect(result).to include v1, v2
|
||||
expect(result).to_not include v3, v4
|
||||
end
|
||||
|
||||
context "matching both product SKUs and variant SKUs" do
|
||||
let!(:v5) { create(:variant, sku: "Product 1b") }
|
||||
|
||||
it "returns all variants whose SKU or product's SKU match the query" do
|
||||
expect(result).to include v1, v2, v5
|
||||
expect(result).to_not include v3, v4
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user