Sha256: 9ed8cd3ad4ee85b2b20d21b783e0c8bcb90e1e50491d78440bd3ebb87cc1fc25

Contents?: true

Size: 1.43 KB

Versions: 32

Compression:

Stored size: 1.43 KB

Contents

require 'spec_helper'

module Spree
  describe ReimbursementType::Exchange, type: :model do
    describe '.reimburse' do
      let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
      let(:return_items)  { reimbursement.return_items }
      let(:new_exchange)  { double("Exchange") }
      let(:simulate)      { true }

      subject { Spree::ReimbursementType::Exchange.reimburse(reimbursement, return_items, simulate) }

      context 'return items are supplied' do
        before do
          expect(Spree::Exchange).to receive(:new).with(reimbursement.order, return_items).and_return(new_exchange)
        end

        context "simulate is true" do
          it 'does not perform an exchange and returns the exchange object' do
            expect(new_exchange).not_to receive(:perform!)
            expect(subject).to eq [new_exchange]
          end
        end

        context "simulate is false" do
          let(:simulate) { false }

          it 'performs an exchange and returns the exchange object' do
            expect(new_exchange).to receive(:perform!)
            expect(subject).to eq [new_exchange]
          end
        end
      end

      context "no return items are supplied" do
        let(:return_items) { [] }

        it 'does not perform an exchange and returns an empty array' do
          expect(new_exchange).not_to receive(:perform!)
          expect(subject).to eq []
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
solidus_core-2.3.1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.2.2 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.1.1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.0.3 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-1.4.2 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-1.3.2 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.3.0 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.3.0.rc3 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.3.0.rc2 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.3.0.rc1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.3.0.beta1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.0.2 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-1.4.1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.2.1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.2.0 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.2.0.rc1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.2.0.beta1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.1.0 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.1.0.rc1 spec/models/spree/reimbursement_type/exchange_spec.rb
solidus_core-2.0.1 spec/models/spree/reimbursement_type/exchange_spec.rb