curdbee 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/Gemfile +16 -0
  2. data/Gemfile.lock +35 -0
  3. data/LICENSE +22 -0
  4. data/README.markdown +43 -0
  5. data/Rakefile +19 -0
  6. data/VERSION +1 -0
  7. data/curdbee.gemspec +103 -0
  8. data/examples/create_invoice_for_new_client.rb +58 -0
  9. data/lib/curdbee.rb +20 -0
  10. data/lib/curdbee/base.rb +75 -0
  11. data/lib/curdbee/client.rb +6 -0
  12. data/lib/curdbee/config.rb +33 -0
  13. data/lib/curdbee/error.rb +23 -0
  14. data/lib/curdbee/estimate.rb +14 -0
  15. data/lib/curdbee/invoice.rb +10 -0
  16. data/lib/curdbee/invoiceable.rb +35 -0
  17. data/lib/curdbee/item.rb +6 -0
  18. data/lib/curdbee/parser.rb +13 -0
  19. data/lib/curdbee/payment.rb +18 -0
  20. data/lib/curdbee/recurring_profile.rb +6 -0
  21. data/spec/client_spec.rb +144 -0
  22. data/spec/estimate_spec.rb +312 -0
  23. data/spec/fixtures/client.json +20 -0
  24. data/spec/fixtures/clients.json +20 -0
  25. data/spec/fixtures/customers.json +12 -0
  26. data/spec/fixtures/estimate.json +24 -0
  27. data/spec/fixtures/estimates.json +26 -0
  28. data/spec/fixtures/invoice.json +24 -0
  29. data/spec/fixtures/invoices.json +26 -0
  30. data/spec/fixtures/item.json +11 -0
  31. data/spec/fixtures/items.json +11 -0
  32. data/spec/fixtures/new_client.json +20 -0
  33. data/spec/fixtures/new_estimate.json +24 -0
  34. data/spec/fixtures/new_invoice.json +24 -0
  35. data/spec/fixtures/new_item.json +11 -0
  36. data/spec/fixtures/new_payment.json +10 -0
  37. data/spec/fixtures/new_recurring_profile.json +26 -0
  38. data/spec/fixtures/payment.json +10 -0
  39. data/spec/fixtures/payments.json +10 -0
  40. data/spec/fixtures/recurring_profile.json +26 -0
  41. data/spec/fixtures/recurring_profiles.json +28 -0
  42. data/spec/invoice_spec.rb +280 -0
  43. data/spec/item_spec.rb +137 -0
  44. data/spec/payment_spec.rb +143 -0
  45. data/spec/recurring_profile_spec.rb +140 -0
  46. data/spec/spec_helper.rb +24 -0
  47. data/spec/support/fakeweb_stubs.rb +33 -0
  48. metadata +156 -0
