mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Inject #updated_ids to strategy
Their values are known beforehand.
This commit is contained in:
@@ -81,7 +81,7 @@ module ProductImport
|
||||
end
|
||||
|
||||
def strategy
|
||||
@strategy ||= strategy_factory.new
|
||||
@strategy ||= strategy_factory.new(settings.updated_ids)
|
||||
end
|
||||
|
||||
def total_saved_count
|
||||
|
||||
@@ -2,16 +2,16 @@ module ProductImport
|
||||
class InventoryReset
|
||||
attr_reader :supplier_ids
|
||||
|
||||
def initialize
|
||||
def initialize(updated_ids)
|
||||
@supplier_ids = []
|
||||
@updated_ids = updated_ids
|
||||
end
|
||||
|
||||
def <<(values)
|
||||
@supplier_ids << values
|
||||
end
|
||||
|
||||
def reset(updated_ids)
|
||||
@updated_ids = updated_ids
|
||||
def reset
|
||||
relation.update_all(count_on_hand: 0)
|
||||
end
|
||||
|
||||
|
||||
@@ -2,16 +2,16 @@ module ProductImport
|
||||
class ProductsReset
|
||||
attr_reader :supplier_ids
|
||||
|
||||
def initialize
|
||||
def initialize(updated_ids)
|
||||
@supplier_ids = []
|
||||
@updated_ids = updated_ids
|
||||
end
|
||||
|
||||
def <<(values)
|
||||
@supplier_ids << values
|
||||
end
|
||||
|
||||
def reset(updated_ids)
|
||||
@updated_ids = updated_ids
|
||||
def reset
|
||||
relation.update_all(count_on_hand: 0)
|
||||
end
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ module ProductImport
|
||||
attr_reader :settings, :strategy, :entry_processor
|
||||
|
||||
def reset_stock
|
||||
@products_reset_count += strategy.reset(settings.updated_ids)
|
||||
@products_reset_count += strategy.reset
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,8 +13,7 @@ module ProductImport
|
||||
let(:settings) do
|
||||
instance_double(
|
||||
Settings,
|
||||
enterprises_to_reset: [],
|
||||
updated_ids: []
|
||||
enterprises_to_reset: []
|
||||
)
|
||||
end
|
||||
|
||||
@@ -27,13 +26,12 @@ module ProductImport
|
||||
end
|
||||
end
|
||||
|
||||
context 'when there are updated_ids and enterprises_to_reset' do
|
||||
context 'when there are enterprises_to_reset' do
|
||||
let(:enterprise) { instance_double(Enterprise, id: 1) }
|
||||
|
||||
let(:settings) do
|
||||
instance_double(
|
||||
Settings,
|
||||
updated_ids: [0],
|
||||
enterprises_to_reset: [enterprise.id.to_s]
|
||||
)
|
||||
end
|
||||
@@ -46,7 +44,7 @@ module ProductImport
|
||||
|
||||
allow(strategy).to receive(:<<).with(enterprise.id)
|
||||
allow(strategy).to receive(:supplier_ids) { [enterprise.id] }
|
||||
allow(strategy).to receive(:reset).with([0]) { 2 }
|
||||
allow(strategy).to receive(:reset) { 2 }
|
||||
end
|
||||
|
||||
it 'returns the number of products reset' do
|
||||
@@ -54,7 +52,7 @@ module ProductImport
|
||||
end
|
||||
|
||||
it 'resets the products of the specified suppliers' do
|
||||
expect(strategy).to receive(:reset).with([0]) { 2 }
|
||||
expect(strategy).to receive(:reset) { 2 }
|
||||
reset_absent.call
|
||||
end
|
||||
end
|
||||
@@ -65,7 +63,6 @@ module ProductImport
|
||||
let(:settings) do
|
||||
instance_double(
|
||||
Settings,
|
||||
updated_ids: [0],
|
||||
enterprises_to_reset: [enterprise.id.to_s]
|
||||
)
|
||||
end
|
||||
@@ -92,7 +89,6 @@ module ProductImport
|
||||
let(:settings) do
|
||||
instance_double(
|
||||
Settings,
|
||||
updated_ids: [0],
|
||||
enterprises_to_reset: [enterprise.id.to_s]
|
||||
)
|
||||
end
|
||||
@@ -105,7 +101,7 @@ module ProductImport
|
||||
|
||||
allow(strategy).to receive(:<<).with(enterprise.id)
|
||||
allow(strategy).to receive(:supplier_ids) { [enterprise.id] }
|
||||
allow(strategy).to receive(:reset).with([0]) { 1 }
|
||||
allow(strategy).to receive(:reset) { 1 }
|
||||
end
|
||||
|
||||
it 'returns the number of reset variant overrides' do
|
||||
|
||||
Reference in New Issue
Block a user