From 7caebb11e2f3052f742bd7530143e2a47c1cc28c Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Tue, 28 Jul 2015 12:00:40 +1000 Subject: [PATCH] Clear variants registry before reloading products - fixes fees not updating when changing order cycle --- .../darkswarm/services/products.js.coffee | 10 +++++++-- .../consumer/shopping/shopping_spec.rb | 21 +++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/darkswarm/services/products.js.coffee b/app/assets/javascripts/darkswarm/services/products.js.coffee index 9dd76cb7e2..4a415bba24 100644 --- a/app/assets/javascripts/darkswarm/services/products.js.coffee +++ b/app/assets/javascripts/darkswarm/services/products.js.coffee @@ -10,8 +10,14 @@ Darkswarm.factory 'Products', ($resource, Enterprises, Dereferencer, Taxons, Pro update: => @loading = true - @products = $resource("/shop/products").query (products)=> - @extend() && @dereference() + @products = [] + $resource("/shop/products").query (products)=> + Variants.clear() + + @products = products + + @extend() + @dereference() @registerVariants() @registerVariantsWithCart() @loading = false diff --git a/spec/features/consumer/shopping/shopping_spec.rb b/spec/features/consumer/shopping/shopping_spec.rb index 5f2ae3d6c4..01ace904b4 100644 --- a/spec/features/consumer/shopping/shopping_spec.rb +++ b/spec/features/consumer/shopping/shopping_spec.rb @@ -42,7 +42,7 @@ feature "As a consumer I want to shop with a distributor", js: true do end describe "selecting an order cycle" do - let(:exchange1) { Exchange.find(oc1.exchanges.to_enterprises(distributor).outgoing.first.id) } + let(:exchange1) { oc1.exchanges.to_enterprises(distributor).outgoing.first } it "selects an order cycle if only one is open" do exchange1.update_attribute :pickup_time, "turtles" @@ -51,7 +51,8 @@ feature "As a consumer I want to shop with a distributor", js: true do end describe "with multiple order cycles" do - let(:exchange2) { Exchange.find(oc2.exchanges.to_enterprises(distributor).outgoing.first.id) } + let(:exchange2) { oc2.exchanges.to_enterprises(distributor).outgoing.first } + before do exchange1.update_attribute :pickup_time, "frogs" exchange2.update_attribute :pickup_time, "turtles" @@ -83,6 +84,22 @@ feature "As a consumer I want to shop with a distributor", js: true do open_product_modal product modal_should_be_open_for product end + + it "shows the correct fees after selecting and changing an order cycle" do + enterprise_fee = create(:enterprise_fee, amount: 1001) + exchange2.enterprise_fees << enterprise_fee + exchange2.variants << variant + exchange1.variants << variant + + # -- Selecting an order cycle + visit shop_path + select "turtles", from: "order_cycle_id" + page.should have_content "$1020.99" + + # -- Changing order cycle + select "frogs", from: "order_cycle_id" + page.should have_content "$19.99" + end end end