Sha256: 505ffdcb4c5a3a3aad0a74c6a8efb8ec95342f553836b29275c8df265c2f9159

Contents?: true

Size: 1.58 KB

Versions: 1

Compression:

Stored size: 1.58 KB

Contents

require 'spec_helper'

describe Spree::Shipment, :type => :model do

  let(:shipment) { create(:shipment) }
  subject { shipment.determine_state(shipment.order) }

  describe "#determine_state" do
    context "with a canceled order" do
      before do
        shipment.order.update(state: 'canceled')
        shipment.update(state: 'canceled')
      end

      it "canceled shipments remain canceled" do
        expect(subject).to eq "canceled"
      end
    end

    context "with an approved order" do
      before { shipment.order.contents.approve(name: 'test approver') }

      it "pending shipments remain pending" do
        expect(subject).to eq "pending"
      end

      describe "regular Solidus behaviour" do
        context "order cannot ship" do
          before { allow(shipment.order).to receive_messages can_ship?: false }

          it 'returns pending' do
            expect(subject).to eq 'pending'
          end
        end

        context "order can ship" do
          before { allow(shipment.order).to receive_messages can_ship?: true }

          it 'returns shipped when already shipped' do
            allow(shipment).to receive_messages state: 'shipped'
            expect(subject).to eq 'shipped'
          end

          it 'returns pending when unpaid' do
            allow(shipment.order).to receive_messages paid?: false
            expect(subject).to eq 'pending'
          end

          it 'returns ready when paid' do
            allow(shipment.order).to receive_messages paid?: true
            expect(subject).to eq 'ready'
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solidus_signifyd-1.1.0 spec/models/spree/shipment_spec.rb