Run transpec on the new specs from spree_core

This commit is contained in:
Luis Ramos
2020-08-08 17:29:49 +01:00
parent 31f9cd3caf
commit 4215dcb927
11 changed files with 148 additions and 148 deletions

View File

@@ -15,7 +15,7 @@ describe Spree::InventoryUnit do
shipment.shipping_methods << create(:shipping_method)
shipment.order = order
# We don't care about this in this test
shipment.stub(:ensure_correct_adjustment)
allow(shipment).to receive(:ensure_correct_adjustment)
shipment.tap(&:save!)
end

View File

@@ -8,8 +8,8 @@ module Spree
context '#save' do
it 'should update inventory, totals, and tax' do
# Regression check for Spree #1481
line_item.order.should_receive(:create_tax_charge!)
line_item.order.should_receive(:update!)
expect(line_item.order).to receive(:create_tax_charge!)
expect(line_item.order).to receive(:update!)
line_item.quantity = 2
line_item.save
end
@@ -18,7 +18,7 @@ module Spree
context '#destroy' do
# Regression test for Spree #1481
it "applies tax adjustments" do
line_item.order.should_receive(:create_tax_charge!)
expect(line_item.order).to receive(:create_tax_charge!)
line_item.destroy
end

View File

@@ -8,14 +8,14 @@ describe Spree::Order do
let(:adjustment) { double("Adjustment") }
it "destroys all order adjustments" do
order.stub(adjustments: adjustment)
adjustment.should_receive(:destroy_all)
allow(order).to receive_messages(adjustments: adjustment)
expect(adjustment).to receive(:destroy_all)
order.clear_adjustments!
end
it "destroy all line item adjustments" do
order.stub(line_item_adjustments: adjustment)
adjustment.should_receive(:destroy_all)
allow(order).to receive_messages(line_item_adjustments: adjustment)
expect(adjustment).to receive(:destroy_all)
order.clear_adjustments!
end
end
@@ -26,14 +26,14 @@ describe Spree::Order do
context "#ship_total" do
it "should return the correct amount" do
order.stub_chain :adjustments, shipping: [adjustment1, adjustment2]
allow(order).to receive_message_chain :adjustments, shipping: [adjustment1, adjustment2]
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]
allow(order).to receive_message_chain :adjustments, tax: [adjustment1, adjustment2]
expect(order.tax_total).to eq 15
end
end
@@ -43,7 +43,7 @@ describe Spree::Order do
before { @order = Spree::Order.create! }
context "when there are no line item adjustments" do
before { @order.stub_chain(:line_item_adjustments, eligible: []) }
before { allow(@order).to receive_message_chain(:line_item_adjustments, eligible: []) }
it "should return an empty hash" do
expect(@order.line_item_adjustment_totals).to eq({})
@@ -55,7 +55,7 @@ describe Spree::Order do
let(:adj2) { build(:adjustment, amount: 20, label: "Bar") }
before do
@order.stub_chain(:line_item_adjustments, eligible: [adj1, adj2])
allow(@order).to receive_message_chain(:line_item_adjustments, eligible: [adj1, adj2])
end
it "should return exactly two totals" do
@@ -74,7 +74,7 @@ describe Spree::Order do
let(:adj3) { build(:adjustment, amount: 40, label: "Bar") }
before do
@order.stub_chain(:line_item_adjustments, eligible: [adj1, adj2, adj3])
allow(@order).to receive_message_chain(:line_item_adjustments, eligible: [adj1, adj2, adj3])
end
it "should return exactly two totals" do
@@ -90,7 +90,7 @@ describe Spree::Order do
context "line item adjustments" do
before do
@order = Spree::Order.create!
@order.stub line_items: [line_item1, line_item2]
allow(@order).to receive_messages line_items: [line_item1, line_item2]
end
let(:line_item1) { create(:line_item, order: @order) }

View File

