Sha256: 7e1b0b7b5c7a69331712e0a725073cd79ea4640105f6f802a5369a2a95b2ed2d

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

require 'spec_helper'

describe Chargify::Customer do
  context '.find_by_reference' do
    let(:existing_customer) { Chargify::Customer.create(:id => 5, :reference => 'sigma') }

    before(:each) do
      FakeWeb.register_uri(:get, "#{test_domain}/customers/lookup.xml?reference=#{existing_customer.reference}", :body => existing_customer.attributes.to_xml)
    end
    
    it 'finds the correct customer by reference' do
      customer = Chargify::Customer.find_by_reference('sigma')
      customer.should == existing_customer
    end
    
    it 'is an instance of Chargify::Customer' do
      customer = Chargify::Customer.find_by_reference('sigma')
      customer.should be_instance_of(Chargify::Customer)
    end

    it 'is marked as persisted' do
      customer = Chargify::Customer.find_by_reference('sigma')
      customer.persisted?.should == true
    end
  end

  context "#subscriptions" do
    let(:customer) { Chargify::Customer.create(:id => 5, :reference => 'sigma') }
    let(:subscription_1) { Chargify::Customer::Subscription.create(:customer_id => customer.id, :balance_in_cents => 4999) }
    let(:subscription_2) { Chargify::Customer::Subscription.create(:customer_id => customer.id, :balance_in_cents => 2499) }

    before(:each) do
      FakeWeb.register_uri(:get, "#{test_domain}/customers/#{customer.id}/subscriptions.xml", :body => [subscription_1.attributes, subscription_2.attributes].to_xml)
    end

    it "returns the subscriptions belonging to the customer" do
      customer.subscriptions.should =~ [subscription_1, subscription_2]
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chargify_api_ares-0.5.4 spec/resources/customer_spec.rb
chargify_api_ares-0.5.2 spec/resources/customer_spec.rb
chargify_api_ares-0.5.1 spec/resources/customer_spec.rb