mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-13 18:46:49 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f2df6a941 | ||
|
|
278147b81f | ||
|
|
7ea10f6d98 | ||
|
|
545c7c99ed | ||
|
|
cc3a0877c4 | ||
|
|
bb12592a74 | ||
|
|
f951ebe178 | ||
|
|
bcc21cdade |
@@ -3,7 +3,14 @@ require 'open_food_network/products_cache_integrity_checker'
|
||||
ProductsCacheIntegrityCheckerJob = Struct.new(:distributor_id, :order_cycle_id) do
|
||||
def perform
|
||||
unless checker.ok?
|
||||
Bugsnag.notify RuntimeError.new("Products JSON differs from cached version for distributor: #{distributor_id}, order cycle: #{order_cycle_id}"), diff: checker.diff.to_s(:text)
|
||||
exception = RuntimeError.new(
|
||||
"Products JSON differs from cached version for distributor: #{distributor_id}, " \
|
||||
"order cycle: #{order_cycle_id}"
|
||||
)
|
||||
|
||||
Bugsnag.notify(exception) do |report|
|
||||
report.add_tab(:products_cache, diff: checker.diff.to_s(:text))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
7
app/models/spree/stock_item_decorator.rb
Normal file
7
app/models/spree/stock_item_decorator.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
Spree::StockItem.class_eval do
|
||||
after_save :refresh_products_cache
|
||||
|
||||
def refresh_products_cache
|
||||
OpenFoodNetwork::ProductsCache.variant_changed(variant)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class UpdateStockLocationsBackorderableDefault < ActiveRecord::Migration
|
||||
def change
|
||||
Spree::StockLocation.update_all(backorderable_default: false)
|
||||
end
|
||||
end
|
||||
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20190501143327) do
|
||||
ActiveRecord::Schema.define(:version => 20190506194625) do
|
||||
|
||||
create_table "adjustment_metadata", :force => true do |t|
|
||||
t.integer "adjustment_id"
|
||||
|
||||
10
spec/models/spree/stock_item_spec.rb
Normal file
10
spec/models/spree/stock_item_spec.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::StockItem do
|
||||
let!(:variant) { create(:variant) }
|
||||
|
||||
it 'refreshes the products cache on save' do
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:variant_changed).with(variant)
|
||||
variant.on_hand = -2
|
||||
end
|
||||
end
|
||||
@@ -166,7 +166,8 @@ module Spree
|
||||
let(:variant) { create(:variant) }
|
||||
|
||||
it "refreshes the products cache on save" do
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:variant_changed).with(variant)
|
||||
# When creating the variant both the Variant and StockItem callbacks get executed
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:variant_changed).with(variant).twice
|
||||
variant.sku = 'abc123'
|
||||
variant.save
|
||||
end
|
||||
@@ -182,7 +183,8 @@ module Spree
|
||||
|
||||
it "refreshes the products cache for the entire product on save" do
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:product_changed).with(product)
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:variant_changed).never
|
||||
# The StockItem callback is still executed
|
||||
expect(OpenFoodNetwork::ProductsCache).to receive(:variant_changed).once
|
||||
master.sku = 'abc123'
|
||||
master.save
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user