mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Update specs that stub associations inaccurately
These specs fail if the code is using #sum on stubbed objects that don't respond to it nicely.
This commit is contained in:
@@ -11,14 +11,12 @@ module OrderManagement
|
||||
before { allow(order).to receive(:backordered?) { false } }
|
||||
|
||||
it "updates totals" do
|
||||
payments = [double(amount: 5), double(amount: 5)]
|
||||
allow(order).to receive_message_chain(:payments, :completed).and_return(payments)
|
||||
allow(order).to receive_message_chain(:payments, :completed, :sum).and_return(10)
|
||||
|
||||
line_items = [double(amount: 10), double(amount: 20)]
|
||||
allow(order).to receive_messages line_items: line_items
|
||||
|
||||
adjustments = [double(amount: 10), double(amount: -20)]
|
||||
allow(order).to receive_message_chain(:adjustments, :eligible).and_return(adjustments)
|
||||
allow(order).to receive_message_chain(:adjustments, :eligible, :sum).and_return(-10)
|
||||
|
||||
updater.update_totals
|
||||
expect(order.payment_total).to eq 10
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Order do
|
||||
let(:order) { Spree::Order.new }
|
||||
|
||||
@@ -21,19 +22,20 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
context "totaling adjustments" do
|
||||
let(:adjustment1) { build(:adjustment, amount: 5) }
|
||||
let(:adjustment2) { build(:adjustment, amount: 10) }
|
||||
let!(:adjustment1) { create(:adjustment, amount: 5) }
|
||||
let!(:adjustment2) { create(:adjustment, amount: 10) }
|
||||
let(:adjustments) { Spree::Adjustment.where(id: [adjustment1, adjustment2]) }
|
||||
|
||||
context "#ship_total" do
|
||||
it "should return the correct amount" do
|
||||
allow(order).to receive_message_chain :adjustments, shipping: [adjustment1, adjustment2]
|
||||
allow(order).to receive_message_chain :adjustments, shipping: adjustments
|
||||
expect(order.ship_total).to eq 15
|
||||
end
|
||||
end
|
||||
|
||||
context "#tax_total" do
|
||||
it "should return the correct amount" do
|
||||
allow(order).to receive_message_chain :adjustments, tax: [adjustment1, adjustment2]
|
||||
allow(order).to receive_message_chain :adjustments, tax: adjustments
|
||||
expect(order.tax_total).to eq 15
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user