Sha256: 4e67695053a7578814ce0166d8e62c9bbe50bc89a2a4707be1e9a0d236d32bff

Contents?: true

Size: 1.94 KB

Versions: 48

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

RSpec.shared_examples "a payment source" do
  subject(:payment_source) { described_class.new }

  describe 'attributes' do
    it { is_expected.to respond_to(:imported) }
    it { is_expected.to respond_to(:name) }
  end

  describe "#associations" do
    it { is_expected.to respond_to(:payments) }
    it { is_expected.to respond_to(:user) }
  end

  describe "#can_capture?" do
    it "should be true if payment is pending" do
      payment = mock_model(Spree::Payment, pending?: true, created_at: Time.current)
      expect(payment_source.can_capture?(payment)).to be true
    end

    it "should be true if payment is checkout" do
      payment = mock_model(Spree::Payment, pending?: false, checkout?: true, created_at: Time.current)
      expect(payment_source.can_capture?(payment)).to be true
    end
  end

  describe "#can_void?" do
    it "should be true if payment is not void" do
      payment = mock_model(Spree::Payment, failed?: false, void?: false)
      expect(payment_source.can_void?(payment)).to be true
    end
  end

  describe "#can_credit?" do
    it "should be false if payment is not completed" do
      payment = mock_model(Spree::Payment, completed?: false)
      expect(payment_source.can_credit?(payment)).to be false
    end

    it "should be false when credit_allowed is zero" do
      payment = mock_model(Spree::Payment, completed?: true, credit_allowed: 0, order: mock_model(Spree::Order, payment_state: 'credit_owed'))
      expect(payment_source.can_credit?(payment)).to be false
    end
  end

  describe "#first_name" do
    before do
      payment_source.name = "Ludwig van Beethoven"
    end

    it "extracts the first name" do
      expect(payment_source.first_name).to eq "Ludwig"
    end
  end

  describe "#last_name" do
    before do
      payment_source.name = "Ludwig van Beethoven"
    end

    it "extracts the last name" do
      expect(payment_source.last_name).to eq "van Beethoven"
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
solidus_core-2.10.5 spec/support/concerns/payment_source.rb
solidus_core-2.10.3 spec/support/concerns/payment_source.rb
solidus_core-2.10.2 spec/support/concerns/payment_source.rb
solidus_core-2.9.6 spec/support/concerns/payment_source.rb
solidus_core-2.8.6 spec/support/concerns/payment_source.rb
solidus_core-2.10.1 spec/support/concerns/payment_source.rb
solidus_core-2.9.5 spec/support/concerns/payment_source.rb
solidus_core-2.10.0 spec/support/concerns/payment_source.rb
solidus_core-2.9.4 spec/support/concerns/payment_source.rb
solidus_core-2.6.6 spec/support/concerns/payment_source.rb
solidus_core-2.7.4 spec/support/concerns/payment_source.rb
solidus_core-2.8.5 spec/support/concerns/payment_source.rb
solidus_core-2.9.3 spec/support/concerns/payment_source.rb
solidus_core-2.9.2 spec/support/concerns/payment_source.rb
solidus_core-2.10.0.beta1 spec/support/concerns/payment_source.rb
solidus_core-2.7.3 spec/support/concerns/payment_source.rb
solidus_core-2.6.5 spec/support/concerns/payment_source.rb
solidus_core-2.9.1 spec/support/concerns/payment_source.rb
solidus_core-2.9.0 spec/support/concerns/payment_source.rb
solidus_core-2.9.0.rc.1 spec/support/concerns/payment_source.rb