diff --git a/app/assets/javascripts/admin/bulk_order_management.js.coffee b/app/assets/javascripts/admin/bulk_order_management.js.coffee index 03ca6cbbde..f8369a063f 100644 --- a/app/assets/javascripts/admin/bulk_order_management.js.coffee +++ b/app/assets/javascripts/admin/bulk_order_management.js.coffee @@ -42,7 +42,15 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [ $scope.resetLineItems = -> $scope.lineItems = $scope.orders.reduce (lineItems,order) -> for i,line_item of order.line_items + $scope.matchSupplier line_item line_item.order = order lineItems.concat order.line_items , [] + + $scope.matchSupplier = (line_item) -> + for i of $scope.suppliers + supplier = $scope.suppliers[i] + if angular.equals(supplier, line_item.supplier) + line_item.supplier = supplier + break ] \ No newline at end of file diff --git a/spec/features/admin/bulk_order_management_spec.rb b/spec/features/admin/bulk_order_management_spec.rb index 85c55d6bf2..d9e63dd0e6 100644 --- a/spec/features/admin/bulk_order_management_spec.rb +++ b/spec/features/admin/bulk_order_management_spec.rb @@ -59,8 +59,8 @@ feature %q{ it "displays a column for producer" do page.should have_selector "th.producer", text: "PRODUCER", :visible => true - page.should have_selector "td.producer", text: li1.supplier.name, :visible => true - page.should have_selector "td.producer", text: li2.supplier.name, :visible => true + page.should have_selector "td.producer", text: li1.product.supplier.name, :visible => true + page.should have_selector "td.producer", text: li2.product.supplier.name, :visible => true end end end diff --git a/spec/javascripts/unit/bulk_order_management_spec.js.coffee b/spec/javascripts/unit/bulk_order_management_spec.js.coffee index c3c843fedb..27cc3d870a 100644 --- a/spec/javascripts/unit/bulk_order_management_spec.js.coffee +++ b/spec/javascripts/unit/bulk_order_management_spec.js.coffee @@ -36,19 +36,21 @@ describe "AdminOrderMgmtCtrl", -> expect(scope.resetOrders).toHaveBeenCalledWith "list of orders" describe "resetting orders", -> - it "sets the value of $scope.orders to the data received", -> + beforeEach -> + spyOn(scope, "resetLineItems").andReturn "nothing" scope.resetOrders "list of orders" + + it "sets the value of $scope.orders to the data received", -> expect(scope.orders).toEqual "list of orders" it "makes a call to $scope.resetLineItems", -> - spyOn scope, "resetLineItems" - scope.resetOrders "list of orders" expect(scope.resetLineItems).toHaveBeenCalled() describe "resetting line items", -> order1 = order2 = order3 = null beforeEach -> + spyOn(scope, "matchSupplier").andReturn "nothing" order1 = { line_items: [ { name: "line_item1.1" }, { name: "line_item1.1" }, { name: "line_item1.1" } ] } order2 = { line_items: [ { name: "line_item2.1" }, { name: "line_item2.1" }, { name: "line_item2.1" } ] } order3 = { line_items: [ { name: "line_item3.1" }, { name: "line_item3.1" }, { name: "line_item3.1" } ] } @@ -64,4 +66,33 @@ describe "AdminOrderMgmtCtrl", -> it "adds a reference to the parent order to each line item", -> expect(scope.lineItems[0].order).toEqual order1 expect(scope.lineItems[3].order).toEqual order2 - expect(scope.lineItems[6].order).toEqual order3 \ No newline at end of file + expect(scope.lineItems[6].order).toEqual order3 + + it "calls matchSupplier for each line item", -> + expect(scope.matchSupplier.calls.length).toEqual 9 + + describe "matching supplier", -> + it "changes the supplier of the line_item to the one which matches it from the suppliers list", -> + s1_s = + id: 1 + name: "S1" + + s2_s = + id: 2 + name: "S2" + + s1_l = + id: 1 + name: "S1" + + expect(s1_s is s1_l).not.toEqual true + scope.suppliers = [ + s1_s + s2_s + ] + line_item = + id: 10 + supplier: s1_l + + scope.matchSupplier line_item + expect(line_item.supplier is s1_s).toEqual true \ No newline at end of file diff --git a/spec/javascripts/unit/bulk_product_update_spec.js.coffee b/spec/javascripts/unit/bulk_product_update_spec.js.coffee index 2f5857e7f3..72096f6fb1 100644 --- a/spec/javascripts/unit/bulk_product_update_spec.js.coffee +++ b/spec/javascripts/unit/bulk_product_update_spec.js.coffee @@ -393,7 +393,7 @@ describe "AdminProductEditCtrl", -> supplier: s1_p scope.matchSupplier product - expect(product.supplier).toEqual s1_s + expect(product.supplier is s1_s).toEqual true describe "loading variant unit", ->