Permalink
Browse files

Add Customer.update functionality

  • Loading branch information...
1 parent 838bce6 commit 4e71052f5d5e001d96a33522e62b5a94569e76c5 @l4rk l4rk committed Oct 26, 2009
Showing with 108 additions and 0 deletions.
  1. +6 −0 lib/mousetrap/customer.rb
  2. +76 −0 spec/integration/smoke_test.rb
  3. +26 −0 spec/mousetrap/customer_spec.rb
@@ -90,6 +90,12 @@ def self.new_from_api(attributes)
customer
end
+ def self.update(customer_code, attributes)
+ customer = new(attributes)
+ customer.code = customer_code
+ customer.send :update
+ end
+
protected
@@ -137,6 +137,82 @@
end
end
+ describe ".update" do
+ describe "Given a customer" do
+ before :all do
+ @customer = Factory :new_customer
+ @api_customer = nil
+
+ # TODO: figure out why multiple records are being created even though
+ # we use "before :all". Until then, here's the kludge...
+ if Mousetrap::Customer.all.size == 1
+ @api_customer = Mousetrap::Customer.all.first
+ @customer = @api_customer
+ else
+ @customer.save
+ @api_customer = Mousetrap::Customer[@customer.code]
+ end
+ end
+
+ describe "When I update the customer, with only customer attributes" do
+ before :all do
+ @api_customer = Mousetrap::Customer[@customer.code]
+
+ updated_attributes = {
+ :first_name => 'new_first',
+ :last_name => 'new_last',
+ :email => 'new_email@example.com',
+ :company => 'new_company'
+ }
+
+ @customer = Mousetrap::Customer.new updated_attributes
+ @customer.code = @api_customer.code
+ @customer.id = @api_customer.id
+
+ Mousetrap::Customer.update(@api_customer.code, updated_attributes)
+ end
+
+ it_should_behave_like "a Customer record from CheddarGetter"
+ end
+
+ describe "When I update the customer, with customer and subscription attributes" do
+ before :all do
+ @api_customer = Mousetrap::Customer[@customer.code]
+
+ updated_attributes = {
+ :first_name => 'new_first',
+ :last_name => 'new_last',
+ :email => 'new_email@example.com',
+ :company => 'new_company',
+ :subscription_attributes => {
+ :plan_code => 'TEST',
+ :billing_first_name => 'new_billing_first',
+ :billing_last_name => 'new_billing_last',
+ :credit_card_number => '5555555555554444',
+ :credit_card_expiration_month => '01',
+ :credit_card_expiration_year => '2013',
+ :billing_zip_code => '12345'
+ }
+ }
+
+ @credit_card_type = 'mc'
+
+ @customer = Mousetrap::Customer.new updated_attributes
+
+ # set up our test comparison objects as if they came from API gets
+ @customer.code = @api_customer.code
+ @customer.id = @api_customer.id
+ @customer.subscription.send(:id=, @api_customer.subscription.id)
+
+ Mousetrap::Customer.update(@api_customer.code, updated_attributes)
+ end
+
+ it_should_behave_like "a Customer record from CheddarGetter"
+ it_should_behave_like "an active Subscription record from CheddarGetter"
+ end
+ end
+ end
+
describe "#cancel" do
describe "Given a customer" do
before :all do
@@ -114,6 +114,32 @@ def customer_attributes_for_api(customer)
end
end
+ describe '.update' do
+ def do_update
+ Mousetrap::Customer.update('some customer code', 'some attributes')
+ end
+
+ it "makes a new customer from the attributes" do
+ Mousetrap::Customer.should_receive(:new).with('some attributes').and_return(stub(:null_object => true))
+ do_update
+ end
+
+ it "sets the new customer code to the argument" do
+ customer = mock
+ customer.stub :update
+ Mousetrap::Customer.stub :new => customer
+ customer.should_receive(:code=).with('some customer code')
+ do_update
+ end
+
+ it "calls #update" do
+ customer = mock(:null_object => true)
+ Mousetrap::Customer.stub :new => customer
+ customer.should_receive :update
+ do_update
+ end
+ end
+
describe '#cancel' do
context "for existing records" do
it 'cancels' do

0 comments on commit 4e71052

Please sign in to comment.