quickeebooks 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. data/Gemfile.lock +19 -16
  2. data/README.md +29 -23
  3. data/coverage/assets/0.7.1/application.css +1110 -0
  4. data/coverage/assets/0.7.1/application.js +626 -0
  5. data/coverage/assets/0.7.1/fancybox/blank.gif +0 -0
  6. data/coverage/assets/0.7.1/fancybox/fancy_close.png +0 -0
  7. data/coverage/assets/0.7.1/fancybox/fancy_loading.png +0 -0
  8. data/coverage/assets/0.7.1/fancybox/fancy_nav_left.png +0 -0
  9. data/coverage/assets/0.7.1/fancybox/fancy_nav_right.png +0 -0
  10. data/coverage/assets/0.7.1/fancybox/fancy_shadow_e.png +0 -0
  11. data/coverage/assets/0.7.1/fancybox/fancy_shadow_n.png +0 -0
  12. data/coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png +0 -0
  13. data/coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png +0 -0
  14. data/coverage/assets/0.7.1/fancybox/fancy_shadow_s.png +0 -0
  15. data/coverage/assets/0.7.1/fancybox/fancy_shadow_se.png +0 -0
  16. data/coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png +0 -0
  17. data/coverage/assets/0.7.1/fancybox/fancy_shadow_w.png +0 -0
  18. data/coverage/assets/0.7.1/fancybox/fancy_title_left.png +0 -0
  19. data/coverage/assets/0.7.1/fancybox/fancy_title_main.png +0 -0
  20. data/coverage/assets/0.7.1/fancybox/fancy_title_over.png +0 -0
  21. data/coverage/assets/0.7.1/fancybox/fancy_title_right.png +0 -0
  22. data/coverage/assets/0.7.1/fancybox/fancybox-x.png +0 -0
  23. data/coverage/assets/0.7.1/fancybox/fancybox-y.png +0 -0
  24. data/coverage/assets/0.7.1/fancybox/fancybox.png +0 -0
  25. data/coverage/assets/0.7.1/favicon_green.png +0 -0
  26. data/coverage/assets/0.7.1/favicon_red.png +0 -0
  27. data/coverage/assets/0.7.1/favicon_yellow.png +0 -0
  28. data/coverage/assets/0.7.1/loading.gif +0 -0
  29. data/coverage/assets/0.7.1/magnify.png +0 -0
  30. data/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  31. data/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  32. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  33. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  34. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  35. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  36. data/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  37. data/coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  38. data/coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png +0 -0
  39. data/coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  40. data/coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png +0 -0
  41. data/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png +0 -0
  42. data/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  43. data/coverage/index.html +29154 -0
  44. data/lib/quickeebooks/common/online_line_item_model_methods.rb +43 -0
  45. data/lib/quickeebooks/common/service_crud.rb +56 -0
  46. data/lib/quickeebooks/online/model/bill.rb +26 -0
  47. data/lib/quickeebooks/online/model/bill_header.rb +21 -0
  48. data/lib/quickeebooks/online/model/bill_line_item.rb +22 -0
  49. data/lib/quickeebooks/online/model/bill_reimbursable.rb +11 -0
  50. data/lib/quickeebooks/online/model/invoice.rb +2 -31
  51. data/lib/quickeebooks/online/model/payment.rb +5 -33
  52. data/lib/quickeebooks/online/service/bill.rb +17 -0
  53. data/lib/quickeebooks/online/service/customer.rb +3 -47
  54. data/lib/quickeebooks/online/service/invoice.rb +1 -1
  55. data/lib/quickeebooks/online/service/payment.rb +3 -46
  56. data/lib/quickeebooks/online/service/service_base.rb +3 -2
  57. data/lib/quickeebooks/online/service/sort.rb +1 -12
  58. data/lib/quickeebooks/shared/service/filter.rb +19 -2
  59. data/lib/quickeebooks/shared/service/sort.rb +22 -0
  60. data/lib/quickeebooks/version.rb +1 -1
  61. data/lib/quickeebooks/windows/service/clazz.rb +1 -5
  62. data/lib/quickeebooks/windows/service/customer.rb +9 -13
  63. data/lib/quickeebooks/windows/service/item.rb +2 -5
  64. data/lib/quickeebooks/windows/service/service_base.rb +30 -15
  65. data/lib/quickeebooks/windows/service/sort.rb +8 -0
  66. data/lib/quickeebooks.rb +11 -5
  67. data/quickeebooks.gemspec +2 -2
  68. data/spec/quickeebooks/common/online_line_item_model_methods_spec.rb +41 -0
  69. data/spec/quickeebooks/common/service_crud_spec.rb +41 -0
  70. data/spec/quickeebooks/online/account_spec.rb +4 -8
  71. data/spec/quickeebooks/online/bill_spec.rb +17 -0
  72. data/spec/quickeebooks/online/company_meta_data_spec.rb +6 -9
  73. data/spec/quickeebooks/online/customer_spec.rb +10 -14
  74. data/spec/quickeebooks/online/invoice_spec.rb +3 -7
  75. data/spec/quickeebooks/online/payment_spec.rb +6 -10
  76. data/spec/quickeebooks/online/services/account_spec.rb +8 -13
  77. data/spec/quickeebooks/online/services/bill_spec.rb +61 -0
  78. data/spec/quickeebooks/online/services/company_meta_data_spec.rb +2 -7
  79. data/spec/quickeebooks/online/services/customer_spec.rb +15 -20
  80. data/spec/quickeebooks/online/services/filter_spec.rb +0 -5
  81. data/spec/quickeebooks/online/services/invoice_spec.rb +5 -10
  82. data/spec/quickeebooks/online/services/payment_spec.rb +63 -0
  83. data/spec/quickeebooks/online/services/service_base_spec.rb +62 -9
  84. data/spec/quickeebooks/shared/access_token_spec.rb +6 -11
  85. data/spec/quickeebooks/shared/filter_spec.rb +159 -0
  86. data/spec/quickeebooks/shared/sort_spec.rb +17 -0
  87. data/spec/quickeebooks/windows/customer_spec.rb +11 -15
  88. data/spec/quickeebooks/windows/services/class_spec.rb +2 -7
  89. data/spec/quickeebooks/windows/services/company_meta_data_spec.rb +2 -7
  90. data/spec/quickeebooks/windows/services/customer_spec.rb +16 -21
  91. data/spec/quickeebooks/windows/services/invoice_spec.rb +13 -19
  92. data/spec/quickeebooks/windows/services/payment_spec.rb +6 -12
  93. data/spec/quickeebooks/windows/services/sales_rep_spec.rb +6 -11
  94. data/spec/quickeebooks/windows/services/sales_taxes_spec.rb +5 -10
  95. data/spec/quickeebooks/windows/services/service_base_spec.rb +95 -0
  96. data/spec/quickeebooks/windows/services/ship_method_spec.rb +4 -9
  97. data/spec/quickeebooks_spec.rb +0 -3
  98. data/spec/spec_helper.rb +30 -1
  99. data/spec/support/oauth.rb +20 -0
  100. data/spec/xml/online/bill.xml +32 -0
  101. data/spec/xml/online/bill2.xml +32 -0
  102. data/spec/xml/online/bills.xml +33 -0
  103. data/spec/xml/online/payment.xml +1 -1
  104. data/spec/xml/online/payment2.xml +24 -0
  105. data/spec/xml/online/payments.xml +30 -0
  106. metadata +103 -40
  107. data/spec/quickeebooks/online/services/sort_spec.rb +0 -17
