mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-05 02:41:33 +00:00
Fix spec/models/spree/order specs
This commit is contained in:
@@ -8,7 +8,7 @@ describe Spree::Order do
|
||||
context 'validation' do
|
||||
context "when @use_billing is populated" do
|
||||
before do
|
||||
order.bill_address = stub_model(Spree::Address)
|
||||
order.bill_address = build(:address)
|
||||
order.ship_address = nil
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ describe Spree::Order do
|
||||
|
||||
it "clones the bill address to the ship address" do
|
||||
order.valid?
|
||||
order.ship_address.should == order.bill_address
|
||||
expect(order.ship_address).to eq order.bill_address
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,7 +26,7 @@ describe Spree::Order do
|
||||
|
||||
it "clones the bill address to the shipping" do
|
||||
order.valid?
|
||||
order.ship_address.should == order.bill_address
|
||||
expect(order.ship_address).to eq order.bill_address
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@ describe Spree::Order do
|
||||
|
||||
it "clones the bill address to the shipping" do
|
||||
order.valid?
|
||||
order.ship_address.should == order.bill_address
|
||||
expect(order.ship_address).to eq order.bill_address
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,7 +44,7 @@ describe Spree::Order do
|
||||
|
||||
it "does not clone the bill address to the shipping" do
|
||||
order.valid?
|
||||
order.ship_address.should be_nil
|
||||
expect(order.ship_address).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -21,20 +21,20 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
context "totaling adjustments" do
|
||||
let(:adjustment1) { mock_model(Spree::Adjustment, amount: 5) }
|
||||
let(:adjustment2) { mock_model(Spree::Adjustment, amount: 10) }
|
||||
let(:adjustment1) { build(:adjustment, amount: 5) }
|
||||
let(:adjustment2) { build(:adjustment, amount: 10) }
|
||||
|
||||
context "#ship_total" do
|
||||
it "should return the correct amount" do
|
||||
order.stub_chain :adjustments, shipping: [adjustment1, adjustment2]
|
||||
order.ship_total.should == 15
|
||||
expect(order.ship_total).to eq 15
|
||||
end
|
||||
end
|
||||
|
||||
context "#tax_total" do
|
||||
it "should return the correct amount" do
|
||||
order.stub_chain :adjustments, tax: [adjustment1, adjustment2]
|
||||
order.tax_total.should == 15
|
||||
expect(order.tax_total).to eq 15
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -46,43 +46,43 @@ describe Spree::Order do
|
||||
before { @order.stub_chain(:line_item_adjustments, eligible: []) }
|
||||
|
||||
it "should return an empty hash" do
|
||||
@order.line_item_adjustment_totals.should == {}
|
||||
expect(@order.line_item_adjustment_totals).to eq({})
|
||||
end
|
||||
end
|
||||
|
||||
context "when there are two adjustments with different labels" do
|
||||
let(:adj1) { mock_model Spree::Adjustment, amount: 10, label: "Foo" }
|
||||
let(:adj2) { mock_model Spree::Adjustment, amount: 20, label: "Bar" }
|
||||
let(:adj1) { build(:adjustment, amount: 10, label: "Foo") }
|
||||
let(:adj2) { build(:adjustment, amount: 20, label: "Bar") }
|
||||
|
||||
before do
|
||||
@order.stub_chain(:line_item_adjustments, eligible: [adj1, adj2])
|
||||
end
|
||||
|
||||
it "should return exactly two totals" do
|
||||
@order.line_item_adjustment_totals.size.should == 2
|
||||
expect(@order.line_item_adjustment_totals.size).to eq 2
|
||||
end
|
||||
|
||||
it "should return the correct totals" do
|
||||
@order.line_item_adjustment_totals["Foo"].should == Spree::Money.new(10)
|
||||
@order.line_item_adjustment_totals["Bar"].should == Spree::Money.new(20)
|
||||
expect(@order.line_item_adjustment_totals["Foo"]).to eq Spree::Money.new(10)
|
||||
expect(@order.line_item_adjustment_totals["Bar"]).to eq Spree::Money.new(20)
|
||||
end
|
||||
end
|
||||
|
||||
context "when there are two adjustments with one label and a single adjustment with another" do
|
||||
let(:adj1) { mock_model Spree::Adjustment, amount: 10, label: "Foo" }
|
||||
let(:adj2) { mock_model Spree::Adjustment, amount: 20, label: "Bar" }
|
||||
let(:adj3) { mock_model Spree::Adjustment, amount: 40, label: "Bar" }
|
||||
let(:adj1) { build(:adjustment, amount: 10, label: "Foo") }
|
||||
let(:adj2) { build(:adjustment, amount: 20, label: "Bar") }
|
||||
let(:adj3) { build(:adjustment, amount: 40, label: "Bar") }
|
||||
|
||||
before do
|
||||
@order.stub_chain(:line_item_adjustments, eligible: [adj1, adj2, adj3])
|
||||
end
|
||||
|
||||
it "should return exactly two totals" do
|
||||
@order.line_item_adjustment_totals.size.should == 2
|
||||
expect(@order.line_item_adjustment_totals.size).to eq 2
|
||||
end
|
||||
it "should return the correct totals" do
|
||||
@order.line_item_adjustment_totals["Foo"].should == Spree::Money.new(10)
|
||||
@order.line_item_adjustment_totals["Bar"].should == Spree::Money.new(60)
|
||||
expect(@order.line_item_adjustment_totals["Foo"]).to eq Spree::Money.new(10)
|
||||
expect(@order.line_item_adjustment_totals["Bar"]).to eq Spree::Money.new(60)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -98,7 +98,7 @@ describe Spree::Order do
|
||||
|
||||
context "when there are no line item adjustments" do
|
||||
it "should return nothing if line items have no adjustments" do
|
||||
@order.line_item_adjustments.should be_empty
|
||||
expect(@order.line_item_adjustments).to be_empty
|
||||
end
|
||||
end
|
||||
|
||||
@@ -118,7 +118,8 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
it "should return the adjustments for that line item" do
|
||||
@order.line_item_adjustments.should =~ [@adj1, @adj2]
|
||||
expect(@order.line_item_adjustments).to include @adj1
|
||||
expect(@order.line_item_adjustments).to include @adj2
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Order do
|
||||
let(:order) { stub_model(Spree::Order) }
|
||||
let(:order) { build(:order) }
|
||||
before do
|
||||
Spree::Order.define_state_machine!
|
||||
end
|
||||
@@ -14,7 +14,7 @@ describe Spree::Order do
|
||||
it "o'brien@gmail.com is a valid email address" do
|
||||
order.state = 'address'
|
||||
order.email = "o'brien@gmail.com"
|
||||
order.should have(:no).error_on(:email)
|
||||
expect(order.errors[:email]).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -29,7 +29,7 @@ describe Spree::Order do
|
||||
|
||||
it "should assign the email address of the user" do
|
||||
order.run_callbacks(:create)
|
||||
order.email.should == user.email
|
||||
expect(order.email).to eq user.email
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -38,7 +38,7 @@ describe Spree::Order do
|
||||
it "should not validate email address" do
|
||||
order.state = "cart"
|
||||
order.email = nil
|
||||
order.should have(:no).error_on(:email)
|
||||
expect(order.errors[:email]).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,8 +4,9 @@ require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe Spree::Order do
|
||||
let(:order) { stub_model(Spree::Order) }
|
||||
let(:order) { build(:order) }
|
||||
let(:updater) { Spree::OrderUpdater.new(order) }
|
||||
let(:bogus) { create(:bogus_payment_method, distributors: [create(:enterprise)]) }
|
||||
|
||||
before do
|
||||
# So that Payment#purchase! is called during processing
|
||||
@@ -16,39 +17,39 @@ module Spree
|
||||
end
|
||||
|
||||
it 'processes all payments' do
|
||||
payment_1 = create(:payment, amount: 50)
|
||||
payment_2 = create(:payment, amount: 50)
|
||||
order.stub(:pending_payments).and_return([payment_1, payment_2])
|
||||
payment1 = create(:payment, amount: 50, payment_method: bogus)
|
||||
payment2 = create(:payment, amount: 50, payment_method: bogus)
|
||||
order.stub(:pending_payments).and_return([payment1, payment2])
|
||||
|
||||
order.process_payments!
|
||||
updater.update_payment_state
|
||||
order.payment_state.should == 'paid'
|
||||
expect(order.payment_state).to eq 'paid'
|
||||
|
||||
payment_1.should be_completed
|
||||
payment_2.should be_completed
|
||||
expect(payment1).to be_completed
|
||||
expect(payment2).to be_completed
|
||||
end
|
||||
|
||||
it 'does not go over total for order' do
|
||||
payment_1 = create(:payment, amount: 50)
|
||||
payment_2 = create(:payment, amount: 50)
|
||||
payment_3 = create(:payment, amount: 50)
|
||||
order.stub(:pending_payments).and_return([payment_1, payment_2, payment_3])
|
||||
payment1 = create(:payment, amount: 50, payment_method: bogus)
|
||||
payment2 = create(:payment, amount: 50, payment_method: bogus)
|
||||
payment3 = create(:payment, amount: 50, payment_method: bogus)
|
||||
order.stub(:pending_payments).and_return([payment1, payment2, payment3])
|
||||
|
||||
order.process_payments!
|
||||
updater.update_payment_state
|
||||
order.payment_state.should == 'paid'
|
||||
expect(order.payment_state).to eq 'paid'
|
||||
|
||||
payment_1.should be_completed
|
||||
payment_2.should be_completed
|
||||
payment_3.should be_checkout
|
||||
expect(payment1).to be_completed
|
||||
expect(payment2).to be_completed
|
||||
expect(payment3).to be_checkout
|
||||
end
|
||||
|
||||
it "does not use failed payments" do
|
||||
payment_1 = create(:payment, amount: 50)
|
||||
payment_2 = create(:payment, amount: 50, state: 'failed')
|
||||
order.stub(:pending_payments).and_return([payment_1])
|
||||
payment1 = create(:payment, amount: 50, payment_method: bogus)
|
||||
payment2 = create(:payment, amount: 50, state: 'failed', payment_method: bogus)
|
||||
order.stub(:pending_payments).and_return([payment1])
|
||||
|
||||
payment_2.should_not_receive(:process!)
|
||||
payment2.should_not_receive(:process!)
|
||||
|
||||
order.process_payments!
|
||||
end
|
||||
|
||||
@@ -12,9 +12,9 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
context "#next!" do
|
||||
context "when current state is confirm" do
|
||||
context "when current state is payment" do
|
||||
before do
|
||||
order.state = "confirm"
|
||||
order.state = "payment"
|
||||
order.run_callbacks(:create)
|
||||
order.stub payment_required?: true
|
||||
order.stub process_payments!: true
|
||||
@@ -34,7 +34,7 @@ describe Spree::Order do
|
||||
|
||||
it "should not complete the order" do
|
||||
order.next
|
||||
order.state.should == "confirm"
|
||||
expect(order.state).to eq "payment"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -44,7 +44,7 @@ describe Spree::Order do
|
||||
|
||||
it "cannot transition to complete" do
|
||||
order.next
|
||||
order.state.should == "confirm"
|
||||
expect(order.state).to eq "payment"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -77,7 +77,7 @@ describe Spree::Order do
|
||||
it "should be true if shipment_state is #{shipment_state}" do
|
||||
order.stub completed?: true
|
||||
order.shipment_state = shipment_state
|
||||
order.can_cancel?.should be_true
|
||||
expect(order.can_cancel?).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
@@ -85,26 +85,26 @@ describe Spree::Order do
|
||||
it "should be false if shipment_state is #{shipment_state}" do
|
||||
order.stub completed?: true
|
||||
order.shipment_state = shipment_state
|
||||
order.can_cancel?.should be_false
|
||||
expect(order.can_cancel?).to be_falsy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#cancel" do
|
||||
let!(:variant) { stub_model(Spree::Variant) }
|
||||
let!(:variant) { build(:variant) }
|
||||
let!(:inventory_units) {
|
||||
[stub_model(Spree::InventoryUnit, variant: variant),
|
||||
stub_model(Spree::InventoryUnit, variant: variant)]
|
||||
[build(:inventory_unit, variant: variant),
|
||||
build(:inventory_unit, variant: variant)]
|
||||
}
|
||||
let!(:shipment) do
|
||||
shipment = stub_model(Spree::Shipment)
|
||||
shipment = build(:shipment)
|
||||
shipment.stub inventory_units: inventory_units
|
||||
order.stub shipments: [shipment]
|
||||
shipment
|
||||
end
|
||||
|
||||
before do
|
||||
order.stub line_items: [stub_model(Spree::LineItem, variant: variant, quantity: 2)]
|
||||
order.stub line_items: [build(:line_item, variant: variant, quantity: 2)]
|
||||
order.line_items.stub find_by_variant_id: order.line_items.first
|
||||
|
||||
order.stub completed?: true
|
||||
@@ -124,7 +124,7 @@ describe Spree::Order do
|
||||
}
|
||||
mail_message.should_receive :deliver
|
||||
order.cancel!
|
||||
order_id.should == order.id
|
||||
expect(order_id).to eq order.id
|
||||
end
|
||||
|
||||
context "restocking inventory" do
|
||||
@@ -151,7 +151,7 @@ describe Spree::Order do
|
||||
context "without shipped items" do
|
||||
it "should set payment state to 'credit owed'" do
|
||||
order.cancel!
|
||||
order.payment_state.should == 'credit_owed'
|
||||
expect(order.payment_state).to eq 'credit_owed'
|
||||
end
|
||||
end
|
||||
|
||||
@@ -162,7 +162,7 @@ describe Spree::Order do
|
||||
|
||||
it "should not alter the payment state" do
|
||||
order.cancel!
|
||||
order.payment_state.should be_nil
|
||||
expect(order.payment_state).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,7 @@ require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe Spree::Order do
|
||||
let(:order) { stub_model(Spree::Order) }
|
||||
let(:order) { build(:order) }
|
||||
|
||||
context "#tax_zone" do
|
||||
let(:bill_address) { create :address }
|
||||
@@ -16,7 +16,7 @@ module Spree
|
||||
before { Spree::Zone.destroy_all }
|
||||
|
||||
it "should return nil" do
|
||||
order.tax_zone.should be_nil
|
||||
expect(order.tax_zone).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,7 +50,7 @@ module Spree
|
||||
before { Spree::Zone.stub(match: zone) }
|
||||
|
||||
it "should return the matching zone" do
|
||||
order.tax_zone.should == zone
|
||||
expect(order.tax_zone).to eq zone
|
||||
end
|
||||
end
|
||||
|
||||
@@ -58,7 +58,7 @@ module Spree
|
||||
before { Spree::Zone.stub(match: nil) }
|
||||
|
||||
it "should return the default tax zone" do
|
||||
order.tax_zone.should == @default_zone
|
||||
expect(order.tax_zone).to eq @default_zone
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -70,7 +70,7 @@ module Spree
|
||||
before { Spree::Zone.stub(match: zone) }
|
||||
|
||||
it "should return the matching zone" do
|
||||
order.tax_zone.should == zone
|
||||
expect(order.tax_zone).to eq zone
|
||||
end
|
||||
end
|
||||
|
||||
@@ -78,7 +78,7 @@ module Spree
|
||||
before { Spree::Zone.stub(match: nil) }
|
||||
|
||||
it "should return nil" do
|
||||
order.tax_zone.should be_nil
|
||||
expect(order.tax_zone).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -96,12 +96,12 @@ module Spree
|
||||
|
||||
it "should be true when tax_zone is not the same as the default" do
|
||||
@order.stub tax_zone: create(:zone, name: "other_zone")
|
||||
@order.exclude_tax?.should be_true
|
||||
expect(@order.exclude_tax?).to be_truthy
|
||||
end
|
||||
|
||||
it "should be false when tax_zone is the same as the default" do
|
||||
@order.stub tax_zone: @default_zone
|
||||
@order.exclude_tax?.should be_false
|
||||
expect(@order.exclude_tax?).to be_falsy
|
||||
end
|
||||
end
|
||||
|
||||
@@ -109,7 +109,7 @@ module Spree
|
||||
before { Spree::Config.set(prices_inc_tax: false) }
|
||||
|
||||
it "should be false" do
|
||||
@order.exclude_tax?.should be_false
|
||||
expect(@order.exclude_tax?).to be_falsy
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Order do
|
||||
let(:order) { stub_model(Spree::Order) }
|
||||
let(:order) { build(:order) }
|
||||
|
||||
context "#update!" do
|
||||
let(:line_items) { [mock_model(Spree::LineItem, amount: 5)] }
|
||||
let(:line_items) { [build(:line_item, amount: 5)] }
|
||||
|
||||
context "when there are update hooks" do
|
||||
before { Spree::Order.register_update_hook :foo }
|
||||
|
||||
@@ -171,13 +171,6 @@ describe Spree::Order do
|
||||
expect(order.shipment_state).to eq 'ready'
|
||||
end
|
||||
|
||||
after { Spree::Config.set track_inventory_levels: true }
|
||||
it "should not sell inventory units if track_inventory_levels is false" do
|
||||
Spree::Config.set track_inventory_levels: false
|
||||
Spree::InventoryUnit.should_not_receive(:sell_units)
|
||||
order.finalize!
|
||||
end
|
||||
|
||||
it "should send an order confirmation email" do
|
||||
expect do
|
||||
order.finalize!
|
||||
|
||||
Reference in New Issue
Block a user