From b293e00777dfbf6e1b49515b756face7278616e7 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Fri, 22 Mar 2019 09:37:20 +0100 Subject: [PATCH] Test that we refresh the cache on variant destroy These tests prove that https://github.com/openfoodfoundation/openfoodnetwork/issues/3629 is indeed is a bug because we don't refresh the cache when deleting a variant. --- .../spree/admin/variants_controller_spec.rb | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/controllers/spree/admin/variants_controller_spec.rb b/spec/controllers/spree/admin/variants_controller_spec.rb index d34444026d..8846d80e22 100644 --- a/spec/controllers/spree/admin/variants_controller_spec.rb +++ b/spec/controllers/spree/admin/variants_controller_spec.rb @@ -59,6 +59,19 @@ module Spree spree_delete :destroy, id: variant.id, product_id: variant.product.permalink, format: 'js' expect(response).to render_template('spree/admin/shared/_destroy') end + + it 'refreshes the cache' do + expect(OpenFoodNetwork::ProductsCache).to receive(:variant_destroyed).with(variant) + spree_delete :destroy, id: variant.id, product_id: variant.product.permalink, format: 'js' + end + + it 'destroys all its exchanges' do + exchange = create(:exchange) + variant.exchanges << exchange + + spree_delete :destroy, id: variant.id, product_id: variant.product.permalink, format: 'js' + expect(variant.exchanges).to be_empty + end end context 'when requesting with html' do @@ -85,6 +98,19 @@ module Spree product_id: variant.product.permalink ) end + + it 'refreshes the cache' do + expect(OpenFoodNetwork::ProductsCache).to receive(:variant_destroyed).with(variant) + spree_delete :destroy, id: variant.id, product_id: variant.product.permalink, format: 'js' + end + + it 'destroys all its exchanges' do + exchange = create(:exchange) + variant.exchanges << exchange + + spree_delete :destroy, id: variant.id, product_id: variant.product.permalink, format: 'js' + expect(variant.exchanges).to be_empty + end end end end