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.
This commit is contained in:
Pau Perez
2019-03-22 09:37:20 +01:00
parent fbc3fc6a51
commit b293e00777

View File

@@ -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