Deal with unset distribution

This commit is contained in:
Rohan Mitchell
2016-02-04 11:41:56 +11:00
parent 235c463849
commit fa543fed63
2 changed files with 10 additions and 0 deletions

View File

@@ -14,6 +14,8 @@ module OpenFoodNetwork
end
def products_json
raise NoProducts.new if @distributor.nil? || @order_cycle.nil?
products_json = Rails.cache.fetch("products-json-#{@distributor.id}-#{@order_cycle.id}") do
log_warning

View File

@@ -8,6 +8,14 @@ module OpenFoodNetwork
let(:order_cycle) { double(:order_cycle, id: 456) }
let(:cpr) { CachedProductsRenderer.new(distributor, order_cycle) }
describe "when the distribution is not set" do
let(:cpr) { CachedProductsRenderer.new(nil, nil) }
it "raises an exception and returns no products" do
expect { cpr.products_json }.to raise_error CachedProductsRenderer::NoProducts
end
end
describe "when the products JSON is already cached" do
before do
Rails.cache.write "products-json-#{distributor.id}-#{order_cycle.id}", 'products'