From c2aa516f0bf8a6a6a6bc64f65aecdd45ca6fc05d Mon Sep 17 00:00:00 2001 From: Gabe Berke-Williams Date: Sun, 20 Nov 2011 18:50:26 -0500 Subject: [PATCH] Braintree::Customer.delete --- README.md | 1 + lib/fake_braintree/customer.rb | 11 ++++++++++- lib/fake_braintree/sinatra_app.rb | 7 +++++++ spec/fake_braintree/customer_spec.rb | 10 ++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a3d07a9..edd53a3 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ Currently in alpha (i.e. it does not support every Braintree call). * `Braintree::Customer.find` * `Braintree::Customer.create` * `Braintree::Customer.update` +* `Braintree::Customer.delete` ### Subscription * `Braintree::Subscription.find` diff --git a/lib/fake_braintree/customer.rb b/lib/fake_braintree/customer.rb index c85233f..cbc7866 100644 --- a/lib/fake_braintree/customer.rb +++ b/lib/fake_braintree/customer.rb @@ -26,6 +26,11 @@ def update end end + def delete + FakeBraintree.customers[existing_customer_id] = nil + gzipped_response(200, '') + end + def customer_hash hash = @customer_hash.dup hash["id"] ||= create_id @@ -58,7 +63,7 @@ def split_expiration_date_into_month_and_year!(hash) end def existing_customer_hash - @customer_hash['id'] && FakeBraintree.customers[@customer_hash["id"]] + existing_customer_id && FakeBraintree.customers[existing_customer_id] end def update_existing_customer! @@ -110,5 +115,9 @@ def has_credit_card_number? def credit_card_number has_credit_card_number? && @customer_hash["credit_card"]["number"] end + + def existing_customer_id + @customer_hash['id'] + end end end diff --git a/lib/fake_braintree/sinatra_app.rb b/lib/fake_braintree/sinatra_app.rb index a4c08df..fb72d68 100644 --- a/lib/fake_braintree/sinatra_app.rb +++ b/lib/fake_braintree/sinatra_app.rb @@ -33,6 +33,13 @@ class SinatraApp < Sinatra::Base Customer.new(customer_hash, options).update end + # Braintree::Customer.delete + delete "/merchants/:merchant_id/customers/:id" do + customer_hash = {} + options = {:id => params[:id], :merchant_id => params[:merchant_id]} + Customer.new(customer_hash, options).delete + end + # Braintree::Subscription.create post "/merchants/:merchant_id/subscriptions" do subscription_hash = Hash.from_xml(request.body).delete("subscription") diff --git a/spec/fake_braintree/customer_spec.rb b/spec/fake_braintree/customer_spec.rb index bf5c64f..beab924 100644 --- a/spec/fake_braintree/customer_spec.rb +++ b/spec/fake_braintree/customer_spec.rb @@ -88,3 +88,13 @@ lambda { Braintree::Customer.update("foo", {:first_name => "Bob"}) }.should raise_error(Braintree::NotFoundError) end end + +describe "Braintree::Customer.delete" do + it "successfully deletes a customer" do + customer_id = create_customer.customer.id + result = Braintree::Customer.delete(customer_id) + + result.should be_success + expect { Braintree::Customer.find(customer_id) }.to raise_error(Braintree::NotFoundError) + end +end