spec/mousetrap/customer_spec.rb in hashrocket-mousetrap-0.2.1 vs spec/mousetrap/customer_spec.rb in hashrocket-mousetrap-0.3.0
- old
+ new
@@ -1,8 +1,53 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe Mousetrap::Customer do
+ # customers:
+ # customer:
+ # firstName: nvnawrelyv
+ # lastName: vklidifvfd
+ # email: bvvljaeegs@example.com
+ # code: ablntsorai@example.com
+ # company:
+ # gatewayToken:
+ # id: eac1cf0e-fc5b-102c-a92d-40402145ee8b
+ # createdDatetime: "2009-09-27T02:16:15+00:00"
+ # modifiedDatetime: "2009-09-27T02:16:16+00:00"
+ # subscriptions:
+ # subscription:
+ # gatewayToken:
+ # id: eac26b4e-fc5b-102c-a92d-40402145ee8b
+ # createdDatetime: "2009-09-27T02:16:15+00:00"
+ # ccType: visa
+ # ccLastFour: "1111"
+ # ccExpirationDate: "2012-12-31T00:00:00+00:00"
+ # canceledDatetime:
+ # plans:
+ # plan:
+ # name: Test
+ # setupChargeAmount: "0.00"
+ # code: TEST
+ # recurringChargeAmount: "42.00"
+ # billingFrequencyQuantity: "1"
+ # trialDays: "0"
+ # id: 5fbb9a84-e27f-102c-a92d-40402145ee8b
+ # billingFrequency: monthly
+ # createdDatetime: "2009-08-25T04:24:34+00:00"
+ # recurringChargeCode: TEST_RECURRING
+ # isActive: "1"
+ # billingFrequencyUnit: months
+ # description: Test
+ # billingFrequencyPer: month
+ # setupChargeCode: TEST_SETUP
+ # invoices:
+ # invoice:
+ # number: "2"
+ # billingDatetime: "2009-10-27T02:16:15+00:00"
+ # id: eac74d62-fc5b-102c-a92d-40402145ee8b
+ # createdDatetime: "2009-09-27T02:16:15+00:00"
+ # type: subscription
+
def customer_attributes_for_api(customer)
{
:firstName => customer.first_name,
:lastName => customer.last_name,
:email => customer.email,
@@ -17,10 +62,39 @@
:ccZip => customer.subscription.billing_zip_code,
}
}
end
+ describe '.all' do
+ before do
+ Mousetrap::Customer.stub :build_resources_from
+ end
+
+ it "gets all customers" do
+ Mousetrap::Customer.should_receive(:get_resources).with('customers').and_return('some hash')
+ Mousetrap::Customer.all
+ end
+
+ it "handles kludgy 'no customers found' response" do
+ Mousetrap::Customer.stub :get_resources => { 'error' => "Bad request: No customers found." }
+ Mousetrap::Customer.all.should == []
+ end
+
+ it "raises error if response has one" do
+ expect do
+ Mousetrap::Customer.stub :get_resources => { 'error' => "some other error" }
+ Mousetrap::Customer.all
+ end.to raise_error(RuntimeError, "some other error")
+ end
+
+ it "builds resources from the response" do
+ Mousetrap::Customer.stub :get_resources => 'some hash'
+ Mousetrap::Customer.should_receive(:build_resources_from).with('some hash')
+ Mousetrap::Customer.all
+ end
+ end
+
describe '.create' do
before do
@customer_hash = Factory.attributes_for :new_customer
@customer = Mousetrap::Customer.new @customer_hash
@customer.stub(:save)
@@ -78,23 +152,23 @@
subject.code.should == 'asfkhw0'
end
end
end
- describe '#destroy' do
+ describe '#cancel' do
context "for existing records" do
- it 'destroys' do
+ it 'cancels' do
customer = Factory :existing_customer
- Mousetrap::Customer.should_receive(:delete_resource).with('customers', customer.code)
- customer.destroy
+ customer.should_receive(:member_action).with('cancel')
+ customer.cancel
end
end
context "for new records" do
it "does nothing" do
- customer = Factory :new_customer
- Mousetrap::Customer.should_not_receive(:delete_resource)
- customer.destroy
+ customer = Factory.build :new_customer
+ customer.should_not_receive(:member_action).with('cancel')
+ customer.cancel
end
end
end
describe '#save' do