diff --git a/app/models/product_import/entry_processor.rb b/app/models/product_import/entry_processor.rb index 05ca71c8d4..8b45a2bf4f 100644 --- a/app/models/product_import/entry_processor.rb +++ b/app/models/product_import/entry_processor.rb @@ -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 diff --git a/app/models/product_import/inventory_reset.rb b/app/models/product_import/inventory_reset.rb index cd064777c2..a03a008592 100644 --- a/app/models/product_import/inventory_reset.rb +++ b/app/models/product_import/inventory_reset.rb @@ -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 diff --git a/app/models/product_import/products_reset.rb b/app/models/product_import/products_reset.rb index 7462a56523..219b656f12 100644 --- a/app/models/product_import/products_reset.rb +++ b/app/models/product_import/products_reset.rb @@ -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 diff --git a/app/models/product_import/reset_absent.rb b/app/models/product_import/reset_absent.rb index 06b2eb4c43..385b27d4ce 100644 --- a/app/models/product_import/reset_absent.rb +++ b/app/models/product_import/reset_absent.rb @@ -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 diff --git a/spec/models/product_import/reset_absent_spec.rb b/spec/models/product_import/reset_absent_spec.rb index 5ef90d8f55..e10a3a025b 100644 --- a/spec/models/product_import/reset_absent_spec.rb +++ b/spec/models/product_import/reset_absent_spec.rb @@ -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