@@ -24,7 +24,7 @@ describe Spree::Order do
let(:user) { double(:user, email: "test@example.com") }
before do
order.stub user: user
allow(order).to receive_messages user: user
end
it "should assign the email address of the user" do

View File

@@ -12,14 +12,14 @@ module Spree
# So that Payment#purchase! is called during processing
Spree::Config[:auto_capture] = true
order.stub_chain(:line_items, :empty?).and_return(false)
order.stub total: 100
allow(order).to receive_message_chain(:line_items, :empty?).and_return(false)
allow(order).to receive_messages total: 100
end
it 'processes all payments' do
payment1 = create(:payment, amount: 50, payment_method: bogus)
payment2 = create(:payment, amount: 50, payment_method: bogus)
order.stub(:pending_payments).and_return([payment1, payment2])
allow(order).to receive(:pending_payments).and_return([payment1, payment2])
order.process_payments!
updater.update_payment_state
@@ -33,7 +33,7 @@ module Spree
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])
allow(order).to receive(:pending_payments).and_return([payment1, payment2, payment3])
order.process_payments!
updater.update_payment_state
@@ -47,9 +47,9 @@ module Spree
it "does not use failed payments" do
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])
allow(order).to receive(:pending_payments).and_return([payment1])
payment2.should_not_receive(:process!)
expect(payment2).not_to receive(:process!)
order.process_payments!
end

View File

