spec/models/spree/shipment_spec.rb in solidus_signifyd-1.0.1 vs spec/models/spree/shipment_spec.rb in solidus_signifyd-1.1.0

- old
+ new

@@ -3,55 +3,53 @@ describe Spree::Shipment, :type => :model do let(:shipment) { create(:shipment) } subject { shipment.determine_state(shipment.order) } - describe "#determine_state_with_signifyd" do - - context "with a risky order" do - before { shipment.order.stub(:is_risky?).and_return(true) } - - context "the order is not approved" do - it "returns pending" do - shipment.order.stub(:approved?).and_return(false) - subject.should eq "pending" - end + describe "#determine_state" do + context "with a canceled order" do + before do + shipment.order.update(state: 'canceled') + shipment.update(state: 'canceled') end - context "the order is approved" do - it "defaults to existing behavior" do - shipment.order.stub(:approved?).and_return(true) - shipment.should_receive(:determine_state).with(shipment.order) - subject - end + it "canceled shipments remain canceled" do + expect(subject).to eq "canceled" end end - context "without a risky order" do - before { shipment.order.stub(:is_risky?).and_return(false) } + context "with an approved order" do + before { shipment.order.contents.approve(name: 'test approver') } - it "defaults to existing behavior" do - shipment.should_receive(:determine_state).with(shipment.order) - subject + it "pending shipments remain pending" do + expect(subject).to eq "pending" end - end - context "shipment state" do - [:shipped, :ready].each do |state| - context "the shipment is #{state}" do - before { shipment.update_columns(state: state) } - it "defaults to existing behavior" do - shipment.should_receive(:determine_state).with(shipment.order) - subject + 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 - end - [:pending, :canceled].each do |state| - context "the shipment is #{state}" do - before { shipment.update_columns(state: state) } - it "is pending" do - subject.should eq "pending" + 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