@@ -26,7 +26,7 @@ module Quickeebooks
26
26
 
27
27
  def initialize(oauth_access_token = nil, realm_id = nil)
28
28
  @base_uri = 'https://services.intuit.com/sb'
29
-
29
+
30
30
  if !oauth_access_token.nil? && !realm_id.nil?
31
31
  msg = "Quickeebooks::Windows::ServiceBase - "
32
32
  msg += "This version of the constructor is deprecated. "
@@ -36,11 +36,11 @@ module Quickeebooks
36
36
  realm_id = realm_id
37
37
  end
38
38
  end
39
-
39
+
40
40
  def access_token=(token)
41
41
  @oauth = token
42
42
  end
43
-
43
+
44
44
  def realm_id=(realm_id)
45
45
  @realm_id = realm_id
46
46
  end
@@ -52,7 +52,7 @@ module Quickeebooks
52
52
  def url_for_base(raw)
53
53
  "#{@base_uri}/#{raw}/v2/#{@realm_id}"
54
54
  end
55
-
55
+
56
56
  def guid
57
57
  UUIDTools::UUID.random_create.to_s.gsub('-', '')
58
58
  end
@@ -60,7 +60,7 @@ module Quickeebooks
60
60
  private
61
61
 
62
62
  def parse_xml(xml)
