Skip to content

Commit

Permalink
Don't allow customers to be updated with failing credit cards.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Feb 3, 2012
1 parent 783719c commit a2ceb58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/fake_braintree/customer.rb
Expand Up @@ -24,9 +24,13 @@ def create

def update
if customer_exists_in_registry?
updates = customer_hash
updated_customer = update_existing_customer(updates)
response_for_updated_customer(updated_customer)
if credit_card_is_failure?
response_for_invalid_card
else
updates = customer_hash
updated_customer = update_existing_customer(updates)
response_for_updated_customer(updated_customer)
end
else
response_for_customer_not_found
end
Expand Down
9 changes: 9 additions & 0 deletions spec/fake_braintree/customer_spec.rb
Expand Up @@ -109,6 +109,15 @@
it "raises an error for a nonexistent customer" do
lambda { Braintree::Customer.update("foo", {:first_name => "Bob"}) }.should raise_error(Braintree::NotFoundError)
end

it "does not allow a customer to be updated to a failing credit card" do
bad_credit_card = "123456"
FakeBraintree.registry.failures[bad_credit_card] = FakeBraintree.failure_response

customer = create_customer
result = Braintree::Customer.update(customer.customer.id, {:credit_card => { :number => bad_credit_card }})
result.should_not be_success
end
end

describe "Braintree::Customer.delete" do
Expand Down

0 comments on commit a2ceb58

Please sign in to comment.