mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-01 21:47:16 +00:00
Refresh products cache when exchange fee is changed or destroyed
This commit is contained in:
@@ -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
|
||||
|
||||
19
spec/models/exchange_fee_spec.rb
Normal file
19
spec/models/exchange_fee_spec.rb
Normal 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
|
||||
Reference in New Issue
Block a user