Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Make Splitter::Base.build_package and Shipment.to_package use Config::package_factory #39

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/app/models/spree/shipment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def inventory_units_for(variant)
end

def to_package
package = Stock::Package.new(stock_location, order)
package = Spree::Config.package_factory.new(stock_location, order)
inventory_units.includes(:variant).each do |inventory_unit|
package.add inventory_unit.variant, 1, inventory_unit.state_name
end
Expand Down
4 changes: 1 addition & 3 deletions core/app/models/spree/stock/packer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Spree
module Stock
class Packer
attr_reader :stock_location, :order, :splitters
attr_reader :stock_location, :order, :splitters, :package_factory

def initialize(stock_location, order, splitters=[Splitter::Base])
@stock_location = stock_location
Expand All @@ -28,8 +28,6 @@ def default_package

private

attr_reader :package_factory

def build_splitter
splitter = nil
splitters.reverse.each do |klass|
Expand Down
3 changes: 2 additions & 1 deletion core/app/models/spree/stock/splitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ def split(packages)
end

private

def return_next(packages)
next_splitter ? next_splitter.split(packages) : packages
end

def build_package(contents=[])
Spree::Stock::Package.new(stock_location, order, contents)
@packer.package_factory.new(stock_location, order, contents)
end
end
end
Expand Down
16 changes: 16 additions & 0 deletions core/spec/models/spree/stock/splitter/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ module Splitter
splitter2.split(packages)
end

it 'builds package using package factory' do
# Basic extension of Base splitter used to test build_package method
class ::BasicSplitter < Base
def split(packages)
build_package
end
end

# Custom package used to test setting package factory
class ::CustomPackage
def initialize(stock_location, order, splitters); end
end
allow(Spree::Config).to receive(:package_factory) { CustomPackage }

expect(::BasicSplitter.new(packer).split(nil).class).to eq CustomPackage
end
end
end
end
Expand Down