From a42799dff495a7c82abfefdedde0fa81d80e4055 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 14 Jun 2017 16:28:55 +1000 Subject: [PATCH] Initialise `product.variant_names` Not initialising `product.variant_names` causes it to become the string "undefinedVariant1Variant2" while it should just be "Variant1Variant2". This mistake did not matter when `variant_names` was just used to search for a sub-string. A recent change to search only for the beginning of a word, caused this to fail. See: https://github.com/openfoodfoundation/openfoodnetwork/pull/1545 --- .../javascripts/darkswarm/services/products.js.coffee | 1 + .../unit/darkswarm/services/products_spec.js.coffee | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/app/assets/javascripts/darkswarm/services/products.js.coffee b/app/assets/javascripts/darkswarm/services/products.js.coffee index 63e015e5ba..a6b5292f0d 100644 --- a/app/assets/javascripts/darkswarm/services/products.js.coffee +++ b/app/assets/javascripts/darkswarm/services/products.js.coffee @@ -42,6 +42,7 @@ Darkswarm.factory 'Products', ($resource, Enterprises, Dereferencer, Taxons, Pro registerVariants: -> for product in @products if product.variants + product.variant_names = "" product.variants = for variant in product.variants variant = Variants.register variant if product.name != variant.name_to_display diff --git a/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee index c5f9d64f12..57320fbb1b 100644 --- a/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/products_spec.js.coffee @@ -82,6 +82,12 @@ describe 'Products service', -> $httpBackend.flush() expect(Products.products[0].variants[0]).toBe Variants.variants[1] + it "stores variant names", -> + product.variants = [{id: 1, name_to_display: "one"}, {id: 2, name_to_display: "two"}] + $httpBackend.expectGET("/shop/products").respond([product]) + $httpBackend.flush() + expect(Products.products[0].variant_names).toEqual "onetwo" + it "sets primaryImageOrMissing when no images are provided", -> $httpBackend.expectGET("/shop/products").respond([product]) $httpBackend.flush()