Sha256: fca62f8ee2f3543ea03d5dc42e93ec4fac19417abbe0f10ffc6a160712f29eae

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

require 'spec_helper'

describe Spree::Gateway, :type => :model do
  class Provider
    def initialize(options)
    end

    def imaginary_method

    end
  end

  class TestGateway < Spree::Gateway
    def provider_class
      Provider
    end
  end

  it "passes through all arguments on a method_missing call" do
    gateway = TestGateway.new
    expect(gateway.provider).to receive(:imaginary_method).with('foo')
    gateway.imaginary_method('foo')
  end

  context "fetching payment sources" do
    let(:order) { Spree::Order.create(user_id: 1) }

    let(:has_card) { create(:credit_card_payment_method) }
    let(:no_card) { create(:credit_card_payment_method) }

    let(:cc) do
      create(:credit_card, payment_method: has_card, gateway_customer_profile_id: "EFWE")
    end

    let(:payment) do
      create(:payment, order: order, source: cc, payment_method: has_card)
    end

    it "finds credit cards associated on a order completed" do
      allow(payment.order).to receive_messages completed?: true

      expect(no_card.reusable_sources(payment.order)).to be_empty
      expect(has_card.reusable_sources(payment.order)).not_to be_empty
    end

    it "finds credit cards associated with the order user" do
      cc.update_column :user_id, 1
      allow(payment.order).to receive_messages completed?: false

      expect(no_card.reusable_sources(payment.order)).to be_empty
      expect(has_card.reusable_sources(payment.order)).not_to be_empty
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_core-3.0.10 spec/models/spree/gateway_spec.rb
spree_core-3.0.9 spec/models/spree/gateway_spec.rb
spree_core-3.0.8 spec/models/spree/gateway_spec.rb
spree_core-3.0.7 spec/models/spree/gateway_spec.rb
spree_core-3.0.6.1 spec/models/spree/gateway_spec.rb
spree_core-3.0.6 spec/models/spree/gateway_spec.rb