From a67c7b808dbc35c5cc1a30fb35d11a8e7938898a Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 12 Dec 2013 10:50:03 +1100 Subject: [PATCH] Do not set unit value or description on variant when unpacked field is undefined --- .../javascripts/admin/bulk_product_update.js.coffee | 9 +++++---- spec/javascripts/unit/bulk_product_update_spec.js.coffee | 5 +++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/admin/bulk_product_update.js.coffee b/app/assets/javascripts/admin/bulk_product_update.js.coffee index d18c48b771..c44f1c954a 100644 --- a/app/assets/javascripts/admin/bulk_product_update.js.coffee +++ b/app/assets/javascripts/admin/bulk_product_update.js.coffee @@ -295,10 +295,11 @@ productsApp.controller "AdminBulkProductsCtrl", [ $scope.packVariant = (variant) -> - match = variant.unit_value_with_description.match(/^([\d\.]+|)( |)(.*)$/) - if match - variant.unit_value = parseFloat(match[1]) || null - variant.unit_description = match[3] + if variant.hasOwnProperty("unit_value_with_description") + match = variant.unit_value_with_description.match(/^([\d\.]+|)( |)(.*)$/) + if match + variant.unit_value = parseFloat(match[1]) || null + variant.unit_description = match[3] $scope.productsWithoutDerivedAttributes = -> diff --git a/spec/javascripts/unit/bulk_product_update_spec.js.coffee b/spec/javascripts/unit/bulk_product_update_spec.js.coffee index 1728fcc4e8..bed0687231 100644 --- a/spec/javascripts/unit/bulk_product_update_spec.js.coffee +++ b/spec/javascripts/unit/bulk_product_update_spec.js.coffee @@ -552,6 +552,11 @@ describe "AdminBulkProductsCtrl", -> unit_description: '' unit_value_with_description: "" + it "sets nothing when the field is undefined", -> + testVariant = {} + scope.packVariant(testVariant) + expect(testVariant).toEqual {} + describe "filtering products", -> beforeEach ->