@@ -8,7 +8,7 @@ describe Spree::Order do
# Ensure state machine has been re-defined correctly
Spree::Order.define_state_machine!
# We don't care about this validation here
order.stub(:require_email)
allow(order).to receive(:require_email)
end
context "#next!" do
@@ -16,21 +16,21 @@ describe Spree::Order do
before do
order.state = "payment"
order.run_callbacks(:create)
order.stub payment_required?: true
order.stub process_payments!: true
order.stub :has_available_shipment
allow(order).to receive_messages payment_required?: true
allow(order).to receive_messages process_payments!: true
allow(order).to receive :has_available_shipment
end
context "when payment processing succeeds" do
before { order.stub process_payments!: true }
before { allow(order).to receive_messages process_payments!: true }
it "should finalize order when transitioning to complete state" do
order.should_receive(:finalize!)
expect(order).to receive(:finalize!)
order.next!
end
context "when credit card processing fails" do
before { order.stub process_payments!: false }
before { allow(order).to receive_messages process_payments!: false }
it "should not complete the order" do
order.next
@@ -40,7 +40,7 @@ describe Spree::Order do
end
context "when payment processing fails" do
before { order.stub process_payments!: false }
before { allow(order).to receive_messages process_payments!: false }
it "cannot transition to complete" do
order.next
@@ -51,15 +51,15 @@ describe Spree::Order do
context "when current state is address" do
before do
order.stub(:has_available_payment)
order.stub(:ensure_available_shipping_rates)
allow(order).to receive(:has_available_payment)
allow(order).to receive(:ensure_available_shipping_rates)
order.state = "address"
end
it "adjusts tax rates when transitioning to delivery" do
# Once because the record is being saved
# Twice because it is transitioning to the delivery state
Spree::TaxRate.should_receive(:adjust).twice
expect(Spree::TaxRate).to receive(:adjust).twice
order.next!
end
end
@@ -67,7 +67,7 @@ describe Spree::Order do
context "when current state is delivery" do
before do
order.state = "delivery"
order.stub total: 10.0
allow(order).to receive_messages total: 10.0
end
end
end
@@ -75,7 +75,7 @@ describe Spree::Order do
context "#can_cancel?" do
%w(pending backorder ready).each do |shipment_state|
it "should be true if shipment_state is #{shipment_state}" do
order.stub completed?: true
allow(order).to receive_messages completed?: true
order.shipment_state = shipment_state
expect(order.can_cancel?).to be_truthy
end
@@ -83,7 +83,7 @@ describe Spree::Order do
(Spree::Shipment.state_machine.states.keys - %w(pending backorder ready)).each do |shipment_state|
it "should be false if shipment_state is #{shipment_state}" do
order.stub completed?: true
allow(order).to receive_messages completed?: true
order.shipment_state = shipment_state
expect(order.can_cancel?).to be_falsy
end
@@ -98,54 +98,54 @@ describe Spree::Order do
}
let!(:shipment) do
shipment = build(:shipment)
shipment.stub inventory_units: inventory_units
order.stub shipments: [shipment]
allow(shipment).to receive_messages inventory_units: inventory_units
allow(order).to receive_messages shipments: [shipment]
shipment
end
before do
order.stub line_items: [build(:line_item, variant: variant, quantity: 2)]
order.line_items.stub find_by_variant_id: order.line_items.first
allow(order).to receive_messages line_items: [build(:line_item, variant: variant, quantity: 2)]
allow(order.line_items).to receive_messages find_by_variant_id: order.line_items.first
order.stub completed?: true
order.stub allow_cancel?: true
allow(order).to receive_messages completed?: true
allow(order).to receive_messages allow_cancel?: true
end
it "should send a cancel email" do
# Stub methods that cause side-effects in this test
shipment.stub(:cancel!)
order.stub :has_available_shipment
order.stub :restock_items!
allow(shipment).to receive(:cancel!)
allow(order).to receive :has_available_shipment
allow(order).to receive :restock_items!
mail_message = double "Mail::Message"
order_id = nil
Spree::OrderMailer.should_receive(:cancel_email) { |*args|
expect(Spree::OrderMailer).to receive(:cancel_email) { |*args|
order_id = args[0]
mail_message
}
mail_message.should_receive :deliver
expect(mail_message).to receive :deliver
order.cancel!
expect(order_id).to eq order.id
end
context "restocking inventory" do
before do
shipment.stub(:ensure_correct_adjustment)
shipment.stub(:update_order)
Spree::OrderMailer.stub(:cancel_email).and_return(mail_message = double)
mail_message.stub :deliver
allow(shipment).to receive(:ensure_correct_adjustment)
allow(shipment).to receive(:update_order)
allow(Spree::OrderMailer).to receive(:cancel_email).and_return(mail_message = double)
allow(mail_message).to receive :deliver
order.stub :has_available_shipment
allow(order).to receive :has_available_shipment
end
end
context "resets payment state" do
before do
# Stubs methods that cause unwanted side effects in this test
Spree::OrderMailer.stub(:cancel_email).and_return(mail_message = double)
mail_message.stub :deliver
order.stub :has_available_shipment
order.stub :restock_items!
shipment.stub(:cancel!)
allow(Spree::OrderMailer).to receive(:cancel_email).and_return(mail_message = double)
allow(mail_message).to receive :deliver
allow(order).to receive :has_available_shipment
allow(order).to receive :restock_items!
allow(shipment).to receive(:cancel!)
end
context "without shipped items" do
@@ -157,7 +157,7 @@ describe Spree::Order do
context "with shipped items" do
before do
order.stub shipment_state: 'partial'
allow(order).to receive_messages shipment_state: 'partial'
end
it "should not alter the payment state" do
@@ -171,12 +171,12 @@ describe Spree::Order do
# Another regression test for Spree #729
context "#resume" do
before do
order.stub email: "user@spreecommerce.com"
order.stub state: "canceled"
order.stub allow_resume?: true
allow(order).to receive_messages email: "user@spreecommerce.com"
allow(order).to receive_messages state: "canceled"
allow(order).to receive_messages allow_resume?: true
# Stubs method that cause unwanted side effects in this test
order.stub :has_available_shipment
allow(order).to receive :has_available_shipment
end
end
end

View File

@@ -24,8 +24,8 @@ module Spree
before { Spree::Config.set(tax_using_ship_address: true) }
it "should calculate using ship_address" do
Spree::Zone.should_receive(:match).at_least(:once).with(ship_address)
Spree::Zone.should_not_receive(:match).with(bill_address)
expect(Spree::Zone).to receive(:match).at_least(:once).with(ship_address)
expect(Spree::Zone).not_to receive(:match).with(bill_address)
order.tax_zone
end
end
@@ -34,8 +34,8 @@ module Spree
before { Spree::Config.set(tax_using_ship_address: false) }
it "should calculate using bill_address" do
Spree::Zone.should_receive(:match).at_least(:once).with(bill_address)
Spree::Zone.should_not_receive(:match).with(ship_address)
expect(Spree::Zone).to receive(:match).at_least(:once).with(bill_address)
expect(Spree::Zone).not_to receive(:match).with(ship_address)
order.tax_zone
end
end
@@ -43,11 +43,11 @@ module Spree
context "when there is a default tax zone" do
before do
@default_zone = create(:zone, name: "foo_zone")
Spree::Zone.stub default_tax: @default_zone
allow(Spree::Zone).to receive_messages default_tax: @default_zone
end
context "when there is a matching zone" do
before { Spree::Zone.stub(match: zone) }
before { allow(Spree::Zone).to receive_messages(match: zone) }
it "should return the matching zone" do
expect(order.tax_zone).to eq zone
@@ -55,7 +55,7 @@ module Spree
end
context "when there is no matching zone" do
before { Spree::Zone.stub(match: nil) }
before { allow(Spree::Zone).to receive_messages(match: nil) }
it "should return the default tax zone" do
expect(order.tax_zone).to eq @default_zone
@@ -64,10 +64,10 @@ module Spree
end
context "when no default tax zone" do
before { Spree::Zone.stub default_tax: nil }
before { allow(Spree::Zone).to receive_messages default_tax: nil }
context "when there is a matching zone" do
before { Spree::Zone.stub(match: zone) }
before { allow(Spree::Zone).to receive_messages(match: zone) }
it "should return the matching zone" do
expect(order.tax_zone).to eq zone
@@ -75,7 +75,7 @@ module Spree
end
context "when there is no matching zone" do
before { Spree::Zone.stub(match: nil) }
before { allow(Spree::Zone).to receive_messages(match: nil) }
it "should return nil" do
expect(order.tax_zone).to be_nil
@@ -88,19 +88,19 @@ module Spree
before do
@order = create(:order)
@default_zone = create(:zone)
Spree::Zone.stub default_tax: @default_zone
allow(Spree::Zone).to receive_messages default_tax: @default_zone
end
context "when prices include tax" do
before { Spree::Config.set(prices_inc_tax: true) }
it "should be true when tax_zone is not the same as the default" do
@order.stub tax_zone: create(:zone, name: "other_zone")
allow(@order).to receive_messages tax_zone: create(:zone, name: "other_zone")
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
allow(@order).to receive_messages tax_zone: @default_zone
expect(@order.exclude_tax?).to be_falsy
end
end

View File

@@ -12,7 +12,7 @@ describe Spree::Order do
before { Spree::Order.register_update_hook :foo }
after { Spree::Order.update_hooks.clear }
it "should call each of the update hooks" do
order.should_receive :foo
expect(order).to receive :foo
order.update!
end
end

View File

@@ -33,16 +33,16 @@ describe Spree::OrderInventory do
let(:variant) { create :variant }
context "order is not completed" do
before { order.stub completed?: false }
before { allow(order).to receive_messages completed?: false }
it "doesn't unstock items" do
shipment.stock_location.should_not_receive(:unstock)
expect(shipment.stock_location).not_to receive(:unstock)
expect(subject.send(:add_to_shipment, shipment, variant, 5)).to eq 5
end
end
it 'should create inventory_units in the necessary states' do
shipment.stock_location.should_receive(:fill_status).with(variant, 5).and_return([3, 2])
expect(shipment.stock_location).to receive(:fill_status).with(variant, 5).and_return([3, 2])
expect(subject.send(:add_to_shipment, shipment, variant, 5)).to eq 5
@@ -85,10 +85,10 @@ describe Spree::OrderInventory do
let(:variant) { order.line_items.first.variant }
context "order is not completed" do
before { order.stub completed?: false }
before { allow(order).to receive_messages completed?: false }
it "doesn't restock items" do
shipment.stock_location.should_not_receive(:restock)
expect(shipment.stock_location).not_to receive(:restock)
expect(subject.send(:remove_from_shipment, shipment, variant, 1)).to eq 1
end
end
@@ -102,40 +102,40 @@ describe Spree::OrderInventory do
end
it 'should destroy backordered units first' do
shipment.stub(inventory_units_for: [build(:inventory_unit, variant_id: variant.id, state: 'backordered'),
allow(shipment).to receive_messages(inventory_units_for: [build(:inventory_unit, variant_id: variant.id, state: 'backordered'),
build(:inventory_unit, variant_id: variant.id, state: 'on_hand'),
build(:inventory_unit, variant_id: variant.id, state: 'backordered')])
shipment.inventory_units_for[0].should_receive(:destroy)
shipment.inventory_units_for[1].should_not_receive(:destroy)
shipment.inventory_units_for[2].should_receive(:destroy)
expect(shipment.inventory_units_for[0]).to receive(:destroy)
expect(shipment.inventory_units_for[1]).not_to receive(:destroy)
expect(shipment.inventory_units_for[2]).to receive(:destroy)
expect(subject.send(:remove_from_shipment, shipment, variant, 2)).to eq 2
end
it 'should destroy unshipped units first' do
shipment.stub(inventory_units_for: [build(:inventory_unit, variant_id: variant.id, state: 'shipped'),
allow(shipment).to receive_messages(inventory_units_for: [build(:inventory_unit, variant_id: variant.id, state: 'shipped'),
build(:inventory_unit, variant_id: variant.id, state: 'on_hand')] )
shipment.inventory_units_for[0].should_not_receive(:destroy)
shipment.inventory_units_for[1].should_receive(:destroy)
expect(shipment.inventory_units_for[0]).not_to receive(:destroy)
expect(shipment.inventory_units_for[1]).to receive(:destroy)
expect(subject.send(:remove_from_shipment, shipment, variant, 1)).to eq 1
end
it 'only attempts to destroy as many units as are eligible, and return amount destroyed' do
shipment.stub(inventory_units_for: [build(:inventory_unit, variant_id: variant.id, state: 'shipped'),
allow(shipment).to receive_messages(inventory_units_for: [build(:inventory_unit, variant_id: variant.id, state: 'shipped'),
build(:inventory_unit, variant_id: variant.id, state: 'on_hand')] )
shipment.inventory_units_for[0].should_not_receive(:destroy)
shipment.inventory_units_for[1].should_receive(:destroy)
expect(shipment.inventory_units_for[0]).not_to receive(:destroy)
expect(shipment.inventory_units_for[1]).to receive(:destroy)
expect(subject.send(:remove_from_shipment, shipment, variant, 1)).to eq 1
end
it 'should destroy self if not inventory units remain' do
shipment.inventory_units.stub(count: 0)
shipment.should_receive(:destroy)
allow(shipment.inventory_units).to receive_messages(count: 0)
expect(shipment).to receive(:destroy)
expect(subject.send(:remove_from_shipment, shipment, variant, 1)).to eq 1
end

View File

@@ -7,7 +7,7 @@ describe Spree::Order do
let(:order) { build(:order, user: user) }
before do
Spree::LegacyUser.stub(current: build(:user, id: 123))
allow(Spree::LegacyUser).to receive_messages(current: build(:user, id: 123))
end
context "#products" do
@@ -102,39 +102,39 @@ describe Spree::Order do
let(:order) { Spree::Order.create }
it "should be true for order in the 'complete' state" do
order.stub(complete?: true)
allow(order).to receive_messages(complete?: true)
expect(order.can_ship?).to be_truthy
end
it "should be true for order in the 'resumed' state" do
order.stub(resumed?: true)
allow(order).to receive_messages(resumed?: true)
expect(order.can_ship?).to be_truthy
end
it "should be true for an order in the 'awaiting return' state" do
order.stub(awaiting_return?: true)
allow(order).to receive_messages(awaiting_return?: true)
expect(order.can_ship?).to be_truthy
end
it "should be true for an order in the 'returned' state" do
order.stub(returned?: true)
allow(order).to receive_messages(returned?: true)
expect(order.can_ship?).to be_truthy
end
it "should be false if the order is neither in the 'complete' nor 'resumed' state" do
order.stub(resumed?: false, complete?: false)
allow(order).to receive_messages(resumed?: false, complete?: false)
expect(order.can_ship?).to be_falsy
end
end
context "checking if order is paid" do
context "payment_state is paid" do
before { order.stub payment_state: 'paid' }
before { allow(order).to receive_messages payment_state: 'paid' }
it { expect(order).to be_paid }
end
context "payment_state is credit_owned" do
before { order.stub payment_state: 'credit_owed' }
before { allow(order).to receive_messages payment_state: 'credit_owed' }
it { expect(order).to be_paid }
end
end
@@ -142,21 +142,21 @@ describe Spree::Order do
context "#finalize!" do
let(:order) { Spree::Order.create }
it "should set completed_at" do
order.should_receive(:touch).with(:completed_at)
expect(order).to receive(:touch).with(:completed_at)
order.finalize!
end
it "should sell inventory units" do
order.shipments.each do |shipment|
shipment.should_receive(:update!)
shipment.should_receive(:finalize!)
expect(shipment).to receive(:update!)
expect(shipment).to receive(:finalize!)
end
order.finalize!
end
it "should decrease the stock for each variant in the shipment" do
order.shipments.each do |shipment|
shipment.stock_location.should_receive(:decrease_stock_for_variant)
expect(shipment.stock_location).to receive(:decrease_stock_for_variant)
end
order.finalize!
end
@@ -165,7 +165,7 @@ describe Spree::Order do
Spree::Shipment.create(order: order)
order.shipments.reload
order.stub(paid?: true, complete?: true)
allow(order).to receive_messages(paid?: true, complete?: true)
order.finalize!
order.reload # reload so we're sure the changes are persisted
expect(order.shipment_state).to eq 'ready'
@@ -180,41 +180,41 @@ describe Spree::Order do
it "should freeze all adjustments" do
# Stub this method as it's called due to a callback
# and it's irrelevant to this test
order.stub :has_available_shipment
Spree::OrderMailer.stub_chain :confirm_email, :deliver
allow(order).to receive :has_available_shipment
allow(Spree::OrderMailer).to receive_message_chain :confirm_email, :deliver
adjustments = double
order.stub adjustments: adjustments
allow(order).to receive_messages adjustments: adjustments
expect(adjustments).to receive(:update_all).with(state: 'closed')
order.finalize!
end
it "should log state event" do
order.state_changes.should_receive(:create).exactly(3).times # order, shipment & payment state changes
expect(order.state_changes).to receive(:create).exactly(3).times # order, shipment & payment state changes
order.finalize!
end
it 'calls updater#before_save' do
order.updater.should_receive(:before_save_hook)
expect(order.updater).to receive(:before_save_hook)
order.finalize!
end
end
context "#process_payments!" do
let(:payment) { build(:payment) }
before { order.stub pending_payments: [payment], total: 10 }
before { allow(order).to receive_messages pending_payments: [payment], total: 10 }
it "should process the payments" do
payment.should_receive(:process!)
expect(payment).to receive(:process!)
expect(order.process_payments!).to be_truthy
end
it "should return false if no pending_payments available" do
order.stub pending_payments: []
allow(order).to receive_messages pending_payments: []
expect(order.process_payments!).to be_falsy
end
context "when a payment raises a GatewayError" do
before { payment.should_receive(:process!).and_raise(Spree::Core::GatewayError) }
before { expect(payment).to receive(:process!).and_raise(Spree::Core::GatewayError) }
it "should return true when configured to allow checkout on gateway failures" do
Spree::Config.set allow_checkout_on_gateway_error: true
@@ -271,11 +271,11 @@ describe Spree::Order do
context "#allow_checkout?" do
it "should be true if there are line_items in the order" do
order.stub_chain(:line_items, count: 1)
allow(order).to receive_message_chain(:line_items, count: 1)
expect(order.checkout_allowed?).to be_truthy
end
it "should be false if there are no line_items in the order" do
order.stub_chain(:line_items, count: 0)
allow(order).to receive_message_chain(:line_items, count: 0)
expect(order.checkout_allowed?).to be_falsy
end
end
@@ -321,7 +321,7 @@ describe Spree::Order do
let(:line_item) { build(:line_item) }
before do
order.stub(line_items: [line_item])
allow(order).to receive_messages(line_items: [line_item])
allow(line_item).to receive(:insufficient_stock?) { true }
end
@@ -334,10 +334,10 @@ describe Spree::Order do
context "empty!" do
it "should clear out all line items and adjustments" do
order = build(:order)
order.stub(line_items: line_items = [])
order.stub(adjustments: adjustments = [])
order.line_items.should_receive(:destroy_all)
order.adjustments.should_receive(:destroy_all)
allow(order).to receive_messages(line_items: line_items = [])
allow(order).to receive_messages(adjustments: adjustments = [])
expect(order.line_items).to receive(:destroy_all)
expect(order.adjustments).to receive(:destroy_all)
order.empty!
end
@@ -345,14 +345,14 @@ describe Spree::Order do
context "#display_outstanding_balance" do
it "returns the value as a spree money" do
order.stub(:outstanding_balance) { 10.55 }
allow(order).to receive(:outstanding_balance) { 10.55 }
expect(order.display_outstanding_balance).to eq Spree::Money.new(10.55)
end
end
context "#display_item_total" do
it "returns the value as a spree money" do
order.stub(:item_total) { 10.55 }
allow(order).to receive(:item_total) { 10.55 }
expect(order.display_item_total).to eq Spree::Money.new(10.55)
end
end
@@ -402,7 +402,7 @@ describe Spree::Order do
before do
# Don't care about available payment methods in this test
persisted_order.stub(has_available_payment: false)
allow(persisted_order).to receive_messages(has_available_payment: false)
persisted_order.line_items << line_item
persisted_order.adjustments.create(amount: -line_item.amount, label: "Promotion")
persisted_order.state = 'delivery'
@@ -410,7 +410,7 @@ describe Spree::Order do
end
it "transitions from delivery to payment" do
persisted_order.stub(payment_required?: true)
allow(persisted_order).to receive_messages(payment_required?: true)
persisted_order.next!
expect(persisted_order.state).to eq "payment"
end
@@ -424,7 +424,7 @@ describe Spree::Order do
end
context "total > zero" do
before { order.stub(total: 1) }
before { allow(order).to receive_messages(total: 1) }
it { expect(order.payment_required?).to be_truthy }
end
end
@@ -442,13 +442,13 @@ describe Spree::Order do
it "calls hook during update" do
order = create(:order)
order.should_receive(:add_awesome_sauce)
expect(order).to receive(:add_awesome_sauce)
order.update!
end
it "calls hook during finalize" do
order = create(:order)
order.should_receive(:add_awesome_sauce)
expect(order).to receive(:add_awesome_sauce)
order.finalize!
end
end
@@ -498,7 +498,7 @@ describe Spree::Order do
end
before do
Spree::Config.stub(:order_updater_decorator) { FakeOrderUpdaterDecorator }
allow(Spree::Config).to receive(:order_updater_decorator) { FakeOrderUpdaterDecorator }
end
it 'returns an order_updater_decorator class' do
@@ -514,7 +514,7 @@ describe Spree::Order do
let(:order) { build(:order) }
it "has errors if email is blank" do
order.stub(require_email: true)
allow(order).to receive_messages(require_email: true)
order.email = ""
order.valid?
@@ -522,7 +522,7 @@ describe Spree::Order do
end
it "has errors if email is invalid" do
order.stub(require_email: true)
allow(order).to receive_messages(require_email: true)
order.email = "invalid_email"
order.valid?
@@ -530,7 +530,7 @@ describe Spree::Order do
end
it "has errors if email has invalid domain" do
order.stub(require_email: true)
allow(order).to receive_messages(require_email: true)
order.email = "single_letter_tld@domain.z"
order.valid?
@@ -538,7 +538,7 @@ describe Spree::Order do
end
it "is valid if email is valid" do
order.stub(require_email: true)
allow(order).to receive_messages(require_email: true)
order.email = "a@b.ca"
order.valid?

View File

@@ -15,7 +15,7 @@ describe Spree::ReturnAuthorization do
end
it "should generate RMA number" do
return_authorization.should_receive(:generate_number)
expect(return_authorization).to receive(:generate_number)
return_authorization.save
end
end
@@ -33,7 +33,7 @@ describe Spree::ReturnAuthorization do
end
it "should update order state" do
order.should_receive(:authorize_return!)
expect(order).to receive(:authorize_return!)
return_authorization.add_variant(variant.id, 1)
end
end
@@ -56,12 +56,12 @@ describe Spree::ReturnAuthorization do
context "can_receive?" do
it "should allow_receive when inventory units assigned" do
return_authorization.stub(inventory_units: [1, 2, 3])
allow(return_authorization).to receive_messages(inventory_units: [1, 2, 3])
expect(return_authorization.can_receive?).to be_truthy
end
it "should not allow_receive with no inventory units" do
return_authorization.stub(inventory_units: [])
allow(return_authorization).to receive_messages(inventory_units: [])
expect(return_authorization.can_receive?).to be_falsy
end
end
@@ -70,28 +70,28 @@ describe Spree::ReturnAuthorization do
let(:inventory_unit) { order.shipments.first.inventory_units.first }
before do
return_authorization.stub(inventory_units: [inventory_unit], amount: -20)
Spree::Adjustment.stub(:create)
order.stub(:update!)
allow(return_authorization).to receive_messages(inventory_units: [inventory_unit], amount: -20)
allow(Spree::Adjustment).to receive(:create)
allow(order).to receive(:update!)
end
it "should mark all inventory units are returned" do
inventory_unit.should_receive(:return!)
expect(inventory_unit).to receive(:return!)
return_authorization.receive!
end
it "should add credit for specified amount" do
return_authorization.amount = 20
mock_adjustment = double
mock_adjustment.should_receive(:source=).with(return_authorization)
mock_adjustment.should_receive(:adjustable=).with(order)
mock_adjustment.should_receive(:save)
Spree::Adjustment.should_receive(:new).with(amount: -20, label: Spree.t(:rma_credit)).and_return(mock_adjustment)
expect(mock_adjustment).to receive(:source=).with(return_authorization)
expect(mock_adjustment).to receive(:adjustable=).with(order)
expect(mock_adjustment).to receive(:save)
expect(Spree::Adjustment).to receive(:new).with(amount: -20, label: Spree.t(:rma_credit)).and_return(mock_adjustment)
return_authorization.receive!
end
it "should update order state" do
order.should_receive :update!
expect(order).to receive :update!
return_authorization.receive!
end
end
@@ -106,13 +106,13 @@ describe Spree::ReturnAuthorization do
context "after_save" do
it "should run correct callbacks" do
return_authorization.should_receive(:force_positive_amount)
expect(return_authorization).to receive(:force_positive_amount)
return_authorization.run_callbacks(:save)
end
end
context "currency" do
before { order.stub(:currency) { "ABC" } }
before { allow(order).to receive(:currency) { "ABC" } }
it "returns the order currency" do
expect(return_authorization.currency).to eq "ABC"
end