Skip to content
Browse files

Added CheddarGetter#update_customer

  • Loading branch information...
1 parent 9b05afb commit de5c78eea171c2a005ed0f58051053d28bb831b5 @blaix blaix committed
Showing with 21 additions and 0 deletions.
  1. +9 −0 lib/cheddargetter.rb
  2. +12 −0 spec/cheddargetter_spec.rb
View
9 lib/cheddargetter.rb
@@ -68,6 +68,15 @@ def create_customer(attributes)
normalize(response, 'customers', 'customer')
end
+ # Attributes are the same as #create_customer
+ # Only included attributes will be udpated.
+ # Credit Card information is only required if the plan is not free and
+ # no credit card information is already saved.
+ def update_customer(customer_code, attributes)
+ response = post("/customers/edit/productCode/#{@product_code}/code/#{customer_code}", :body => attributes)
+ normalize(response, 'customers', 'customer')
+ end
+
private
def get(path)
View
12 spec/cheddargetter_spec.rb
@@ -110,6 +110,18 @@
end
end
+ describe 'calling #update_customer(customer_code, attributes)' do
+ it "should return the updated customer" do
+ mock_request(:post, "/customers/edit/productCode/MY_PRODUCT/code/MY_CUSTOMER", "<customers><customer>updated customer</customer></customers>")
+ @cheddar_getter.update_customer('MY_CUSTOMER', :name => "new name").should == "updated customer"
+ end
+
+ it "should raise if an error is returned" do
+ mock_request(:post, "/customers/edit/productCode/MY_PRODUCT/code/MY_CUSTOMER", "<error>failed update</error>")
+ lambda { @cheddar_getter.update_customer('MY_CUSTOMER', :name => "new name") }.should raise_error(CheddarGetter::Error, 'failed update')
+ end
+ end
+
def mock_request(method, request_path, response_xml)
request_path.gsub!(/^\//, '')
options = { :body => response_xml, :content_type => "text/xml" }

0 comments on commit de5c78e

Please sign in to comment.
Something went wrong with that request. Please try again.