Sha256: 58220afb9c74542ad502d2d87b04869749935924d354848c6f518e0ae063d5de

Contents?: true

Size: 1.63 KB

Versions: 6

Compression:

Stored size: 1.63 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

  it "returns exchange multiplier for gateway" do
    gateway = TestGateway.new

    rate = Spree::Gateway::FROM_DOLLAR_TO_CENT_RATE
    expect(gateway.exchange_multiplier).to eq rate
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
spree_core-3.3.0.rc1 spec/models/spree/gateway_spec.rb
spree_core-3.2.1 spec/models/spree/gateway_spec.rb
spree_core-3.2.0 spec/models/spree/gateway_spec.rb
spree_core-3.2.0.rc3 spec/models/spree/gateway_spec.rb
spree_core-3.2.0.rc2 spec/models/spree/gateway_spec.rb
spree_core-3.2.0.rc1 spec/models/spree/gateway_spec.rb