63
- @last_response_xml =
63
+ @last_response_xml =
64
64
  begin
65
65
  x = Nokogiri::XML(xml)
66
66
  #x.document.remove_namespaces!
@@ -71,7 +71,7 @@ module Quickeebooks
71
71
  def valid_xml_document(xml)
72
72
  %Q{<?xml version="1.0" encoding="utf-8"?>\n#{xml.strip}}
73
73
  end
74
-
74
+
75
75
  # In QBD a single object response is the same as a collection response except
76
76
  # it just has a single main element
77
77
  def fetch_object(model, url, params = {}, options = {})
@@ -88,14 +88,29 @@ module Quickeebooks
88
88
  def fetch_collection(model, custom_field_query = nil, filters = [], page = 1, per_page = 20, sort = nil, options ={})
89
89
  raise ArgumentError, "missing model to instantiate" if model.nil?
90
90
 
91
- if custom_field_query != nil
92
- response = do_http_post(url_for_resource(model::REST_RESOURCE), custom_field_query, {}, {'Content-Type' => 'text/xml'})
93
- else
94
- response = do_http_get(url_for_resource(model::REST_RESOURCE), {}, {'Content-Type' => 'text/html'})
91
+ post_body_tags = []
92
+
93
+ if filters.is_a?(Array) && filters.length > 0
94
+ post_body_tags << filters.collect { |f| f.to_xml }
95
+ post_body_tags.flatten!
96
+ end
97
+
98
+ post_body_tags << "<StartPage>#{page}</StartPage>"
99
+ post_body_tags << "<ChunkSize>#{per_page}</ChunkSize>"
100
+
101
+ if sort
102
+ post_body_tags << sort.to_xml
95
103
  end
104
+
105
+ post_body_tags << custom_field_query
106
+
107
+ xml_query_tag = "#{model::XML_NODE}Query"
108
+ body = %Q{<?xml version="1.0" encoding="utf-8"?>\n<#{xml_query_tag} xmlns="http://www.intuit.com/sb/cdm/v2">#{post_body_tags.join}</#{xml_query_tag}>}
109
+
110
+ response = do_http_post(url_for_resource(model::REST_RESOURCE), body, {}, {'Content-Type' => 'text/xml'})
96
111
  parse_collection(response, model)
97
112
  end
98
-
113
+
99
114
  def parse_collection(response, model)
100
115
  if response
101
116
  collection = Quickeebooks::Collection.new
@@ -121,14 +136,14 @@ module Quickeebooks
121
136
  nil
122
137
  end
123
138
  end
124
-
139
+
125
140
  def perform_write(model, body = "", params = {}, headers = {})
126
141
  url = url_for_resource(model::REST_RESOURCE)
127
142
  unless headers.has_key?('Content-Type')
128
143
  headers['Content-Type'] = 'text/xml'
129
144
  end
130
145
  response = do_http_post(url, body.strip, params, headers)
131
-
146
+
132
147
  result = nil
133
148
  if response
134
149
  case response.code.to_i
@@ -195,7 +210,7 @@ module Quickeebooks
195
210
  raise "HTTP Error Code: #{status}, Msg: #{response.body}"
196
211
  end
197
212
  end
198
-
213
+
199
214
  def parse_and_raise_exceptione
200
215
  err = parse_intuit_error
201
216
  ex = IntuitRequestException.new(err[:message])
@@ -203,7 +218,7 @@ module Quickeebooks
203
218
  ex.cause = err[:cause]
204
219
  raise ex
205
220
  end
206
-
221
+
207
222
  def response_is_error?
208
223
  @last_response_xml.xpath("//xmlns:RestResponse/xmlns:Error").first != nil
209
224
  end
@@ -0,0 +1,8 @@
1
+ module Quickeebooks
2
+ module Windows
3
+ module Service
4
+ class Sort < Quickeebooks::Shared::Service::Sort
5
+ end
6
+ end
7
+ end
8
+ end
data/lib/quickeebooks.rb CHANGED
@@ -7,19 +7,19 @@ class InvalidModelException < Exception; end
7
7
 
8
8
  module Quickeebooks
9
9
  @@logger = nil
10
-
10
+
11
11
  def self.logger
12
12
  @@logger || Logger.new($stdout) # TODO: replace with a real log file
13
13
  end
14
-
14
+
15
15
  def self.logger=(logger)
16
16
  @@logger = logger
17
17
  end
18
-
18
+
19
19
  class Collection
20
20
  attr_accessor :entries, :count, :current_page
21
21
  end
22
-
22
+
23
23
  end
24
24
 
25
25
  # monkey-path the to_xml method to add support for passing
@@ -36,7 +36,7 @@ module ROXML
36
36
  refs = (self.roxml_references.present? \
37
37
  ? self.roxml_references \
38
38
  : self.class.roxml_attrs.map {|attr| attr.to_ref(self) })
39
-
39
+
40
40
  if params[:fields].length > 0
41
41
  refs.reject! { |r| !params[:fields].include?(r.name) }
42
42
  end
@@ -56,6 +56,7 @@ end
56
56
  # Services
57
57
  require 'quickeebooks/shared/service/filter'
58
58
  require 'quickeebooks/shared/service/access_token'
59
+ require 'quickeebooks/shared/service/sort'
59
60
 
60
61
  #== Online
61
62
 
@@ -64,6 +65,9 @@ require 'quickeebooks/online/model/intuit_type'
64
65
  require 'quickeebooks/online/model/company_meta_data'
65
66
  require 'quickeebooks/online/model/customer'
66
67
  require 'quickeebooks/online/model/account'
68
+ require 'quickeebooks/online/model/bill'
69
+ require 'quickeebooks/online/model/bill_header'
70
+ require 'quickeebooks/online/model/bill_line_item'
67
71
  require 'quickeebooks/online/model/invoice'
68
72
  require 'quickeebooks/online/model/invoice_header'
69
73
  require 'quickeebooks/online/model/invoice_line_item'
@@ -87,6 +91,7 @@ require 'quickeebooks/online/service/sort'
87
91
  require 'quickeebooks/online/service/company_meta_data'
88
92
  require 'quickeebooks/online/service/customer'
89
93
  require 'quickeebooks/online/service/account'
94
+ require 'quickeebooks/online/service/bill'
90
95
  require 'quickeebooks/online/service/invoice'
91
96
  require 'quickeebooks/online/service/item'
92
97
  require 'quickeebooks/online/service/entitlement'
@@ -134,6 +139,7 @@ require 'quickeebooks/windows/model/sales_receipt'
134
139
 
135
140
  # Services
136
141
  require 'quickeebooks/windows/service/filter'
142
+ require 'quickeebooks/windows/service/sort'
137
143
  require 'quickeebooks/windows/service/service_base'
138
144
  require 'quickeebooks/windows/service/account'
139
145
  require 'quickeebooks/windows/service/customer'
data/quickeebooks.gemspec CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |gem|
19
19
  gem.add_dependency 'nokogiri'
20
20
  gem.add_dependency 'activemodel'
21
21
  gem.add_dependency 'uuidtools'
22
-
22
+
23
23
  gem.add_development_dependency 'rake'
24
- gem.add_development_dependency 'rcov', '~> 0.9.8'
24
+ gem.add_development_dependency 'simplecov'
25
25
  gem.add_development_dependency 'rr', '~> 1.0.2'
26
26
  gem.add_development_dependency 'rspec', '2.11.0'
27
27
  gem.add_development_dependency 'fakeweb'
@@ -0,0 +1,41 @@
1
+ describe 'Mixin for online models that have line items' do
2
+
3
+ let (:shared_models) { %w(Invoice Payment Bill) }
4
+
5
+ it 'initializes' do
6
+ shared_models.each do |model|
7
+ klass = "Quickeebooks::Online::Model::#{model}".constantize
8
+ klass.new.line_items.size == 0
9
+ xml = onlineFixture("#{model.downcase}.xml")
10
+ klass.from_xml(xml).line_items.size.should == 1
11
+ end
12
+ end
13
+
14
+ it 'references constants' do
15
+ shared_models.each do |model|
16
+ klass = "Quickeebooks::Online::Model::#{model}".constantize
17
+ klass.resource_for_collection.should == "#{model.downcase}s"
18
+ klass.new.to_xml_ns.should == "<#{model}/>"
19
+ end
20
+ end
21
+
22
+ it 'valid for updates' do
23
+ shared_models.each do |model|
24
+ klass = "Quickeebooks::Online::Model::#{model}".constantize.new
25
+ klass.valid_for_update?.should be_true
26
+ klass.errors.add(:id, 'no user')
27
+ klass.valid_for_update?.should be_false
28
+ end
29
+ end
30
+
31
+ it 'valid for deletion' do
32
+ shared_models.each do |model|
33
+ klass = "Quickeebooks::Online::Model::#{model}".constantize
34
+ xml = onlineFixture("#{model.downcase}.xml")
35
+ item = klass.from_xml(xml)
36
+ item.valid_for_deletion?.should be_true
37
+ end
38
+ end
39
+
40
+ end
41
+
@@ -0,0 +1,41 @@
1
+ describe 'Mixin CRUD like methods for various service modules' do
2
+
3
+ context 'model method' do
4
+ it 'should constantize properly for an online service' do
5
+ service = Quickeebooks::Online::Service::Bill.new
6
+ service.model.should be_a(Class)
7
+ service.model.to_s.should == "Quickeebooks::Online::Model::Bill"
8
+ end
9
+
10
+ it 'should constantize properly for a windows service' do
11
+ expect {
12
+ # Test build_dummy first
13
+ build_dummy_windows_service
14
+ Quickeebooks::Windows::Service::TEST.new.model
15
+ }.to raise_exception NoMethodError
16
+
17
+ build_dummy_windows_service('include ServiceCRUD')
18
+ service = Quickeebooks::Windows::Service::TEST.new
19
+ service.model.should be_a(Class)
20
+ service.model.to_s.should == "Quickeebooks::Windows::Model::TEST"
21
+ end
22
+
23
+ def build_dummy_windows_service(inc = '')
24
+ eval("
25
+ module Quickeebooks
26
+ module Windows
27
+ module Service
28
+ class TEST < Quickeebooks::Windows::Service::ServiceBase
29
+ #{inc}
30
+ end
31
+ end
32
+ module Model
33
+ class TEST < Quickeebooks::Windows::Model::IntuitType
34
+ end
35
+ end
36
+ end
37
+ end
38
+ ", TOPLEVEL_BINDING)
39
+ end
40
+ end
41
+ end
@@ -1,9 +1,5 @@
1
- require "spec_helper"
2
- require "stringio"
3
- require "quickeebooks/online/model/account"
4
-
5
1
  describe "Quickeebooks::Online::Model::Account" do
6
-
2
+
7
3
  it "should convert Ruby to XML" do
8
4
  account = Quickeebooks::Online::Model::Account.new
9
5
  account.sync_token = 1
@@ -14,7 +10,7 @@ describe "Quickeebooks::Online::Model::Account" do
14
10
  xml = account.to_xml(:fields => 'Name').write_to(s, :indent => 0, :indent_text => '')
15
11
  xml.string.gsub(/\n/, '').should == expected
16
12
  end
17
-
13
+
18
14
  it "has a validation error on invalid subtype" do
19
15
  account = Quickeebooks::Online::Model::Account.new
20
16
  account.sub_type = "invalid"
@@ -32,10 +28,10 @@ describe "Quickeebooks::Online::Model::Account" do
32
28
  account.sub_type = "AccountsPayable"
33
29
  account.valid?.should == true
34
30
  end
35
-
31
+
36
32
  it "cannot delete an Account without providing required fields" do
37
33
  account = Quickeebooks::Online::Model::Account.new
38
34
  account.valid_for_deletion?.should == false
39
35
  end
40
-
36
+
41
37
  end
@@ -0,0 +1,17 @@
1
+ describe "Quickeebooks::Online::Model::Bill" do
2
+
3
+ describe "parse bill from XML" do
4
+ xml = onlineFixture("bill.xml")
5
+ bill = Quickeebooks::Online::Model::Bill.from_xml(xml)
6
+ bill.header.doc_number.should == "2004"
7
+ bill.header.vendor_id.value.should == "7"
8
+ bill.header.sales_term_id.value.should == "5"
9
+ bill.header.total_amount.should == 50
10
+
11
+ bill.line_items.count.should == 1
12
+ bill.line_items.first.amount.should == 25
13
+ bill.line_items.first.billable_status.should == "NotBillable"
14
+ bill.line_items.first.reimbursable.customer_id.value.should == "5"
15
+ end
16
+
17
+ end
@@ -1,10 +1,7 @@
1
- require "spec_helper"
2
- require "quickeebooks/online/model/company_meta_data"
3
-
4
1
  describe "Quickeebooks::Online::Model::CompanyMetaData" do
5
-
2
+
6
3
  it "parse company meta data from XML" do
7
- xml = File.read(File.dirname(__FILE__) + "/../../xml/online/company_meta_data.xml")
4
+ xml = onlineFixture("company_meta_data.xml")
8
5
  company_meta_data = Quickeebooks::Online::Model::CompanyMetaData.from_xml(xml)
9
6
 
10
7
  company_meta_data.external_realm_id.should be_nil
@@ -14,16 +11,16 @@ describe "Quickeebooks::Online::Model::CompanyMetaData" do
14
11
  company_meta_data.industry_type.should == "Landscaping Services"
15
12
 
16
13
  company_meta_data.addresses.count.should == 2
17
-
14
+
18
15
  company_meta_data.addresses.first.line1.should == "2600 Service Street"
19
16
 
20
17
  company_meta_data.legal_address.line1.should == "2602 Service Street"
21
-
18
+
22
19
  company_meta_data.phone.free_form_number.should == "(669)111-2222"
23
-
20
+
24
21
  company_meta_data.emails.size.should == 2
25
22
  company_meta_data.emails.first.address.should == "john@bayarealandscapeservices.com"
26
-
23
+
27
24
  # Tag not supported yet in Quickeebooks::Online::Model::Email
28
25
  # company_meta_data.emails.first.tag.should == "COMPANY_EMAIL"
29
26
  end
@@ -1,26 +1,22 @@
1
- require "spec_helper"
2
-
3
- require "quickeebooks/online/model/customer"
4
-
5
1
  describe "Quickeebooks::Online::Model::Customer" do
6
-
2
+
7
3
  it "parse customer from XML" do
8
- xml = File.read(File.dirname(__FILE__) + "/../../xml/online/customer.xml")
4
+ xml = onlineFixture("customer.xml")
9
5
  customer = Quickeebooks::Online::Model::Customer.from_xml(xml)
10
6
  customer.sync_token.should == 1
11
7
  customer.name.should == "John Doe"
12
-
8
+
13
9
  create_time = Date.civil(2011, 9, 29)
14
10
  customer.meta_data.create_time.year.should == create_time.year
15
11
  customer.addresses.count.should == 2
16
-
12
+
17
13
  customer.addresses.first.line1.should == "123 Main St."
18
-
14
+
19
15
  customer.phones.size.should == 2
20
16
  customer.phones.first.free_form_number.should == "(408) 555-1212"
21
-
17
+
22
18
  customer.email.address.should == "johndoe@gmail.com"
23
-
19
+
24
20
  customer.notes.count.should == 1
25
21
  customer.notes.first.content.should == "Likes chocolate and horses"
26
22
 
@@ -28,7 +24,7 @@ describe "Quickeebooks::Online::Model::Customer" do
28
24
 
29
25
  customer.open_balance.amount.should == 6200.0
30
26
  end
31
-
27
+
32
28
  it "can assign an email address" do
33
29
  customer = Quickeebooks::Online::Model::Customer.new
34
30
  the_email = "foo@example.org"
@@ -36,11 +32,11 @@ describe "Quickeebooks::Online::Model::Customer" do
36
32
  customer.email.is_a?(Quickeebooks::Online::Model::Email).should == true
37
33
  customer.email.address.should == the_email
38
34
  end
39
-
35
+
40
36
  it "cannot update an invalid model" do
41
37
  customer = Quickeebooks::Online::Model::Customer.new
42
38
  customer.valid_for_update?.should == false
43
39
  customer.errors.keys.include?(:sync_token).should == true
44
40
  end
45
-
41
+
46
42
  end
@@ -1,16 +1,12 @@
1
- require "spec_helper"
2
-
3
- require "quickeebooks/online/model/invoice"
4
-
5
1
  describe "Quickeebooks::Online::Model::Invoice" do
6
-
2
+
7
3
  describe "parse invoice from XML" do
8
- xml = File.read(File.dirname(__FILE__) + "/../../xml/online/invoice.xml")
4
+ xml = onlineFixture("invoice.xml")
9
5
  invoice = Quickeebooks::Online::Model::Invoice.from_xml(xml)
10
6
  invoice.header.balance.should == 0
11
7
  invoice.id.value.should == "13"
12
8
  invoice.line_items.count.should == 1
13
9
  invoice.line_items.first.unit_price.should == 225
14
10
  end
15
-
11
+
16
12
  end
@@ -1,23 +1,19 @@
1
- require "spec_helper"
2
-
3
- require "quickeebooks/online/model/payment"
4
-
5
1
  describe "Quickeebooks::Online::Model::Payment" do
6
-
2
+
7
3
  describe "parse invoice from XML" do
8
- xml = File.read(File.dirname(__FILE__) + "/../../xml/online/payment.xml")
4
+ xml = onlineFixture("payment.xml")
9
5
  invoice = Quickeebooks::Online::Model::Payment.from_xml(xml)
10
6
  invoice.id.value.should == "47"
11
7
  invoice.header.doc_number.should == "54"
12
8
  invoice.header.customer_id.value.should == "5"
13
9
  invoice.header.note.should == "Payment against Invoice"
14
10
  invoice.header.total_amount.should == 20.0
15
-
11
+
16
12
  invoice.line_items.count.should == 1
17
13
  invoice.line_items.first.amount.should == 20.0
18
14
  invoice.line_items.first.txn_id.value.should == "8"
19
-
15
+
20
16
  invoice.line_items.first.amount.should == invoice.header.total_amount
21
17
  end
22
-
23
- end
18
+
19
+ end
@@ -1,8 +1,3 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
- require "fakeweb"
3
- require "oauth"
4
- require "quickeebooks/online/service/account"
5
-
6
1
  describe "Quickeebooks::Online::Service::Account" do
7
2
  before(:all) do
8
3
  FakeWeb.allow_net_connect = false
@@ -24,14 +19,14 @@ describe "Quickeebooks::Online::Service::Account" do
24
19
  @realm_id = "9991111222"
25
20
  }
26
21
  end
27
-
22
+
28
23
  it "receives 404 from invalid base URL" do
29
24
  uri = "https://qbo.intuit.com/invalid"
30
25
  url = @service.url_for_resource(Quickeebooks::Online::Model::Account.resource_for_collection)
31
26
  FakeWeb.register_uri(:post, url, :status => ["200", "OK"], :body => "blah")
32
27
  lambda { @service.list }.should raise_error(IntuitRequestException)
33
28
  end
34
-
29
+
35
30
  it "can fetch a list of accounts" do
36
31
  xml = File.read(File.dirname(__FILE__) + "/../../../xml/online/accounts.xml")
37
32
  url = @service.url_for_resource(Quickeebooks::Online::Model::Account.resource_for_collection)
@@ -41,7 +36,7 @@ describe "Quickeebooks::Online::Service::Account" do
41
36
  accounts.entries.count.should == 10
42
37
  accounts.entries.first.current_balance.should == 6200
43
38
  end
44
-
39
+
45
40
  it "can create an account" do
46
41
  xml = File.read(File.dirname(__FILE__) + "/../../../xml/online/account.xml")
47
42
  url = @service.url_for_resource(Quickeebooks::Online::Model::Account.resource_for_singular)
@@ -64,24 +59,24 @@ describe "Quickeebooks::Online::Service::Account" do
64
59
  result = @service.delete(account)
65
60
  result.should == true
66
61
  end
67
-
62
+
68
63
  it "cannot delete an account with missing required fields for deletion" do
69
64
  account = Quickeebooks::Online::Model::Account.new
70
65
  lambda { @service.delete(account) }.should raise_error(InvalidModelException, "Missing required parameters for delete")
71
66
  end
72
-
67
+
73
68
  it "exception is raised when we try to create an invalid account" do
74
69
  account = Quickeebooks::Online::Model::Account.new
75
70
  lambda { @service.create(account) }.should raise_error(InvalidModelException)
76
71
  end
77
-
72
+
78
73
  it "can fetch an account by id" do
79
- xml = File.read(File.dirname(__FILE__) + "/../../../xml/online/account.xml")
74
+ xml = onlineFixture("account.xml")
80
75
  url = @service.url_for_resource(Quickeebooks::Online::Model::Account.resource_for_singular)
81
76
  url = "#{url}/99"
82
77
  FakeWeb.register_uri(:get, url, :status => ["200", "OK"], :body => xml)
83
78
  account = @service.fetch_by_id(99)
84
79
  account.name.should == "Billy Bob"
85
80
  end
86
-
81
+
87
82
  end
@@ -0,0 +1,61 @@
1
+ describe "Quickeebooks::Online::Service::Bill" do
2
+ before(:all) do
3
+ construct_oauth_service :bill
4
+ end
5
+
6
+ it "can fetch a list of bills" do
7
+ xml = onlineFixture("bills.xml")
8
+ url = @service.url_for_resource(Quickeebooks::Online::Model::Bill.resource_for_collection)
9
+ FakeWeb.register_uri(:post, url, :status => ["200", "OK"], :body => xml)
10
+ bills = @service.list
11
+ bills.current_page.should == 1
12
+ bills.entries.count.should == 1
13
+ bills.entries.first.header.balance.should == 25.00
14
+ end
15
+
16
+ it "can create a bill" do
17
+ xml = onlineFixture("bill.xml")
18
+ url = @service.url_for_resource(Quickeebooks::Online::Model::Bill.resource_for_singular)
19
+ FakeWeb.register_uri(:post, url, :status => ["200", "OK"], :body => xml)
20
+ bill = Quickeebooks::Online::Model::Bill.new
21
+ bill.header = Quickeebooks::Online::Model::BillHeader.new
22
+ bill.header.total_amount = 25.00
23
+ result = @service.create(bill)
24
+ result.id.value.to_i.should > 0
25
+ end
26
+
27
+ it "can delete a bill" do
28
+ url = "#{@service.url_for_resource(Quickeebooks::Online::Model::Bill.resource_for_singular)}/56"
29
+ FakeWeb.register_uri(:post, url, :status => ["200", "OK"])
30
+ bill = Quickeebooks::Online::Model::Bill.new
31
+ bill.id = Quickeebooks::Online::Model::Id.new("56")
32
+ bill.sync_token = 0
33
+ result = @service.delete(bill)
34
+ result.should == true
35
+ end
36
+
37
+ it "can fetch a bill by id" do
38
+ xml = onlineFixture("bill.xml")
39
+ url = "#{@service.url_for_resource(Quickeebooks::Online::Model::Bill.resource_for_singular)}/56"
40
+ FakeWeb.register_uri(:get, url, :status => ["200", "OK"], :body => xml)
41
+ bill = @service.fetch_by_id(56)
42
+ bill.header.total_amount.should == 50
43
+ end
44
+
45
+ it "can update a bill" do
46
+ xml2 = onlineFixture("bill2.xml")
47
+ bill = Quickeebooks::Online::Model::Bill.new
48
+ bill.header = Quickeebooks::Online::Model::BillHeader.new
49
+ bill.header.total_amount = 75.00
50
+ bill.id = Quickeebooks::Online::Model::Id.new("56")
51
+ bill.sync_token = 2
52
+
53
+ url = "#{@service.url_for_resource(Quickeebooks::Online::Model::Bill.resource_for_singular)}/#{bill.id.value}"
54
+ FakeWeb.register_uri(:post, url, :status => ["200", "OK"], :body => xml2)
55
+ updated = @service.update(bill)
56
+ updated.header.total_amount.should == 75.00
57
+ end
58
+
59
+
60
+ end
61
+
@@ -1,8 +1,3 @@
1
- require "spec_helper"
2
- require "fakeweb"
3
- require "oauth"
4
- require "quickeebooks"
5
-
6
1
  describe "Quickeebooks::Online::Service::CompanyMetaData" do
7
2
  before(:all) do
8
3
  FakeWeb.allow_net_connect = false
@@ -17,7 +12,7 @@ describe "Quickeebooks::Online::Service::CompanyMetaData" do
17
12
  :access_token_path => "/oauth/v1/get_access_token"
18
13
  })
19
14
  @oauth = OAuth::AccessToken.new(@oauth_consumer, "blah", "blah")
20
-
15
+
21
16
  @service = Quickeebooks::Online::Service::CompanyMetaData.new
22
17
  @service.access_token = @oauth
23
18
  @service.instance_eval {
@@ -26,7 +21,7 @@ describe "Quickeebooks::Online::Service::CompanyMetaData" do
26
21
  end
27
22
 
28
23
  it "can get the realm's company_meta_data record" do
29
- xml = File.read(File.dirname(__FILE__) + "/../../../xml/online/company_meta_data.xml")
24
+ xml = onlineFixture("company_meta_data.xml")
30
25
  url = @service.url_for_resource(Quickeebooks::Online::Model::CompanyMetaData.resource_for_singular)
31
26
  FakeWeb.register_uri(:get, url, :status => ["200", "OK"], :body => xml)
32
27
  company_meta_data_response = @service.load