mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Improve failed_checkout_spec by making calculator decorator line_items_for work with new Stock::Package
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
module Spree
|
||||
Calculator.class_eval do
|
||||
|
||||
|
||||
private
|
||||
|
||||
# Given an object which might be an Order or a LineItem (amongst
|
||||
@@ -9,10 +8,11 @@ module Spree
|
||||
def line_items_for(object)
|
||||
if object.respond_to? :line_items
|
||||
object.line_items
|
||||
elsif object.respond_to? :order
|
||||
object.order.line_items
|
||||
else
|
||||
[object]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,11 +6,18 @@ describe Spree::Calculator::FlatPercentItemTotal do
|
||||
|
||||
before { calculator.stub :preferred_flat_percent => 10 }
|
||||
|
||||
it "should compute amount correctly for a single line item" do
|
||||
it "computes amount correctly for a single line item" do
|
||||
calculator.compute(line_item).should == 1.0
|
||||
end
|
||||
|
||||
context "extends LocalizedNumber" do
|
||||
it_behaves_like "a model using the LocalizedNumber module", [:preferred_flat_percent]
|
||||
end
|
||||
|
||||
it "computes amount correctly for a given Stock::Package" do
|
||||
order = double(:order, line_items: [line_item] )
|
||||
package = double(:package, order: order)
|
||||
|
||||
calculator.compute(package).should == 1.0
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user