@@ -0,0 +1,20 @@
1
+ {
2
+ "client": {
3
+ "id":31,
4
+ "name": "Awesome Inc.",
5
+ "email": "awesome@example.com",
6
+ "address": "100 Park St.",
7
+ "city": "Las Vegas",
8
+ "province": "Nevada",
9
+ "zip_code": "8323",
10
+ "country": "United States",
11
+ "phone": "(234) 111-129",
12
+ "fax": "(234) 111-122",
13
+ "custom_field_name": "Tax ID",
14
+ "custom_field_value": "1999",
15
+ "currency": {"name":"Dollar", "symbol":"$"},
16
+ "full_address_with_comma": "100 Park St., Las Vegas, Nevada, 8323, United States",
17
+ "created_at": "2010-08-24T01:47:50Z",
18
+ "updated_at": "2010-08-24T01:47:50Z"
19
+ }
20
+ }
@@ -0,0 +1,20 @@
1
+ [{
2
+ "client": {
3
+ "id":31,
4
+ "name": "Awesome Inc.",
5
+ "email": "awesome@example.com",
6
+ "address": "100 Park St.",
7
+ "city": "Las Vegas",
8
+ "province": "Nevada",
9
+ "zip_code": "8323",
10
+ "country": "United States",
11
+ "phone": "(234) 111-129",
12
+ "fax": "(234) 111-122",
13
+ "custom_field_name": "Tax ID",
14
+ "custom_field_value": "1999",
15
+ "currency": {"name":"Dollar", "symbol":"$"},
16
+ "full_address_with_comma": "100 Park St., Las Vegas, Nevada, 8323, United States",
17
+ "created_at": "2010-08-24T01:47:50Z",
18
+ "updated_at": "2010-08-24T01:47:50Z"
19
+ }
20
+ }]
@@ -0,0 +1,12 @@
1
+ [{
2
+ "client": {
3
+ "reference": "bradleyjoyce",
4
+ "updated_at": "2009-10-07T11:10:27-04:00",
5
+ "id": 16,
6
+ "organization": "Squeejee",
7
+ "first_name": "Bradley",
8
+ "last_name": "Joyce",
9
+ "email": "bradley@squeejee.com",
10
+ "created_at": "2009-10-07T11:10:27-04:00"
11
+ }
12
+ }]
@@ -0,0 +1,24 @@
1
+ "estimate": {
2
+ "id":31,
3
+ "created_at":"2010-09-19T19:01:03Z",
4
+ "total_billed":"$150.00",
5
+ "line_items":[{"price":"25.00","unit":null,"quantity":2.0,"sort_order":null,"id":5739,"total":"50.00","name_and_description":"This is a test item"}],
6
+ "updated_at":"2010-09-19T19:01:03Z",
7
+ "tax2_compound":null,
8
+ "notes":null,
9
+ "sub_total":"$150.00",
10
+ "tax_amount":"$0.00",
11
+ "payment_options":[""],
12
+ "hash_key":"tx9045ff",
13
+ "date":"2010-09-20",
14
+ "client":{"name":"Quigley-West","id":3512},
15
+ "discount_amount":"$0.00",
16
+ "due_date":"2010-09-20",
17
+ "paid_total":"$0.00",
18
+ "summary":null,
19
+ "tax2_amount":"$0.00",
20
+ "total_due":"$150.00",
21
+ "shipping_amount":"$0.00",
22
+ "state":"draft",
23
+ "estimate_no":"TEST-1"
24
+ }
@@ -0,0 +1,26 @@
1
+ [{
2
+ "estimate": {
3
+ "id":31,
4
+ "created_at":"2010-09-19T19:01:03Z",
5
+ "total_billed":"$150.00",
6
+ "line_items":[{"price":"25.00","unit":null,"quantity":2.0,"sort_order":null,"id":5739,"total":"50.00","name_and_description":"This is a test item"}],
7
+ "updated_at":"2010-09-19T19:01:03Z",
8
+ "tax2_compound":null,
9
+ "notes":null,
10
+ "sub_total":"$150.00",
11
+ "tax_amount":"$0.00",
12
+ "payment_options":[""],
13
+ "hash_key":"tx9045ff",
14
+ "date":"2010-09-20",
15
+ "client":{"name":"Quigley-West","id":3512},
16
+ "discount_amount":"$0.00",
17
+ "due_date":"2010-09-20",
18
+ "paid_total":"$0.00",
19
+ "summary":null,
20
+ "tax2_amount":"$0.00",
21
+ "total_due":"$150.00",
22
+ "shipping_amount":"$0.00",
23
+ "state":"draft",
24
+ "estimate_no":"TEST-1"
25
+ }
26
+ }]
@@ -0,0 +1,24 @@
1
+ "invoice": {
2
+ "id":31,
3
+ "created_at":"2010-09-19T19:01:03Z",
4
+ "total_billed":"$150.00",
5
+ "line_items":[{"price":"25.00","unit":null,"quantity":2.0,"sort_order":null,"id":5739,"total":"50.00","name_and_description":"This is a test item"}],
6
+ "updated_at":"2010-09-19T19:01:03Z",
7
+ "tax2_compound":null,
8
+ "notes":null,
9
+ "sub_total":"$150.00",
10
+ "tax_amount":"$0.00",
11
+ "payment_options":[""],
12
+ "hash_key":"tx9045ff",
13
+ "date":"2010-09-20",
14
+ "client":{"name":"Quigley-West","id":3512},
15
+ "discount_amount":"$0.00",
16
+ "due_date":"2010-09-20",
17
+ "paid_total":"$0.00",
18
+ "summary":null,
19
+ "tax2_amount":"$0.00",
20
+ "total_due":"$150.00",
21
+ "shipping_amount":"$0.00",
22
+ "state":"draft",
23
+ "invoice_no":"TEST-1"
24
+ }
@@ -0,0 +1,26 @@
1
+ [{
2
+ "invoice": {
3
+ "id":31,
4
+ "created_at":"2010-09-19T19:01:03Z",
5
+ "total_billed":"$150.00",
6
+ "line_items":[{"price":"25.00","unit":null,"quantity":2.0,"sort_order":null,"id":5739,"total":"50.00","name_and_description":"This is a test item"}],
7
+ "updated_at":"2010-09-19T19:01:03Z",
8
+ "tax2_compound":null,
9
+ "notes":null,
10
+ "sub_total":"$150.00",
11
+ "tax_amount":"$0.00",
12
+ "payment_options":[""],
13
+ "hash_key":"tx9045ff",
14
+ "date":"2010-09-20",
15
+ "client":{"name":"Quigley-West","id":3512},
16
+ "discount_amount":"$0.00",
17
+ "due_date":"2010-09-20",
18
+ "paid_total":"$0.00",
19
+ "summary":null,
20
+ "tax2_amount":"$0.00",
21
+ "total_due":"$150.00",
22
+ "shipping_amount":"$0.00",
23
+ "state":"draft",
24
+ "invoice_no":"TEST-1"
25
+ }
26
+ }]
@@ -0,0 +1,11 @@
1
+ {
2
+ "item": {
3
+ "id":25,
4
+ "name": "My Item",
5
+ "description": "This is a sample item",
6
+ "price": "$150.00",
7
+ "units": "hourly",
8
+ "created_at": "2010-08-24T01:47:50Z",
9
+ "updated_at": "2010-08-24T01:47:50Z"
10
+ }
11
+ }
@@ -0,0 +1,11 @@
1
+ [{
2
+ "item": {
3
+ "id":25,
4
+ "name": "My Item",
5
+ "description": "This is a sample item",
6
+ "price": "$150.00",
7
+ "units": "hourly",
8
+ "created_at": "2010-08-24T01:47:50Z",
9
+ "updated_at": "2010-08-24T01:47:50Z"
10
+ }
11
+ }]
@@ -0,0 +1,20 @@
1
+ {
2
+ "client": {
3
+ "id":34,
4
+ "name": "RickRoll Inc.",
5
+ "email": "rickroll@example.com",
6
+ "address": "100 Park St.",
7
+ "city": "Las Vegas",
8
+ "province": "Nevada",
9
+ "zip_code": "8323",
10
+ "country": "United States",
11
+ "phone": "(234) 111-129",
12
+ "fax": "(234) 111-122",
13
+ "custom_field_name": "Tax ID",
14
+ "custom_field_value": "1999",
15
+ "currency": {"name":"Dollar", "symbol":"$"},
16
+ "full_address_with_comma": "100 Park St., Las Vegas, Nevada, 8323, United States",
17
+ "created_at": "2010-08-24T01:47:50Z",
18
+ "updated_at": "2010-08-24T01:47:50Z"
19
+ }
20
+ }
@@ -0,0 +1,24 @@
1
+ "estimate": {
2
+ "id":31,
3
+ "created_at":"2010-09-19T19:01:03Z",
4
+ "total_billed":"$150.00",
5
+ "line_items":[{"price":"25.00","unit":null,"quantity":2.0,"sort_order":null,"id":5739,"total":"50.00","name_and_description":"This is a test item"}],
6
+ "updated_at":"2010-09-19T19:01:03Z",
7
+ "tax2_compound":null,
8
+ "notes":null,
9
+ "sub_total":"$150.00",
10
+ "tax_amount":"$0.00",
11
+ "payment_options":[""],
12
+ "hash_key":"tx9045ff",
13
+ "date":"2010-09-20",
14
+ "client":{"name":"Quigley-West","id":3512},
15
+ "discount_amount":"$0.00",
16
+ "due_date":"2010-09-20",
17
+ "paid_total":"$0.00",
18
+ "summary":null,
19
+ "tax2_amount":"$0.00",
20
+ "total_due":"$150.00",
21
+ "shipping_amount":"$0.00",
22
+ "state":"draft",
23
+ "estimate_no":"EST-NEW"
24
+ }
@@ -0,0 +1,24 @@
1
+ "invoice": {
2
+ "id":32,
3
+ "created_at":"2010-09-19T19:01:03Z",
4
+ "total_billed":"$25.00",
5
+ "line_items":[{"price":"25.00","unit":null,"quantity":2.0,"sort_order":null,"id":5739,"total":"50.00","name_and_description":"This is a test item"}],
6
+ "updated_at":"2010-09-19T19:01:03Z",
7
+ "tax2_compound":null,
8
+ "notes":null,
9
+ "sub_total":"$25.00",
10
+ "tax_amount":"$0.00",
11
+ "payment_options":[""],
12
+ "hash_key":"",
13
+ "date":"2010-09-20",
14
+ "client":{"name":"Quigley-West","id":3512},
15
+ "discount_amount":"$0.00",
16
+ "due_date":"2010-09-20",
17
+ "paid_total":"$0.00",
18
+ "summary":null,
19
+ "tax2_amount":"$0.00",
20
+ "total_due":"$150.00",
21
+ "shipping_amount":"$0.00",
22
+ "state":"draft",
23
+ "invoice_no":"IN-NEW"
24
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "item": {
3
+ "id":28,
4
+ "name": "My New Item",
5
+ "description": "This is a new item",
6
+ "price": "$350.00",
7
+ "units": "hourly",
8
+ "created_at": "2010-08-26T01:47:50Z",
9
+ "updated_at": "2010-08-26T01:47:50Z"
10
+ }
11
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "payment": {
3
+ "id":25,
4
+ "date": "2010-09-25",
5
+ "amount": "50.00",
6
+ "payment_method": "custom payment",
7
+ "created_at": "2010-08-24T01:47:50Z",
8
+ "updated_at": "2010-08-24T01:47:50Z"
9
+ }
10
+ }
@@ -0,0 +1,26 @@
1
+ "recurring_profile": {
2
+ "id":31,
3
+ "created_at":"2010-09-19T19:01:03Z",
4
+ "total_billed":"$150.00",
5
+ "line_items":[{"price":"25.00","unit":null,"quantity":2.0,"sort_order":null,"id":5739,"total":"50.00","name_and_description":"This is a test item"}],
6
+ "updated_at":"2010-09-19T19:01:03Z",
7
+ "tax2_compound":null,
8
+ "notes":null,
9
+ "sub_total":"$150.00",
10
+ "tax_amount":"$0.00",
11
+ "payment_options":[""],
12
+ "client":{"name":"Quigley-West","id":3512},
13
+ "discount_amount":"$0.00",
14
+ "tax2_amount":"$0.00",
15
+ "total_due":"$150.00",
16
+ "shipping_amount":"$0.00",
17
+ "invoice_no":"TEST-1",
18
+ "start_date":"2010-09-21",
19
+ "save_as_draft":false,
20
+ "next_billing_date":"2010-09-21",
21
+ "payment_due_term":"Custom",
22
+ "profile_name":"RP-New",
23
+ "iteration_no":2,
24
+ "occurences":3,
25
+ "frequency_term":"Daily"
26
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "payment": {
3
+ "id":25,
4
+ "date": "2010-09-25",
5
+ "amount": "50.00",
6
+ "payment_method": "cash",
7
+ "created_at": "2010-08-24T01:47:50Z",
8
+ "updated_at": "2010-08-24T01:47:50Z"
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ [{
2
+ "payment": {
3
+ "id":25,
4
+ "date": "2010-09-25",
5
+ "amount": "50.00",
6
+ "payment_method": "cash",
7
+ "created_at": "2010-08-24T01:47:50Z",
8
+ "updated_at": "2010-08-24T01:47:50Z"
9
+ }
10
+ }]
@@ -0,0 +1,26 @@
1
+ "recurring_profile": {
2
+ "id":31,
3
+ "created_at":"2010-09-19T19:01:03Z",
4
+ "total_billed":"$150.00",
5
+ "line_items":[{"price":"25.00","unit":null,"quantity":2.0,"sort_order":null,"id":5739,"total":"50.00","name_and_description":"This is a test item"}],
6
+ "updated_at":"2010-09-19T19:01:03Z",
7
+ "tax2_compound":null,
8
+ "notes":null,
9
+ "sub_total":"$150.00",
10
+ "tax_amount":"$0.00",
11
+ "payment_options":[""],
12
+ "client":{"name":"Quigley-West","id":3512},
13
+ "discount_amount":"$0.00",
14
+ "tax2_amount":"$0.00",
15
+ "total_due":"$150.00",
16
+ "shipping_amount":"$0.00",
17
+ "invoice_no":"TEST-1",
18
+ "start_date":"2010-09-21",
19
+ "save_as_draft":false,
20
+ "next_billing_date":"2010-09-21",
21
+ "payment_due_term":"Custom",
22
+ "profile_name":"RP-Test",
23
+ "iteration_no":2,
24
+ "occurences":3,
25
+ "frequency_term":"Daily"
26
+ }
@@ -0,0 +1,28 @@
1
+ [{
2
+ "recurring_profile": {
3
+ "id":31,
4
+ "created_at":"2010-09-19T19:01:03Z",
5
+ "total_billed":"$150.00",
6
+ "line_items":[{"price":"25.00","unit":null,"quantity":2.0,"sort_order":null,"id":5739,"total":"50.00","name_and_description":"This is a test item"}],
7
+ "updated_at":"2010-09-19T19:01:03Z",
8
+ "tax2_compound":null,
9
+ "notes":null,
10
+ "sub_total":"$150.00",
11
+ "tax_amount":"$0.00",
12
+ "payment_options":[""],
13
+ "client":{"name":"Quigley-West","id":3512},
14
+ "discount_amount":"$0.00",
15
+ "tax2_amount":"$0.00",
16
+ "total_due":"$150.00",
17
+ "shipping_amount":"$0.00",
18
+ "invoice_no":"TEST-1",
19
+ "start_date":"2010-09-21",
20
+ "save_as_draft":false,
21
+ "next_billing_date":"2010-09-21",
22
+ "payment_due_term":"Custom",
23
+ "profile_name":"RP-Test",
24
+ "iteration_no":2,
25
+ "occurences":3,
26
+ "frequency_term":"Daily"
27
+ }
28
+ }]
@@ -0,0 +1,280 @@
1
+ require 'spec_helper'
2
+
3
+ describe CurdBee::Invoice do
4
+
5
+ describe 'list' do
6
+
7
+ before do
8
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
9
+ CurdBee::Config.subdomain = "test"
10
+ end
11
+
12
+ it "should return a list of invoices" do
13
+ stub_get "http://test.curdbee.com/invoices.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=1&per_page=20", "invoices.json"
14
+ result = CurdBee::Invoice.list
15
+ result.first.invoice_no.should == "TEST-1"
16
+ end
17
+
18
+ it "should take limit as an option" do
19
+ stub_get "http://test.curdbee.com/invoices.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=1&per_page=1", "invoices.json"
20
+ result = CurdBee::Invoice.list(:limit => 1)
21
+ result.length.should == 1
22
+ end
23
+
24
+ it "should take page as an option" do
25
+ stub_get "http://test.curdbee.com/invoices.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=2&per_page=1", "invoices.json"
26
+ result = CurdBee::Invoice.list(:limit => 1, :page => 2)
27
+ result.length.should == 1
28
+ end
29
+ end
30
+
31
+ describe 'show' do
32
+
33
+ before do
34
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
35
+ CurdBee::Config.subdomain = "test"
36
+ end
37
+
38
+ it "should return the matching invoice" do
39
+ stub_get "http://test.curdbee.com/invoices/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "invoice.json"
40
+ result = CurdBee::Invoice.show(31)
41
+ result.invoice_no.should == "TEST-1"
42
+ end
43
+
44
+ it "should raise an error if nothing found" do
45
+ stub_get "http://test.curdbee.com/invoices/32.json?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
46
+ lambda{
47
+ CurdBee::Invoice.show(32)
48
+ }.should raise_error(CurdBee::Error::NotFound)
49
+ end
50
+
51
+ end
52
+
53
+ describe 'create' do
54
+
55
+ before do
56
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
57
+ CurdBee::Config.subdomain = "test"
58
+ end
59
+
60
+ it "should return the created invoice" do
61
+ stub_post "http://test.curdbee.com/invoices?api_token=TYMuwW6rM2PQnoWx1ht4", "new_invoice.json"
62
+ invoice_info = {:date => Date.today, :invoice_no => "IN-NEW", :client_id => @client.id,
63
+ :line_items_attributes => [{:name_and_description => "Sample Item", :quantity => 1, :price => 25.00, :unit => "hour"}]
64
+ }
65
+ puts invoice_info.to_xml(:root => 'invoice')
66
+ @invoice = CurdBee::Invoice.new(invoice_info)
67
+ result = @invoice.create
68
+ @invoice.id.should == 32
69
+ end
70
+
71
+ it "should raise an error if creation fails" do
72
+ stub_post "http://test.curdbee.com/invoices?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
73
+ lambda{
74
+ @invoice = CurdBee::Invoice.new({})
75
+ @invoice.create
76
+ }.should raise_error(CurdBee::Error::BadRequest)
77
+ end
78
+
79
+ end
80
+
81
+ describe 'update' do
82
+
83
+ before do
84
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
85
+ CurdBee::Config.subdomain = "test"
86
+ stub_get "http://test.curdbee.com/invoices/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "invoice.json"
87
+ @invoice = CurdBee::Invoice.show(31)
88
+ end
89
+
90
+ it "should return the updated invoice" do
91
+ stub_put "http://test.curdbee.com/invoices/31?api_token=TYMuwW6rM2PQnoWx1ht4", "new_invoice.json"
92
+
93
+ @invoice.invoice_no = "IN-NEW"
94
+ @invoice.date = Date.today
95
+
96
+ result = @invoice.update
97
+ result.should be_true
98
+ end
99
+
100
+ it "should raise an error if update fails" do
101
+ stub_put "http://test.curdbee.com/invoices/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
102
+ lambda{
103
+ @invoice.invoice_no = ""
104
+ @invoice.update
105
+ }.should raise_error(CurdBee::Error::BadRequest)
106
+ end
107
+
108
+ end
109
+
110
+ describe 'delete' do
111
+
112
+ before do
113
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
114
+ CurdBee::Config.subdomain = "test"
115
+ stub_get "http://test.curdbee.com/invoices/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "invoice.json"
116
+ @invoice = CurdBee::Invoice.show(31)
117
+ end
118
+
119
+ it "should return true if invoice was deleted" do
120
+ stub_delete "http://test.curdbee.com/invoices/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
121
+ result = @invoice.delete
122
+ result.should == true
123
+ end
124
+
125
+ it "should raise a bad request error if deletion fails" do
126
+ stub_delete "http://test.curdbee.com/invoices/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
127
+ lambda{
128
+ @invoice.delete
129
+ }.should raise_error(CurdBee::Error::BadRequest)
130
+ end
131
+
132
+ it "should raise a not found error if invoice doesnt exist" do
133
+ stub_delete "http://test.curdbee.com/invoices/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
134
+ lambda{
135
+ @invoice.delete
136
+ }.should raise_error(CurdBee::Error::NotFound)
137
+ end
138
+
139
+ end
140
+
141
+ describe 'duplicate' do
142
+
143
+ before do
144
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
145
+ CurdBee::Config.subdomain = "test"
146
+ stub_get "http://test.curdbee.com/invoices/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "invoice.json"
147
+ @invoice = CurdBee::Invoice.show(31)
148
+ end
149
+
150
+ it "should return the duplicated invoice if invoice was duplicated" do
151
+ stub_post "http://test.curdbee.com/invoices/31/duplicate?api_token=TYMuwW6rM2PQnoWx1ht4", "new_invoice.json"
152
+ result = @invoice.duplicate
153
+ result.invoice_no.should == "IN-NEW"
154
+ end
155
+
156
+ it "should raise a bad request error if duplication fails" do
157
+ stub_post "http://test.curdbee.com/invoices/31/duplicate?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
158
+ lambda{
159
+ @invoice.duplicate
160
+ }.should raise_error(CurdBee::Error::BadRequest)
161
+ end
162
+
163
+ it "should raise a not found error if invoice doesnt exist" do
164
+ stub_post "http://test.curdbee.com/invoices/31/duplicate?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
165
+ lambda{
166
+ @invoice.duplicate
167
+ }.should raise_error(CurdBee::Error::NotFound)
168
+ end
169
+ end
170
+
171
+ describe 'close' do
172
+
173
+ before do
174
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
175
+ CurdBee::Config.subdomain = "test"
176
+ stub_get "http://test.curdbee.com/invoices/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "invoice.json"
177
+ @invoice = CurdBee::Invoice.show(31)
178
+ end
179
+
180
+ it "should return true if invoice was closed" do
181
+ stub_post "http://test.curdbee.com/invoices/31/close?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
182
+ result = @invoice.close
183
+ result.should == true
184
+ end
185
+
186
+ it "should raise a bad request error if closing fails" do
187
+ stub_post "http://test.curdbee.com/invoices/31/close?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
188
+ lambda{
189
+ @invoice.close
190
+ }.should raise_error(CurdBee::Error::BadRequest)
191
+ end
192
+
193
+ it "should raise a not found error if invoice doesnt exist" do
194
+ stub_post "http://test.curdbee.com/invoices/31/close?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
195
+ lambda{
196
+ @invoice.close
197
+ }.should raise_error(CurdBee::Error::NotFound)
198
+ end
199
+ end
200
+
201
+ describe 'reopen' do
202
+
203
+ before do
204
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
205
+ CurdBee::Config.subdomain = "test"
206
+ stub_get "http://test.curdbee.com/invoices/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "invoice.json"
207
+ @invoice = CurdBee::Invoice.show(31)
208
+ end
209
+
210
+ it "should return true if invoice was reopened" do
211
+ stub_post "http://test.curdbee.com/invoices/31/reopen?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
212
+ result = @invoice.reopen
213
+ result.should == true
214
+ end
215
+
216
+ it "should raise a bad request error if reopening fails" do
217
+ stub_post "http://test.curdbee.com/invoices/31/reopen?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
218
+ lambda{
219
+ @invoice.reopen
220
+ }.should raise_error(CurdBee::Error::BadRequest)
221
+ end
222
+
223
+ it "should raise a not found error if invoice doesnt exist" do
224
+ stub_post "http://test.curdbee.com/invoices/31/reopen?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
225
+ lambda{
226
+ @invoice.reopen
227
+ }.should raise_error(CurdBee::Error::NotFound)
228
+ end
229
+ end
230
+
231
+ describe 'deliver' do
232
+
233
+ before do
234
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
235
+ CurdBee::Config.subdomain = "test"
236
+ stub_get "http://test.curdbee.com/invoices/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "invoice.json"
237
+ @invoice = CurdBee::Invoice.show(31)
238
+ end
239
+
240
+ it "should return true if invoice was delivered" do
241
+ stub_post "http://test.curdbee.com/deliver/invoice/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
242
+ result = @invoice.deliver
243
+ result.should == true
244
+ end
245
+
246
+ it "should raise a bad request error if sending fails" do
247
+ stub_post "http://test.curdbee.com/deliver/invoice/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
248
+ lambda{
249
+ @invoice.deliver
250
+ }.should raise_error(CurdBee::Error::BadRequest)
251
+ end
252
+
253
+ it "should raise a not found error if invoice doesnt exist" do
254
+ stub_post "http://test.curdbee.com/deliver/invoice/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
255
+ lambda{
256
+ @invoice.deliver
257
+ }.should raise_error(CurdBee::Error::NotFound)
258
+ end
259
+ end
260
+
261
+ describe 'permalink' do
262
+
263
+ before do
264
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
265
+ CurdBee::Config.subdomain = "test"
266
+ stub_get "http://test.curdbee.com/invoices/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "invoice.json"
267
+ @invoice = CurdBee::Invoice.show(31)
268
+ end
269
+
270
+ it "should return the permalink to view a sent invoice" do
271
+ @invoice.permalink.should == "http://test.curdbee.com/inv/tx9045ff"
272
+ end
273
+
274
+ it "should return nothing for draft invoices" do
275
+ @new_invoice = CurdBee::Invoice.new()
276
+ @new_invoice.permalink.should == ""
277
+ end
278
+ end
279
+
280
+ end