From d8dd84e64e171874c4c27e16c3f46334676253a1 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Tue, 20 Mar 2018 17:18:57 +0100 Subject: [PATCH] Fix enterprise filter in customers page Angular's filter function uses a pattern object to filter specific properties on objects contained by the array. We want an exact match instead, which has to be done by means of a function. --- .../controllers/customers_controller.js.coffee | 2 +- .../controllers/customers_controller_spec.js.coffee | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/admin/customers/controllers/customers_controller.js.coffee b/app/assets/javascripts/admin/customers/controllers/customers_controller.js.coffee index 2506e994ac..d4ba6383d8 100644 --- a/app/assets/javascripts/admin/customers/controllers/customers_controller.js.coffee +++ b/app/assets/javascripts/admin/customers/controllers/customers_controller.js.coffee @@ -12,7 +12,7 @@ angular.module("admin.customers").controller "customersCtrl", ($scope, $q, $filt $scope.$watch "shop_id", -> if $scope.shop_id? - CurrentShop.shop = $filter('filter')($scope.shops, {id: $scope.shop_id})[0] + CurrentShop.shop = $filter('filter')($scope.shops, {id: parseInt($scope.shop_id)}, true)[0] Customers.index({enterprise_id: $scope.shop_id}).then (data) -> pendingChanges.removeAll() $scope.customers_form.$setPristine() diff --git a/spec/javascripts/unit/admin/customers/controllers/customers_controller_spec.js.coffee b/spec/javascripts/unit/admin/customers/controllers/customers_controller_spec.js.coffee index ce4b967f90..a30eb4eeb8 100644 --- a/spec/javascripts/unit/admin/customers/controllers/customers_controller_spec.js.coffee +++ b/spec/javascripts/unit/admin/customers/controllers/customers_controller_spec.js.coffee @@ -10,9 +10,10 @@ describe "CustomersCtrl", -> null shops = [ - { name: "Shop 1", id: 1 } - { name: "Shop 2", id: 2 } - { name: "Shop 3", id: 3 } + { name: "Shop 1", id: 1 }, + { name: "Shop 2", id: 12 }, + { name: "Shop 3", id: 2 }, + { name: "Shop 4", id: 3 } ] availableCountries = [ @@ -39,9 +40,9 @@ describe "CustomersCtrl", -> beforeEach inject (pendingChanges) -> spyOn(pendingChanges, "removeAll") scope.customers_form = jasmine.createSpyObj('customers_form', ['$setPristine']) - http.expectGET('/admin/customers.json?enterprise_id=3').respond 200, customers + http.expectGET('/admin/customers.json?enterprise_id=2').respond 200, customers scope.$apply -> - scope.shop_id = 3 + scope.shop_id = "2" http.flush() it "sets the CurrentShop", inject (CurrentShop) -> @@ -81,7 +82,7 @@ describe "CustomersCtrl", -> { text: 'three' } ] beforeEach -> - http.expectGET('/admin/tag_rules/map_by_tag.json?enterprise_id=3').respond 200, tags + http.expectGET('/admin/tag_rules/map_by_tag.json?enterprise_id=2').respond 200, tags it "retrieves the tag list", -> promise = scope.findTags('')