Permalink
Browse files

Added Customer#credit_cards

* Provides a list of credit cards from the remote_customer
* Removed has from "it 'has returns its first credit card'"
  • Loading branch information...
1 parent 2a7a1da commit f286ddf5315359a67e47149788a3e773f7f17d7f @halogenandtoast halogenandtoast committed Jun 6, 2012
Showing with 24 additions and 2 deletions.
  1. +7 −1 lib/ashmont/customer.rb
  2. +17 −1 spec/ashmont/customer_spec.rb
View
8 lib/ashmont/customer.rb
@@ -12,8 +12,14 @@ def initialize(token = nil)
end
def credit_card
+ credit_cards[0]
+ end
+
+ def credit_cards
if persisted?
- remote_customer.credit_cards[0]
+ remote_customer.credit_cards
+ else
+ []
end
end
View
18 spec/ashmont/customer_spec.rb
@@ -2,7 +2,7 @@
require 'ashmont/customer'
describe Ashmont::Customer do
- it "has returns its first credit card" do
+ it "returns its first credit card" do
token = "xyz"
remote_customer = stub("customer", :credit_cards => ["first", "second"])
Braintree::Customer.stubs(:find => remote_customer)
@@ -17,6 +17,22 @@
Ashmont::Customer.new.credit_card.should be_nil
end
+ it "returns all credit cards" do
+ token = "xyz"
+ remote_customer = stub("customer", :credit_cards => ["first", "second"])
+ Braintree::Customer.stubs(:find => remote_customer)
+
+ result = Ashmont::Customer.new(token).credit_cards
+
+ Braintree::Customer.should have_received(:find).with(token)
+ result.should == ["first", "second"]
+ end
+
+ it "returns an empty array without a remote customer" do
+ Ashmont::Customer.new.credit_cards.should == []
+ end
+
+
it "returns the remote email" do
remote_customer = stub("customer", :email => "admin@example.com")
Braintree::Customer.stubs(:find => remote_customer)

0 comments on commit f286ddf

Please sign in to comment.