From 04930877ddd1a753969511f76577adce02aaa0a0 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 25 Nov 2020 16:07:48 +0100 Subject: [PATCH] Test that payment_total is stored after payment CustomerWithBalance totally relies on `spree_orders.payment_total` so we better cover it with tests. --- spec/models/spree/order_spec.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 2361ff3a21..2a88499e6e 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -201,16 +201,27 @@ describe Spree::Order do let(:payment) { build(:payment) } before { allow(order).to receive_messages pending_payments: [payment], total: 10 } - it "should process the payments" do - expect(payment).to receive(:process!) - expect(order.process_payments!).to be_truthy - end - it "should return false if no pending_payments available" do allow(order).to receive_messages pending_payments: [] expect(order.process_payments!).to be_falsy end + context "when the processing is sucessful" do + it "should process the payments" do + expect(payment).to receive(:process!) + expect(order.process_payments!).to be_truthy + end + + it "stores the payment total on the order" do + allow(payment).to receive(:process!) + allow(payment).to receive(:completed?).and_return(true) + + order.process_payments! + + expect(order.payment_total).to eq(payment.amount) + end + end + context "when a payment raises a GatewayError" do before { expect(payment).to receive(:process!).and_raise(Spree::Core::GatewayError) }