Sha256: db274872205020f18116bad2a8eb50ccc8d835e586b520c90cc32c1c0c8a899b

Contents?: true

Size: 1.99 KB

Versions: 72

Compression:

Stored size: 1.99 KB

Contents

require 'spec_helper'

require 'stripe_mock'

# # Attributes
describe Effective::Customer do
  let(:customer) { FactoryGirl.create(:customer) }
  let(:user) { FactoryGirl.create(:user) }

  describe 'Customer.for_user' do
    it 'creates a new Customer when passed a new user' do
      c = Effective::Customer.for_user(user)

      c.kind_of?(Effective::Customer).should eq true
      c.persisted?.should eq true
      c.valid?.should eq true
      c.user.should eq user
    end

    it 'returns an existing Customer when passed an existing user' do
      c =  Effective::Customer.for_user(customer.user)
      c.should eq customer
    end
  end

  describe 'Stripe Integration' do
    before { StripeMock.start }
    after { StripeMock.stop }
    let(:stripe_helper) { StripeMock.create_test_helper }

    describe '#stripe_customer' do
      it 'creates a new Stripe::Customer if one doesnt exist.' do
        stripe_customer = customer.stripe_customer

        stripe_customer.kind_of?(::Stripe::Customer).should eq true

        stripe_customer.email.should eq customer.user.email
        stripe_customer.id.should eq customer.stripe_customer_id
      end

      it 'retrieves an existing Stripe::Customer if exists' do
        # Test set up. Create the user.
        user = customer.user
        stripe_customer = ::Stripe::Customer.create(:email => user.email, :description => user.id.to_s)
        customer.update_attributes(:stripe_customer_id => stripe_customer.id)

        customer.reload

        customer.stripe_customer.id.should eq stripe_customer.id
      end
    end

    describe '#update_card' do
      it 'can update the card' do
        customer.update_card!(stripe_helper.generate_card_token).should eq true
      end

      it 'updates stripe_active_card when updating the card' do
        customer.should_receive(:save!).and_return(true)
        customer.update_card!(stripe_helper.generate_card_token).should eq true

        customer.stripe_active_card.present?.should eq true
      end

    end

  end




end

Version data entries

72 entries across 72 versions & 1 rubygems

Version Path
effective_orders-1.5.7 spec/models/customer_spec.rb
effective_orders-1.5.5 spec/models/customer_spec.rb
effective_orders-1.5.4 spec/models/customer_spec.rb
effective_orders-1.5.3 spec/models/customer_spec.rb
effective_orders-1.5.2 spec/models/customer_spec.rb
effective_orders-1.5.1 spec/models/customer_spec.rb
effective_orders-1.5.0 spec/models/customer_spec.rb
effective_orders-1.4.8 spec/models/customer_spec.rb
effective_orders-1.4.7 spec/models/customer_spec.rb
effective_orders-1.4.6 spec/models/customer_spec.rb
effective_orders-1.4.5 spec/models/customer_spec.rb
effective_orders-1.4.4 spec/models/customer_spec.rb
effective_orders-1.4.3 spec/models/customer_spec.rb
effective_orders-1.4.2 spec/models/customer_spec.rb
effective_orders-1.4.1 spec/models/customer_spec.rb
effective_orders-1.4.0 spec/models/customer_spec.rb
effective_orders-1.3.13 spec/models/customer_spec.rb
effective_orders-1.3.12 spec/models/customer_spec.rb
effective_orders-1.3.11 spec/models/customer_spec.rb
effective_orders-1.3.10 spec/models/customer_spec.rb