Refresh products cache when exchange fee is changed or destroyed

This commit is contained in:
Rohan Mitchell
2016-02-05 10:40:27 +11:00
parent 8af6866ae4
commit 8b070fddbb
2 changed files with 30 additions and 0 deletions

View File

@@ -1,4 +1,15 @@
class ExchangeFee < ActiveRecord::Base
belongs_to :exchange
belongs_to :enterprise_fee
after_save :refresh_products_cache
after_destroy :refresh_products_cache
private
def refresh_products_cache
exchange.refresh_products_cache
end
end

View File

@@ -0,0 +1,19 @@
require 'spec_helper'
describe ExchangeFee do
describe "products caching" do
let(:exchange) { create(:exchange) }
let(:enterprise_fee) { create(:enterprise_fee) }
it "refreshes the products cache on change" do
expect(OpenFoodNetwork::ProductsCache).to receive(:exchange_changed).with(exchange)
exchange.enterprise_fees << enterprise_fee
end
it "refreshes the products cache on destruction" do
exchange.enterprise_fees << enterprise_fee
expect(OpenFoodNetwork::ProductsCache).to receive(:exchange_changed).with(exchange)
exchange.reload.exchange_fees.destroy_all
end
end
end