Sha256: d9a953edc67692ca467568e119155190beb30be9e64f636e62d3c90d900c164c

Contents?: true

Size: 1.91 KB

Versions: 22

Compression:

Stored size: 1.91 KB

Contents

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

22 entries across 22 versions & 1 rubygems

Version Path
solidus_core-2.5.2 spec/support/concerns/payment_source.rb
solidus_core-2.5.1 spec/support/concerns/payment_source.rb
solidus_core-2.5.0 spec/support/concerns/payment_source.rb
solidus_core-2.5.0.rc1 spec/support/concerns/payment_source.rb
solidus_core-2.5.0.beta2 spec/support/concerns/payment_source.rb
solidus_core-2.5.0.beta1 spec/support/concerns/payment_source.rb
solidus_core-2.4.2 spec/support/concerns/payment_source.rb
solidus_core-2.3.1 spec/support/concerns/payment_source.rb
solidus_core-2.4.1 spec/support/concerns/payment_source.rb
solidus_core-2.2.2 spec/support/concerns/payment_source.rb
solidus_core-2.4.0 spec/support/concerns/payment_source.rb
solidus_core-2.4.0.rc1 spec/support/concerns/payment_source.rb
solidus_core-2.4.0.beta1 spec/support/concerns/payment_source.rb
solidus_core-2.3.0 spec/support/concerns/payment_source.rb
solidus_core-2.3.0.rc3 spec/support/concerns/payment_source.rb
solidus_core-2.3.0.rc2 spec/support/concerns/payment_source.rb
solidus_core-2.3.0.rc1 spec/support/concerns/payment_source.rb
solidus_core-2.3.0.beta1 spec/support/concerns/payment_source.rb
solidus_core-2.2.1 spec/support/concerns/payment_source.rb
solidus_core-2.2.0 spec/support/concerns/payment_source.rb