Improve failed_checkout_spec by making calculator decorator line_items_for work with new Stock::Package

This commit is contained in:
luisramos0
2018-11-13 15:59:28 +00:00
parent a65e2487c4
commit 7c0627a823
2 changed files with 10 additions and 3 deletions

View File

@@ -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

View File

@@ -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