mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
52 lines
1.6 KiB
Ruby
52 lines
1.6 KiB
Ruby
require 'spec_helper'
|
|
|
|
module Spree
|
|
describe LineItem do
|
|
describe "scopes" do
|
|
let(:o) { create(:order) }
|
|
|
|
let(:s1) { create(:supplier_enterprise) }
|
|
let(:s2) { create(:supplier_enterprise) }
|
|
|
|
let(:p1) { create(:simple_product, supplier: s1) }
|
|
let(:p2) { create(:simple_product, supplier: s2) }
|
|
|
|
let(:li1) { create(:line_item, order: o, product: p1) }
|
|
let(:li2) { create(:line_item, order: o, product: p2) }
|
|
|
|
it "finds line items for products supplied by a particular enterprise" do
|
|
LineItem.supplied_by(s1).should == [li1]
|
|
LineItem.supplied_by(s2).should == [li2]
|
|
end
|
|
|
|
it "finds line items for products supplied by one of a number of enterprises" do
|
|
LineItem.supplied_by_any([s1]).should == [li1]
|
|
LineItem.supplied_by_any([s2]).should == [li2]
|
|
LineItem.supplied_by_any([s1, s2]).sort.should == [li1, li2].sort
|
|
end
|
|
end
|
|
|
|
describe "calculating price with adjustments" do
|
|
it "does not return fractional cents" do
|
|
li = LineItem.new
|
|
|
|
li.stub(:price) { 55.55 }
|
|
li.stub_chain(:order, :adjustments, :where, :sum) { 11.11 }
|
|
li.stub(:quantity) { 2 }
|
|
li.price_with_adjustments.should == 61.11
|
|
end
|
|
end
|
|
|
|
describe "calculating amount with adjustments" do
|
|
it "returns a value consistent with price_with_adjustments" do
|
|
li = LineItem.new
|
|
|
|
li.stub(:price) { 55.55 }
|
|
li.stub_chain(:order, :adjustments, :where, :sum) { 11.11 }
|
|
li.stub(:quantity) { 2 }
|
|
li.amount_with_adjustments.should == 122.22
|
|
end
|
|
end
|
|
end
|
|
end
|