curdbee 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,23 @@
1
+ module CurdBee
2
+ module Error
3
+
4
+ class Base < StandardError
5
+ attr_reader :response
6
+
7
+ def initialize(response=nil)
8
+ @response = response
9
+ end
10
+ end
11
+
12
+ class AccessDenied < Base; end # 401 errors
13
+ class Forbidden < Base; end # 403 errors
14
+ class BadRequest < Base; end # 422 errors
15
+ class NotFound < Base; end # 404 errors
16
+ class ServerError < Base; end # 500 errors
17
+ class ConnectionFailed < Base; end
18
+
19
+ class UnexpectedResponse < Base; end
20
+
21
+ end
22
+ end
23
+
@@ -0,0 +1,14 @@
1
+ module CurdBee
2
+ class Estimate < Base
3
+ @resource = "estimates"
4
+ @element = "estimate"
5
+
6
+ include CurdBee::Invoiceable
7
+
8
+ def convert
9
+ response = self.class.send_request(:post, "/#{self.class.resource}/#{self[:id]}/convert")
10
+ self.class.new(response["invoice"])
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ module CurdBee
2
+ class Invoice < Base
3
+
4
+ @resource = "invoices"
5
+ @element = "invoice"
6
+
7
+ include CurdBee::Invoiceable
8
+
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ module CurdBee
2
+ module Invoiceable
3
+
4
+ # common methods for invoices and estimates
5
+
6
+ def duplicate
7
+ response = self.class.send_request(:post, "/#{self.class.resource}/#{self[:id]}/duplicate")
8
+ self.class.new(response["#{self.class.element}"])
9
+ end
10
+
11
+ def close
12
+ response = self.class.send_request(:post, "/#{self.class.resource}/#{self[:id]}/close")
13
+ return true if response.code.to_i == 200
14
+ end
15
+
16
+ def reopen
17
+ response = self.class.send_request(:post, "/#{self.class.resource}/#{self[:id]}/reopen")
18
+ return true if response.code.to_i == 200
19
+ end
20
+
21
+ def deliver
22
+ response = self.class.send_request(:post, "/deliver/#{self.class.element}/#{self[:id]}")
23
+ return true if response.code.to_i == 200
24
+ end
25
+
26
+ def permalink
27
+ statement_type = self.class.element == "estimate" ? "est" : "inv"
28
+ unless self.hash_key.nil? || self.hash_key.empty?
29
+ "#{self.class.base_uri}/#{statement_type}/#{self.hash_key}"
30
+ else
31
+ ""
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,6 @@
1
+ module CurdBee
2
+ class Item < Base
3
+ @resource = "items"
4
+ @element = "item"
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ module CurdBee
2
+ class Parser < HTTParty::Parser
3
+
4
+ def parse
5
+ begin
6
+ Crack::JSON.parse(body)
7
+ rescue => e
8
+ raise(CurdBee::Error::UnexpectedResponse.new(e.message), body)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ module CurdBee
2
+ class Payment < Base
3
+
4
+ class << self;
5
+ def invoice_id=(value)
6
+ @invoice_id = value
7
+ self.resource = "invoices/#{@invoice_id}/payments"
8
+ end
9
+
10
+ def invoice_id
11
+ @invoice_id
12
+ end
13
+ end
14
+
15
+ @element = "payment"
16
+
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ module CurdBee
2
+ class RecurringProfile < Base
3
+ @resource = "recurring_profiles"
4
+ @element = "recurring_profile"
5
+ end
6
+ end
@@ -0,0 +1,144 @@
1
+ require 'spec_helper'
2
+
3
+ describe CurdBee::Client 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 clients" do
13
+ stub_get "http://test.curdbee.com/clients.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=1&per_page=20", "clients.json"
14
+ result = CurdBee::Client.list
15
+ result.first.name.should == "Awesome Inc."
16
+ end
17
+
18
+ it "should take limit as an option" do
19
+ stub_get "http://test.curdbee.com/clients.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=1&per_page=1", "clients.json"
20
+ result = CurdBee::Client.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/clients.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=2&per_page=1", "clients.json"
26
+ result = CurdBee::Client.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
+ #@client = CurdBee::Client.new
37
+ end
38
+
39
+ it "should return the matching client" do
40
+ stub_get "http://test.curdbee.com/clients/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "client.json"
41
+ result = CurdBee::Client.show(31)
42
+ result.name.should == "Awesome Inc."
43
+ end
44
+
45
+ it "should raise an error if nothing found" do
46
+ stub_get "http://test.curdbee.com/clients/32.json?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
47
+ lambda{
48
+ CurdBee::Client.show(32)
49
+ }.should raise_error(CurdBee::Error::NotFound)
50
+ end
51
+
52
+ end
53
+
54
+ describe 'create' do
55
+
56
+ before do
57
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
58
+ CurdBee::Config.subdomain = "test"
59
+ end
60
+
61
+ it "should return the created client" do
62
+ stub_post "http://test.curdbee.com/clients?api_token=TYMuwW6rM2PQnoWx1ht4", "new_client.json"
63
+ @client = CurdBee::Client.new(
64
+ :name => "RickRoll Inc.",
65
+ :email => "rickroll@example.com",
66
+ :currency_id => 150
67
+ )
68
+ result = @client.create
69
+ @client.id.should == 34
70
+ end
71
+
72
+ it "should raise an error if creation fails" do
73
+ stub_post "http://test.curdbee.com/clients?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
74
+ lambda{
75
+ @client = CurdBee::Client.new()
76
+ @client.create
77
+ }.should raise_error(CurdBee::Error::BadRequest)
78
+ end
79
+
80
+
81
+ end
82
+
83
+ describe 'update' do
84
+
85
+ before do
86
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
87
+ CurdBee::Config.subdomain = "test"
88
+ stub_get "http://test.curdbee.com/clients/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "client.json"
89
+ @client = CurdBee::Client.show(31)
90
+ end
91
+
92
+ it "should return the updated client" do
93
+ stub_put "http://test.curdbee.com/clients/31?api_token=TYMuwW6rM2PQnoWx1ht4", "new_client.json"
94
+ @client.name = "RickRoll Inc."
95
+ @client.email = "rickroll@example.com"
96
+
97
+ result = @client.update
98
+ result.should be_true
99
+ end
100
+
101
+ it "should raise an error if update fails" do
102
+ stub_put "http://test.curdbee.com/clients/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
103
+ lambda{
104
+ @client.name = ""
105
+ @client.update
106
+ }.should raise_error(CurdBee::Error::BadRequest)
107
+ end
108
+
109
+
110
+ end
111
+
112
+ describe 'delete' do
113
+
114
+ before do
115
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
116
+ CurdBee::Config.subdomain = "test"
117
+ stub_get "http://test.curdbee.com/clients/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "client.json"
118
+ @client = CurdBee::Client.show(31)
119
+ end
120
+
121
+ it "should return true if client was deleted" do
122
+ stub_delete "http://test.curdbee.com/clients/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
123
+ result = @client.delete
124
+ result.should == true
125
+ end
126
+
127
+ it "should raise a bad request error if deletion fails" do
128
+ stub_delete "http://test.curdbee.com/clients/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
129
+ lambda{
130
+ @client.delete
131
+ }.should raise_error(CurdBee::Error::BadRequest)
132
+ end
133
+
134
+ it "should raise a not found error if client doesnt exist" do
135
+ stub_delete "http://test.curdbee.com/clients/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
136
+ lambda{
137
+ @client.delete
138
+ }.should raise_error(CurdBee::Error::NotFound)
139
+ end
140
+
141
+
142
+ end
143
+
144
+ end
@@ -0,0 +1,312 @@
1
+ require 'spec_helper'
2
+
3
+ describe CurdBee::Estimate 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 estimates" do
13
+ stub_get "http://test.curdbee.com/estimates.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=1&per_page=20", "estimates.json"
14
+ result = CurdBee::Estimate.list
15
+ result.first.estimate_no.should == "TEST-1"
16
+ end
17
+
18
+ it "should take limit as an option" do
19
+ stub_get "http://test.curdbee.com/estimates.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=1&per_page=1", "estimates.json"
20
+ result = CurdBee::Estimate.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/estimates.json?api_token=TYMuwW6rM2PQnoWx1ht4&page=2&per_page=1", "estimates.json"
26
+ result = CurdBee::Estimate.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 estimate" do
39
+ stub_get "http://test.curdbee.com/estimates/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "estimate.json"
40
+ result = CurdBee::Estimate.show(31)
41
+ result.estimate_no.should == "TEST-1"
42
+ end
43
+
44
+ it "should raise an error if nothing found" do
45
+ stub_get "http://test.curdbee.com/estimates/32.json?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
46
+ lambda{
47
+ CurdBee::Estimate.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 estimate" do
61
+ stub_post "http://test.curdbee.com/estimates?api_token=TYMuwW6rM2PQnoWx1ht4", "new_estimate.json"
62
+ estimate_info = {:date => Date.today, :estimate_no => "EST-NEW", :client_id => @client.id,
63
+ :line_items_attributes => [{:name_and_description => "Sample Item", :quantity => 1, :price => 25.00, :unit => "hour"}]
64
+ }
65
+ @estimate = CurdBee::Estimate.new(estimate_info)
66
+ result = @estimate.create
67
+ @estimate.id.should == 31
68
+ end
69
+
70
+ it "should raise an error if creation fails" do
71
+ stub_post "http://test.curdbee.com/estimates?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
72
+ lambda{
73
+ @estimate = CurdBee::Estimate.new({})
74
+ @estimate.create
75
+ }.should raise_error(CurdBee::Error::BadRequest)
76
+ end
77
+
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/estimates/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "estimate.json"
87
+ @estimate = CurdBee::Estimate.show(31)
88
+ end
89
+
90
+ it "should return the updated estimate" do
91
+ stub_put "http://test.curdbee.com/estimates/31?api_token=TYMuwW6rM2PQnoWx1ht4", "new_estimate.json"
92
+ @estimate.estimate_no = "EST-NEW"
93
+ @estimate.date = Date.today
94
+
95
+ result = @estimate.update
96
+ result.should be_true
97
+ end
98
+
99
+ it "should raise an error if update fails" do
100
+ stub_put "http://test.curdbee.com/estimates/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
101
+ lambda{
102
+ @estimate.estimate_no = ""
103
+ @estimate.update
104
+ }.should raise_error(CurdBee::Error::BadRequest)
105
+ end
106
+
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/estimates/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "estimate.json"
116
+ @estimate = CurdBee::Estimate.show(31)
117
+ end
118
+
119
+ it "should return true if estimate was deleted" do
120
+ stub_delete "http://test.curdbee.com/estimates/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
121
+ result = @estimate.delete
122
+ result.should be_true
123
+ end
124
+
125
+ it "should raise a bad request error if deletion fails" do
126
+ stub_delete "http://test.curdbee.com/estimates/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
127
+ lambda{
128
+ @estimate.delete
129
+ }.should raise_error(CurdBee::Error::BadRequest)
130
+ end
131
+
132
+ it "should raise a not found error if estimate doesnt exist" do
133
+ stub_delete "http://test.curdbee.com/estimates/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
134
+ lambda{
135
+ @estimate.delete
136
+ }.should raise_error(CurdBee::Error::NotFound)
137
+ end
138
+
139
+
140
+ end
141
+
142
+ describe 'duplicate' do
143
+
144
+ before do
145
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
146
+ CurdBee::Config.subdomain = "test"
147
+ stub_get "http://test.curdbee.com/estimates/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "estimate.json"
148
+ @estimate = CurdBee::Estimate.show(31)
149
+ end
150
+
151
+ it "should return the duplicated estimate if it was duplicated" do
152
+ stub_post "http://test.curdbee.com/estimates/31/duplicate?api_token=TYMuwW6rM2PQnoWx1ht4", "new_estimate.json"
153
+ result = @estimate.duplicate
154
+ result.estimate_no.should == "EST-NEW"
155
+ end
156
+
157
+ it "should raise a bad request error if duplication fails" do
158
+ stub_post "http://test.curdbee.com/estimates/31/duplicate?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
159
+ lambda{
160
+ @estimate.duplicate
161
+ }.should raise_error(CurdBee::Error::BadRequest)
162
+ end
163
+
164
+ it "should raise a not found error if estimate doesnt exist" do
165
+ stub_post "http://test.curdbee.com/estimates/31/duplicate?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
166
+ lambda{
167
+ @estimate.duplicate
168
+ }.should raise_error(CurdBee::Error::NotFound)
169
+ end
170
+ end
171
+
172
+ describe 'close' do
173
+
174
+ before do
175
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
176
+ CurdBee::Config.subdomain = "test"
177
+ stub_get "http://test.curdbee.com/estimates/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "estimate.json"
178
+ @estimate = CurdBee::Estimate.show(31)
179
+ end
180
+
181
+ it "should return true if estimate was closed" do
182
+ stub_post "http://test.curdbee.com/estimates/31/close?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
183
+ result = @estimate.close
184
+ result.should be_true
185
+ end
186
+
187
+ it "should raise a bad request error if closing fails" do
188
+ stub_post "http://test.curdbee.com/estimates/31/close?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
189
+ lambda{
190
+ @estimate.close
191
+ }.should raise_error(CurdBee::Error::BadRequest)
192
+ end
193
+
194
+ it "should raise a not found error if estimate doesnt exist" do
195
+ stub_post "http://test.curdbee.com/estimates/31/close?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
196
+ lambda{
197
+ @estimate.close
198
+ }.should raise_error(CurdBee::Error::NotFound)
199
+ end
200
+ end
201
+
202
+ describe 'reopen' do
203
+
204
+ before do
205
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
206
+ CurdBee::Config.subdomain = "test"
207
+ stub_get "http://test.curdbee.com/estimates/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "estimate.json"
208
+ @estimate = CurdBee::Estimate.show(31)
209
+ end
210
+
211
+ it "should return true if estimate was reopened" do
212
+ stub_post "http://test.curdbee.com/estimates/31/reopen?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
213
+ result = @estimate.reopen
214
+ result.should be_true
215
+ end
216
+
217
+ it "should raise a bad request error if reopening fails" do
218
+ stub_post "http://test.curdbee.com/estimates/31/reopen?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
219
+ lambda{
220
+ @estimate.reopen
221
+ }.should raise_error(CurdBee::Error::BadRequest)
222
+ end
223
+
224
+ it "should raise a not found error if estimate doesnt exist" do
225
+ stub_post "http://test.curdbee.com/estimates/31/reopen?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
226
+ lambda{
227
+ @estimate.reopen
228
+ }.should raise_error(CurdBee::Error::NotFound)
229
+ end
230
+ end
231
+
232
+ describe 'convert' do
233
+
234
+ before do
235
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
236
+ CurdBee::Config.subdomain = "test"
237
+ stub_get "http://test.curdbee.com/estimates/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "estimate.json"
238
+ @estimate = CurdBee::Estimate.show(31)
239
+ end
240
+
241
+ it "should return the invoice if estimate was converted to a invoice" do
242
+ stub_post "http://test.curdbee.com/estimates/31/convert?api_token=TYMuwW6rM2PQnoWx1ht4", "new_invoice.json"
243
+ result = @estimate.convert
244
+ result.invoice_no.should == "IN-NEW"
245
+ end
246
+
247
+ it "should raise a bad request error if reopening fails" do
248
+ stub_post "http://test.curdbee.com/estimates/31/convert?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
249
+ lambda{
250
+ @estimate.convert
251
+ }.should raise_error(CurdBee::Error::BadRequest)
252
+ end
253
+
254
+ it "should raise a not found error if estimate doesnt exist" do
255
+ stub_post "http://test.curdbee.com/estimates/31/convert?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
256
+ lambda{
257
+ @estimate.convert
258
+ }.should raise_error(CurdBee::Error::NotFound)
259
+ end
260
+
261
+ end
262
+
263
+ describe 'deliver' do
264
+
265
+ before do
266
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
267
+ CurdBee::Config.subdomain = "test"
268
+ stub_get "http://test.curdbee.com/estimates/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "estimate.json"
269
+ @estimate = CurdBee::Estimate.show(31)
270
+ end
271
+
272
+ it "should return true if estimate was sent" do
273
+ stub_post "http://test.curdbee.com/deliver/estimate/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 200
274
+ result = @estimate.deliver
275
+ result.should be_true
276
+ end
277
+
278
+ it "should raise a bad request error if sending fails" do
279
+ stub_post "http://test.curdbee.com/deliver/estimate/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 422
280
+ lambda{
281
+ @estimate.deliver
282
+ }.should raise_error(CurdBee::Error::BadRequest)
283
+ end
284
+
285
+ it "should raise a not found error if estimate doesnt exist" do
286
+ stub_post "http://test.curdbee.com/deliver/estimate/31?api_token=TYMuwW6rM2PQnoWx1ht4", "", 404
287
+ lambda{
288
+ @estimate.deliver
289
+ }.should raise_error(CurdBee::Error::NotFound)
290
+ end
291
+ end
292
+
293
+ describe 'permalink' do
294
+
295
+ before do
296
+ CurdBee::Config.api_key = "TYMuwW6rM2PQnoWx1ht4"
297
+ CurdBee::Config.subdomain = "test"
298
+ stub_get "http://test.curdbee.com/estimates/31.json?api_token=TYMuwW6rM2PQnoWx1ht4", "estimate.json"
299
+ @estimate = CurdBee::Estimate.show(31)
300
+ end
301
+
302
+ it "should return the permalink to view a sent invoice" do
303
+ @estimate.permalink.should == "http://test.curdbee.com/est/tx9045ff"
304
+ end
305
+
306
+ it "should return nothing for draft invoices" do
307
+ @new_estimate = CurdBee::Estimate.new()
308
+ @new_estimate.permalink.should == ""
309
+ end
310
+ end
311
+
312
+ end