Sha256: 64c4943e1ab4d8389ee7d8ba9a2764eec70ee4b11bd6503bc7192690272021ac

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '../unit_test_helper'))

describe BraintreeRails::CreditCards do
  before do
    stub_braintree_request(:get, '/customers/customer_id', :body => fixture('customer.xml'))
  end

  describe '#initialize' do
    it 'should wrap an array of Braintree::CreditCard' do
      braintree_customer = Braintree::Customer.find('customer_id')
      braintree_credit_cards = braintree_customer.credit_cards
      credit_cards = BraintreeRails::CreditCards.new(braintree_customer, braintree_credit_cards)
      
      credit_cards.size.must_equal braintree_credit_cards.size

      braintree_credit_cards.each do |braintree_credit_card|
        credit_card = credit_cards.find(braintree_credit_card.token)
        BraintreeRails::CreditCard::Attributes.each do |attribute|
          credit_card.send(attribute).must_equal braintree_credit_card.send(attribute) if braintree_credit_card.respond_to?(attribute)
        end
      end
    end
  end

  describe '#build' do
    it 'should build new CreditCard object with customer_id and params' do
      braintree_customer = Braintree::Customer.find('customer_id')
      braintree_credit_cards = braintree_customer.credit_cards
      credit_cards = BraintreeRails::CreditCards.new(braintree_customer, braintree_credit_cards)
      credit_card = credit_cards.build({:first_name => 'foo', :last_name => 'bar'})

      credit_card.persisted?.must_equal false
      credit_card.customer_id.must_equal braintree_customer.id
      credit_card.first_name.must_equal 'foo'
      credit_card.last_name.must_equal 'bar'
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
braintree-rails-0.2.0 test/unit/braintree_rails/credit_cards_test.rb
braintree-rails-0.1.0 test/unit/braintree_rails/credit_cards_test.rb
braintree-rails-0.0.2 test/unit/braintree_rails/credit_cards_test.rb
braintree-rails-0.0.1 test/unit/braintree_rails/credit_cards_test.rb