Remove mocking of deleted Order methods

This commit is contained in:
Maikel Linke
2024-05-09 09:51:57 +10:00
parent 9320ed0559
commit d6318b7194

View File

@@ -21,13 +21,17 @@ describe Spree::Order do
end
context "when payment processing succeeds" do
before { allow(order).to receive_messages process_payments!: true }
it "should finalize order when transitioning to complete state" do
order.next
expect(order.state).to eq "confirmation"
expect(order).to receive(:finalize!)
order.next!
expect {
order.next!
}.to change {
order.state
}.from("confirmation").to("complete")
.and change {
order.completed_at
}
end
context "when credit card processing fails" do
@@ -35,9 +39,15 @@ describe Spree::Order do
it "should still complete the order" do
order.next
expect(order.state).to eq "confirmation"
order.next
expect(order.state).to eq "complete"
expect {
order.next!
}.to change {
order.state
}.from("confirmation").to("complete")
.and change {
order.completed_at
}
end
end
end
@@ -100,9 +110,9 @@ describe Spree::Order do
end
before do
allow(order).to receive_messages line_items: [build(:line_item, variant:,
quantity: 2)]
allow(order.line_items).to receive_messages find_by_variant_id: order.line_items.first
allow(order).to receive_messages line_items: [
build(:line_item, variant:, quantity: 2)
]
allow(order).to receive_messages completed?: true
allow(order).to receive_messages allow_cancel?: true
@@ -111,7 +121,6 @@ describe Spree::Order do
it "should send a cancel email" do
# Stub methods that cause side-effects in this test
allow(shipment).to receive(:cancel!)
allow(order).to receive :restock_items!
mail_message = double "Mail::Message"
order_id = nil
expect(Spree::OrderMailer).to receive(:cancel_email) { |*args|
@@ -137,7 +146,6 @@ describe Spree::Order do
# Stubs methods that cause unwanted side effects in this test
allow(Spree::OrderMailer).to receive(:cancel_email).and_return(mail_message = double)
allow(mail_message).to receive :deliver_later
allow(order).to receive :restock_items!
allow(shipment).to receive(:cancel!)
end
@@ -151,44 +159,4 @@ describe Spree::Order do
end
end
end
# Another regression test for Spree #729
context "#resume" do
context "resets payment state" do
let!(:variant) { build(:variant) }
before do
allow(order).to receive_messages email: "user@spreecommerce.com"
allow(order).to receive_messages allow_cancel?: true
allow(order).to receive_messages allow_resume?: true
allow(order).to receive_messages line_items:
[build(:line_item, variant:, quantity: 2)]
allow(order.line_items).to receive_messages find_by_variant_id: order.line_items.first
order.update(total: 10)
order.cancel!
end
it "should set payment state to 'balance due'" do
expect {
order.resume!
order.reload
}.to change { order.payment_state }.to("balance_due")
end
it "should set payment state to 'paid'" do
expect {
order.update(payment_total: 10)
order.resume!
order.reload
}.to change { order.payment_state }.to("paid")
end
it "should set payment state to 'credit owed'" do
expect {
order.update(payment_total: 20)
order.resume!
order.reload
}.to change { order.payment_state }.to("credit_owed")
end
end
end
end