diff --git a/app/assets/javascripts/darkswarm/controllers/order_cycle_controller.js.coffee b/app/assets/javascripts/darkswarm/controllers/order_cycle_controller.js.coffee index 3fec7cfe9d..9c2baccda9 100644 --- a/app/assets/javascripts/darkswarm/controllers/order_cycle_controller.js.coffee +++ b/app/assets/javascripts/darkswarm/controllers/order_cycle_controller.js.coffee @@ -1,5 +1,3 @@ -# TODO this SUCKS. Fix it - Darkswarm.controller "OrderCycleCtrl", ($scope, $timeout, OrderCycle) -> $scope.order_cycle = OrderCycle.order_cycle $scope.OrderCycle = OrderCycle @@ -12,12 +10,15 @@ Darkswarm.controller "OrderCycleCtrl", ($scope, $timeout, OrderCycle) -> $("#order_cycle_id").trigger("openTrigger") -Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $timeout, OrderCycle, Products, Variants) -> +Darkswarm.controller "OrderCycleChangeCtrl", ($scope, $timeout, OrderCycle, Products, Variants, Cart) -> $scope.changeOrderCycle = -> OrderCycle.push_order_cycle $scope.orderCycleChanged $timeout -> $("#order_cycle_id").trigger("closeTrigger") $scope.orderCycleChanged = -> + # push_order_cycle clears the cart server-side. Here we call Cart.clear() to clear the + # client-side cart. Variants.clear() + Cart.clear() Products.update() diff --git a/app/assets/javascripts/darkswarm/services/products.js.coffee b/app/assets/javascripts/darkswarm/services/products.js.coffee index 3bd0b35e8f..475ed5be0b 100644 --- a/app/assets/javascripts/darkswarm/services/products.js.coffee +++ b/app/assets/javascripts/darkswarm/services/products.js.coffee @@ -19,7 +19,6 @@ Darkswarm.factory 'Products', ($resource, Enterprises, Dereferencer, Taxons, Pro @registerVariants() @registerVariantsWithCart() @loading = false - @ extend: -> for product in @products diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index 01ace904b4..dafc8daad9 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -96,9 +96,21 @@ feature "As a consumer I want to shop with a distributor", js: true do select "turtles", from: "order_cycle_id" page.should have_content "$1020.99" + # -- Cart shows correct price + fill_in "variants[#{variant.id}]", with: 1 + show_cart + within("li.cart") { page.should have_content "$1020.99" } + # -- Changing order cycle select "frogs", from: "order_cycle_id" page.should have_content "$19.99" + + # -- Cart should be cleared + # ng-animate means that the old product row is likely to be present, so we explicitly + # fill in the quantity in the incoming row + page.should_not have_selector "tr.product-cart" + within('product.ng-enter') { fill_in "variants[#{variant.id}]", with: 1 } + within("li.cart") { page.should have_content "$19.99" } end end end