Skip to content

Commit

Permalink
Support Braintree::Customer.find
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Nov 7, 2011
1 parent 26cbdd3 commit 32ad3cc
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/fake_braintree/customer.rb
Expand Up @@ -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?
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/fake_braintree/sinatra_app.rb
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion spec/fake_braintree/customer_spec.rb
@@ -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 }
Expand Down Expand Up @@ -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.