Skip to content

Commit

Permalink
Added CheddarGetter#update_customer
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Blake committed Sep 28, 2009
1 parent 9b05afb commit de5c78e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/cheddargetter.rb
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions spec/cheddargetter_spec.rb
Expand Up @@ -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" }
Expand Down

0 comments on commit de5c78e

Please sign in to comment.