mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Do not retry when refreshing cache on deleted OC
This commit is contained in:
@@ -3,6 +3,8 @@ require 'open_food_network/products_renderer'
|
||||
RefreshProductsCacheJob = Struct.new(:distributor_id, :order_cycle_id) do
|
||||
def perform
|
||||
Rails.cache.write(key, products_json)
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -5,12 +5,34 @@ describe RefreshProductsCacheJob do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:order_cycle) { create(:simple_order_cycle) }
|
||||
|
||||
it "renders products and writes them to cache" do
|
||||
RefreshProductsCacheJob.any_instance.stub(:products_json) { 'products' }
|
||||
context 'when the enterprise and the order cycle exist' do
|
||||
it "renders products and writes them to cache" do
|
||||
RefreshProductsCacheJob.any_instance.stub(:products_json) { 'products' }
|
||||
|
||||
run_job RefreshProductsCacheJob.new distributor.id, order_cycle.id
|
||||
run_job RefreshProductsCacheJob.new distributor.id, order_cycle.id
|
||||
|
||||
expect(Rails.cache.read("products-json-#{distributor.id}-#{order_cycle.id}")).to eq 'products'
|
||||
expect(Rails.cache.read("products-json-#{distributor.id}-#{order_cycle.id}")).to eq 'products'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the order cycle does not exist' do
|
||||
before do
|
||||
allow(OrderCycle)
|
||||
.to receive(:find)
|
||||
.with(order_cycle.id)
|
||||
.and_raise(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it 'does not raise' do
|
||||
expect {
|
||||
run_job RefreshProductsCacheJob.new(distributor.id, order_cycle.id)
|
||||
}.not_to raise_error(/ActiveRecord::RecordNotFound/)
|
||||
end
|
||||
|
||||
it 'returns true' do
|
||||
refresh_products_cache_job = RefreshProductsCacheJob.new(distributor.id, order_cycle.id)
|
||||
expect(refresh_products_cache_job.perform).to eq(true)
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetching products JSON" do
|
||||
|
||||
Reference in New Issue
Block a user