Skip to content

Commit

Permalink
Braintree::Customer.delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Nov 20, 2011
1 parent 917a235 commit c2aa516
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -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`
Expand Down
11 changes: 10 additions & 1 deletion lib/fake_braintree/customer.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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
7 changes: 7 additions & 0 deletions lib/fake_braintree/sinatra_app.rb
Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions spec/fake_braintree/customer_spec.rb
Expand Up @@ -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

0 comments on commit c2aa516

Please sign in to comment.