Permalink
Browse files

Support Braintree::Customer.find

  • Loading branch information...
1 parent 26cbdd3 commit 32ad3cc67f152a481fd81a1964c9f27902671154 Gabe Berke-Williams committed Nov 7, 2011
Showing with 34 additions and 3 deletions.
  1. +4 −2 lib/fake_braintree/customer.rb
  2. +10 −0 lib/fake_braintree/sinatra_app.rb
  3. +20 −1 spec/fake_braintree/customer_spec.rb
@@ -43,7 +43,8 @@ def create_id
end
def credit_card_is_failure?
- FakeBraintree.failure?(@request_hash["credit_card"]["number"])
+ @request_hash.key?('credit_card') &&
+ FakeBraintree.failure?(@request_hash["credit_card"]["number"])
end
def invalid_credit_card?
@@ -53,7 +54,8 @@ def invalid_credit_card?
def verify_credit_card?(customer_hash)
return true if FakeBraintree.verify_all_cards
- @request_hash["credit_card"].key?("options") &&
+ @request_hash.key?("credit_card") &&
+ @request_hash["credit_card"].key?("options") &&
@request_hash["credit_card"]["options"].is_a?(Hash) &&
@request_hash["credit_card"]["options"]["verify_card"] == true
end
@@ -21,6 +21,16 @@ class SinatraApp < Sinatra::Base
end
end
+ # Braintree::Customer.find
+ get "/merchants/:merchant_id/customers/:id" do
+ customer = FakeBraintree.customers[params[:id]]
+ if customer
+ gzipped_response(200, customer.to_xml(:root => 'customer'))
+ else
+ gzipped_response(404, {})
+ end
+ end
+
# Braintree::Subscription.create
post "/merchants/:merchant_id/subscriptions" do
response_hash = Subscription.new(request).response_hash
@@ -1,6 +1,6 @@
require 'spec_helper'
-describe FakeBraintree::SinatraApp, "Braintree::Customer.create" do
+describe "Braintree::Customer.create" do
let(:cc_number) { %w(4111 1111 1111 1111).join }
let(:expiration_date) { "04/2016" }
after { FakeBraintree.verify_all_cards = false }
@@ -71,3 +71,22 @@ def create_customer_with_credit_card(options)
end
end
end
+
+describe "Braintree::Customer.find" do
+ let(:cc_number) { %w(4111 1111 1111 1111).join }
+ let(:expiration_date) { "04/2016" }
+
+ def create_customer(options)
+ Braintree::Customer.create(:credit_card => options)
+ end
+
+ it "successfully finds a customer" do
+ result = Braintree::Customer.create(:first_name => "Bob", :last_name => "Smith")
+
+ Braintree::Customer.find(result.customer.id).first_name.should == "Bob"
+ end
+
+ it "raises an error for a nonexistent customer" do
+ lambda { Braintree::Customer.find("foo") }.should raise_error(Braintree::NotFoundError)
+ end
+end

0 comments on commit 32ad3cc

Please sign in to comment.