xeroizer 2.18.1 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +199 -223
  3. data/lib/xeroizer/connection.rb +49 -0
  4. data/lib/xeroizer/exceptions.rb +2 -0
  5. data/lib/xeroizer/generic_application.rb +12 -5
  6. data/lib/xeroizer/http.rb +5 -78
  7. data/lib/xeroizer/http_response.rb +157 -0
  8. data/lib/xeroizer/models/bank_account.rb +1 -0
  9. data/lib/xeroizer/models/bank_transaction.rb +1 -0
  10. data/lib/xeroizer/models/batch_payment.rb +27 -0
  11. data/lib/xeroizer/models/branding_theme.rb +49 -9
  12. data/lib/xeroizer/models/contact.rb +10 -4
  13. data/lib/xeroizer/models/contact_group.rb +45 -0
  14. data/lib/xeroizer/models/credit_note.rb +23 -22
  15. data/lib/xeroizer/models/from_bank_account.rb +1 -0
  16. data/lib/xeroizer/models/history_record.rb +72 -0
  17. data/lib/xeroizer/models/invoice.rb +14 -3
  18. data/lib/xeroizer/models/line_item.rb +17 -5
  19. data/lib/xeroizer/models/manual_journal.rb +2 -1
  20. data/lib/xeroizer/models/option.rb +1 -1
  21. data/lib/xeroizer/models/organisation.rb +2 -0
  22. data/lib/xeroizer/models/payment_service.rb +22 -0
  23. data/lib/xeroizer/models/payroll/address.rb +53 -0
  24. data/lib/xeroizer/models/payroll/bank_account.rb +18 -6
  25. data/lib/xeroizer/models/payroll/benefit_line.rb +26 -0
  26. data/lib/xeroizer/models/payroll/benefit_type.rb +45 -0
  27. data/lib/xeroizer/models/payroll/deduction_line.rb +32 -0
  28. data/lib/xeroizer/models/payroll/deduction_type.rb +49 -0
  29. data/lib/xeroizer/models/payroll/earnings_line.rb +39 -0
  30. data/lib/xeroizer/models/payroll/earnings_type.rb +53 -0
  31. data/lib/xeroizer/models/payroll/employee.rb +30 -8
  32. data/lib/xeroizer/models/payroll/leave_application.rb +27 -0
  33. data/lib/xeroizer/models/payroll/leave_line.rb +30 -0
  34. data/lib/xeroizer/models/payroll/leave_period.rb +15 -0
  35. data/lib/xeroizer/models/payroll/pay_items.rb +22 -0
  36. data/lib/xeroizer/models/payroll/pay_run.rb +33 -0
  37. data/lib/xeroizer/models/payroll/pay_schedule.rb +40 -0
  38. data/lib/xeroizer/models/payroll/pay_template.rb +24 -0
  39. data/lib/xeroizer/models/payroll/payment_method.rb +24 -0
  40. data/lib/xeroizer/models/payroll/paystub.rb +44 -0
  41. data/lib/xeroizer/models/payroll/reimbursement_line.rb +21 -0
  42. data/lib/xeroizer/models/payroll/reimbursement_type.rb +22 -0
  43. data/lib/xeroizer/models/payroll/salary_and_wage.rb +29 -0
  44. data/lib/xeroizer/models/payroll/super_line.rb +40 -0
  45. data/lib/xeroizer/models/payroll/tax_declaration.rb +50 -0
  46. data/lib/xeroizer/models/payroll/time_off_line.rb +20 -0
  47. data/lib/xeroizer/models/payroll/time_off_type.rb +32 -0
  48. data/lib/xeroizer/models/payroll/work_location.rb +25 -0
  49. data/lib/xeroizer/models/prepayment.rb +1 -0
  50. data/lib/xeroizer/models/purchase_order.rb +6 -6
  51. data/lib/xeroizer/models/quote.rb +76 -0
  52. data/lib/xeroizer/models/schedule.rb +1 -0
  53. data/lib/xeroizer/models/tax_component.rb +1 -0
  54. data/lib/xeroizer/models/to_bank_account.rb +1 -0
  55. data/lib/xeroizer/oauth.rb +12 -1
  56. data/lib/xeroizer/oauth2.rb +82 -0
  57. data/lib/xeroizer/oauth2_application.rb +49 -0
  58. data/lib/xeroizer/payroll_application.rb +8 -3
  59. data/lib/xeroizer/record/base.rb +1 -1
  60. data/lib/xeroizer/record/base_model.rb +1 -1
  61. data/lib/xeroizer/record/base_model_http_proxy.rb +4 -0
  62. data/lib/xeroizer/record/model_definition_helper.rb +1 -1
  63. data/lib/xeroizer/record/payroll_base.rb +4 -0
  64. data/lib/xeroizer/record/record_association_helper.rb +4 -4
  65. data/lib/xeroizer/record/validators/associated_validator.rb +1 -0
  66. data/lib/xeroizer/record/xml_helper.rb +18 -18
  67. data/lib/xeroizer/report/aged_receivables_by_contact.rb +1 -1
  68. data/lib/xeroizer/report/cell_xml_helper.rb +13 -13
  69. data/lib/xeroizer/response.rb +22 -17
  70. data/lib/xeroizer/version.rb +1 -1
  71. data/lib/xeroizer.rb +33 -4
  72. data/test/acceptance/about_creating_bank_transactions_test.rb +80 -82
  73. data/test/acceptance/about_creating_prepayment_test.rb +25 -30
  74. data/test/acceptance/about_fetching_bank_transactions_test.rb +12 -12
  75. data/test/acceptance/about_online_invoice_test.rb +6 -10
  76. data/test/acceptance/acceptance_test.rb +28 -26
  77. data/test/acceptance/bank_transfer_test.rb +12 -17
  78. data/test/acceptance/bulk_operations_test.rb +18 -16
  79. data/test/acceptance/connections_test.rb +11 -0
  80. data/test/stub_responses/bad_request.json +6 -0
  81. data/test/stub_responses/connections.json +16 -0
  82. data/test/stub_responses/expired_oauth2_token.json +6 -0
  83. data/test/stub_responses/generic_response_error.json +6 -0
  84. data/test/stub_responses/invalid_oauth2_request_token.json +6 -0
  85. data/test/stub_responses/invalid_tenant_header.json +6 -0
  86. data/test/stub_responses/object_not_found.json +6 -0
  87. data/test/stub_responses/organisations.xml +10 -0
  88. data/test/stub_responses/payment_service.xml +15 -0
  89. data/test/test_helper.rb +16 -11
  90. data/test/unit/generic_application_test.rb +21 -10
  91. data/test/unit/http_test.rb +284 -10
  92. data/test/unit/models/address_test.rb +2 -2
  93. data/test/unit/models/bank_transaction_model_parsing_test.rb +2 -2
  94. data/test/unit/models/bank_transaction_test.rb +1 -1
  95. data/test/unit/models/bank_transaction_validation_test.rb +1 -1
  96. data/test/unit/models/contact_test.rb +2 -2
  97. data/test/unit/models/credit_note_test.rb +8 -8
  98. data/test/unit/models/employee_test.rb +4 -4
  99. data/test/unit/models/invoice_test.rb +12 -12
  100. data/test/unit/models/journal_line_test.rb +6 -6
  101. data/test/unit/models/journal_test.rb +4 -4
  102. data/test/unit/models/line_item_sum_test.rb +1 -1
  103. data/test/unit/models/line_item_test.rb +26 -28
  104. data/test/unit/models/manual_journal_test.rb +3 -3
  105. data/test/unit/models/organisation_test.rb +16 -2
  106. data/test/unit/models/payment_service_test.rb +29 -0
  107. data/test/unit/models/phone_test.rb +7 -7
  108. data/test/unit/models/prepayment_test.rb +4 -4
  109. data/test/unit/models/repeating_invoice_test.rb +3 -3
  110. data/test/unit/models/tax_rate_test.rb +2 -2
  111. data/test/unit/oauth2_test.rb +171 -0
  112. data/test/unit/oauth_config_test.rb +1 -1
  113. data/test/unit/record/base_model_test.rb +13 -13
  114. data/test/unit/record/base_test.rb +15 -4
  115. data/test/unit/record/block_validator_test.rb +1 -1
  116. data/test/unit/record/connection_test.rb +60 -0
  117. data/test/unit/record/model_definition_test.rb +36 -36
  118. data/test/unit/record/parse_params_test.rb +2 -2
  119. data/test/unit/record/parse_where_hash_test.rb +13 -13
  120. data/test/unit/record/record_association_test.rb +14 -14
  121. data/test/unit/record/validators_test.rb +43 -43
  122. data/test/unit/record_definition_test.rb +7 -7
  123. data/test/unit/report_definition_test.rb +7 -7
  124. data/test/unit/report_test.rb +20 -20
  125. data/test/unit_test_helper.rb +16 -0
  126. metadata +100 -25
  127. data/lib/xeroizer/models/payroll/home_address.rb +0 -24
  128. data/lib/xeroizer/partner_application.rb +0 -51
  129. data/lib/xeroizer/private_application.rb +0 -25
  130. data/lib/xeroizer/public_application.rb +0 -21
  131. data/test/unit/http_tsl_12_upgrade_test.rb +0 -31
  132. data/test/unit/oauth_test.rb +0 -118
  133. data/test/unit/private_application_test.rb +0 -20
@@ -1,10 +1,11 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class RecordBaseTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET, tenant_id: TENANT_ID)
8
+ @client.authorize_from_access(ACCESS_TOKEN)
8
9
  @contact = @client.Contact.build(:name => 'Test Contact Name ABC')
9
10
  end
10
11
 
@@ -26,14 +27,14 @@ class RecordBaseTest < Test::Unit::TestCase
26
27
  context "new_record? states" do
27
28
 
28
29
  should "new_record? should be false when loading data" do
29
- Xeroizer::OAuth.any_instance.stubs(:get).returns(stub(:plain_body => get_record_xml(:contact), :code => '200'))
30
+ Xeroizer::OAuth2.any_instance.stubs(:get).returns(stub(:plain_body => get_record_xml(:contact), :code => '200'))
30
31
  contact = @client.Contact.find('TESTID')
31
32
  assert_kind_of(Xeroizer::Record::Contact, contact)
32
33
  assert_equal(false, contact.new_record?)
33
34
  end
34
35
 
35
36
  should "new_record? should be false after successfully creating a record" do
36
- Xeroizer::OAuth.any_instance.stubs(:put).returns(stub(:plain_body => get_record_xml(:contact), :code => '200'))
37
+ Xeroizer::OAuth2.any_instance.stubs(:put).returns(stub(:plain_body => get_record_xml(:contact), :code => '200'))
37
38
  assert_equal(true, @contact.new_record?)
38
39
  assert_nil(@contact.contact_id)
39
40
  assert_equal(true, @contact.save, "Error saving contact: #{@contact.errors.inspect}")
@@ -104,6 +105,16 @@ class RecordBaseTest < Test::Unit::TestCase
104
105
  end
105
106
  end
106
107
 
108
+ context 'build' do
109
+
110
+ should "raise an undefined method error with useful message" do
111
+ assert_raise_message("undefined method `this_method_does_not_exist=' for #<Xeroizer::Record::Contact >") do
112
+ @client.Contact.build(:this_method_does_not_exist => true)
113
+ end
114
+ end
115
+
116
+ end
117
+
107
118
  context 'saving' do
108
119
  context 'invalid record' do
109
120
  setup do
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'unit_test_helper'
2
2
 
3
3
  class BlockValidatorTest < Test::Unit::TestCase
4
4
  def setup
@@ -0,0 +1,60 @@
1
+ require 'unit_test_helper'
2
+
3
+ class ConnectionTest < UnitTestCase
4
+ include TestHelper
5
+
6
+ setup do
7
+ @client = Xeroizer::OAuth2Application.new("client id", "client secret", access_token: "access token")
8
+ end
9
+
10
+ context "when the request succeeds" do
11
+ setup do
12
+ stub_request(:get, "https://api.xero.com/connections").to_return(
13
+ body: [
14
+ {
15
+ id: "fe4cd81c-624a-4506-ab18-11c656742436",
16
+ tenantId: "c84e0419-ade8-4296-9794-289876d4bc22",
17
+ tenantType: "ORGANISATION",
18
+ createdDateUtc: "2019-12-13T18:10:43.3063640",
19
+ updatedDateUtc: "2019-12-13T18:10:43.3084790"
20
+ },
21
+ {
22
+ id: "fe4cd81c-624a-4506-ab18-11c656742436",
23
+ tenantId: "c84e0419-ade8-4296-9794-289876d4bc22",
24
+ tenantType: "ORGANISATION",
25
+ createdDateUtc: "2019-12-13T18:10:43.3063640",
26
+ updatedDateUtc: "2019-12-13T18:10:43.3084790"
27
+ }
28
+ ].to_json
29
+ )
30
+ end
31
+
32
+ it 'returns connections using the passed client' do
33
+ result = Xeroizer::Connection.current_connections(@client.client)
34
+ assert_equal 2, result.count
35
+ assert_equal "c84e0419-ade8-4296-9794-289876d4bc22", result.first.tenant_id
36
+ end
37
+ end
38
+
39
+ context 'when the request fails' do
40
+ setup do
41
+ @body = {
42
+ title: "Unauthorized",
43
+ status: 401,
44
+ detail: "AuthenticationUnsuccessful",
45
+ instance: "e1d2cb91-82bf-41a5-84dd-fe6a5c6f070c"
46
+ }.to_json
47
+
48
+ stub_request(:get, "https://api.xero.com/connections").to_return(
49
+ status: 401,
50
+ body: @body
51
+ )
52
+ end
53
+
54
+ it 'raises token_invalid error' do
55
+ assert_raises(Xeroizer::OAuth::TokenInvalid, @body) {
56
+ Xeroizer::Connection.current_connections(@client.client)
57
+ }
58
+ end
59
+ end
60
+ end
@@ -1,12 +1,12 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class ModelDefinitionsTest < Test::Unit::TestCase
4
4
  include TestHelper
5
-
5
+
6
6
  class FirstRecord < Xeroizer::Record::Base
7
-
7
+
8
8
  set_primary_key :primary_key_id
9
-
9
+
10
10
  guid :primary_key_id
11
11
  string :string1
12
12
  boolean :boolean1
@@ -14,14 +14,14 @@ class ModelDefinitionsTest < Test::Unit::TestCase
14
14
  decimal :decimal1
15
15
  date :date1
16
16
  datetime :datetime1
17
-
17
+
18
18
  end
19
19
  class Xeroizer::Record::FirstRecordModel < Xeroizer::Record::BaseModel; end
20
-
20
+
21
21
  class SecondRecord < Xeroizer::Record::Base
22
22
 
23
23
  set_primary_key :primary_key_id
24
-
24
+
25
25
  guid :primary_key_id
26
26
  string :string2
27
27
  boolean :boolean2
@@ -32,63 +32,63 @@ class ModelDefinitionsTest < Test::Unit::TestCase
32
32
 
33
33
  end
34
34
  class Xeroizer::Record::SecondRecordModel < Xeroizer::Record::BaseModel; end
35
-
35
+
36
36
  class TestRecord < Xeroizer::Record::Base
37
-
37
+
38
38
  string :xml_name, :api_name => 'ApiNameHere', :internal_name => :internal_name_here
39
39
  string :name
40
-
40
+
41
41
  end
42
42
  class Xeroizer::Record::TestRecordModel < Xeroizer::Record::BaseModel; end
43
-
43
+
44
44
  class SummaryOnlyRecord < Xeroizer::Record::Base
45
45
  class Xeroizer::Record::SummaryOnlyRecordModel < Xeroizer::Record::BaseModel; end
46
-
46
+
47
47
  list_contains_summary_only true
48
48
  set_possible_primary_keys :primary_key_id
49
49
  set_primary_key :primary_key_id
50
-
50
+
51
51
  string :primary_key_id
52
52
  string :name
53
53
  end
54
-
54
+
55
55
  class SummaryOnlyOffRecord < Xeroizer::Record::Base
56
56
  class Xeroizer::Record::SummaryOnlyOffRecordModel < Xeroizer::Record::BaseModel; end
57
-
57
+
58
58
  set_possible_primary_keys :primary_key_id
59
59
  set_primary_key :primary_key_id
60
-
60
+
61
61
  string :primary_key_id
62
62
  string :name
63
63
  end
64
-
64
+
65
65
  def setup
66
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
66
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
67
67
  parent = stub(:application => @client, :mark_dirty => nil)
68
68
  @first = FirstRecord.new(parent)
69
69
  @second = SecondRecord.new(parent)
70
70
  @record = TestRecord.build({}, @client.Contact)
71
71
  @contact = @client.Contact.build
72
72
  end
73
-
73
+
74
74
  context "list contains summary only test" do
75
-
75
+
76
76
  should "show download complete if not summary record and id set" do
77
77
  record = SummaryOnlyRecord.build({}, @client.Contact)
78
78
  record.id = "NOTBLANK"
79
79
  assert_equal(false, record.new_record?)
80
80
  assert_equal(false, record.complete_record_downloaded?)
81
-
81
+
82
82
  record = SummaryOnlyOffRecord.build({}, @client.Contact)
83
83
  record.id = "NOTBLANK"
84
84
  assert_equal(false, record.new_record?)
85
85
  assert_equal(true, record.complete_record_downloaded?)
86
86
  end
87
-
87
+
88
88
  end
89
-
89
+
90
90
  context "record field definition" do
91
-
91
+
92
92
  should "define primary key with real name" do
93
93
  assert_nil(@first.id)
94
94
  value = "PRIMARY KEY VALUE"
@@ -96,7 +96,7 @@ class ModelDefinitionsTest < Test::Unit::TestCase
96
96
  assert_equal(value, @first.primary_key_id)
97
97
  assert_equal(value, @first.id)
98
98
  end
99
-
99
+
100
100
  should "define primary key with shortcut #id method" do
101
101
  assert_nil(@first.id)
102
102
  value = "PRIMARY KEY VALUE"
@@ -104,7 +104,7 @@ class ModelDefinitionsTest < Test::Unit::TestCase
104
104
  assert_equal(value, @first.id)
105
105
  assert_equal(value, @first.primary_key_id)
106
106
  end
107
-
107
+
108
108
  should "only have proper fields" do
109
109
  fieldset = [:primary_key_id, :string1, :boolean1, :integer1, :decimal1, :date1, :datetime1]
110
110
  fieldset.each do | field |
@@ -116,16 +116,16 @@ class ModelDefinitionsTest < Test::Unit::TestCase
116
116
  fieldset.each do | field |
117
117
  assert(@second.class.fields.keys.include?(field), "#{field} not in SecondRecord.fields")
118
118
  end
119
- assert_equal(fieldset.size, @second.class.fields.size)
119
+ assert_equal(fieldset.size, @second.class.fields.size)
120
120
  end
121
-
121
+
122
122
  should "have correct names" do
123
123
  assert(@record.respond_to?(:internal_name_here), "Internal name should be internal_name_here")
124
124
  assert(@record.class.fields.keys.include?(:xml_name), "Field key name should be xml_name")
125
125
  assert_equal('ApiNameHere', @record.class.fields[:xml_name][:api_name])
126
126
  end
127
-
128
- should "have shortcut reader/writer" do
127
+
128
+ should "have shortcut reader/writer" do
129
129
  assert_nil(@first.string1)
130
130
  value = 'TEST VALUE'
131
131
  @first.string1 = value
@@ -136,30 +136,30 @@ class ModelDefinitionsTest < Test::Unit::TestCase
136
136
  @first[:string1] = value
137
137
  assert_equal(value, @first.attributes[:string1])
138
138
  end
139
-
139
+
140
140
  should "define reader/writer methods" do
141
141
  assert(@record.respond_to?(:name), "FirstRecord#name should exist.")
142
142
  assert(@record.respond_to?(:name=), "FirstRecord#name= should exist.")
143
-
143
+
144
144
  value = "TEST NAME"
145
145
  @record.attributes[:name] = value
146
146
  assert_equal(value, @record.attributes[:name])
147
147
  assert_equal(value, @record[:name])
148
148
  assert_equal(value, @record.name)
149
-
149
+
150
150
  value = "TEST DIFFERENT"
151
151
  @record.name = value
152
152
  assert_equal(value, @record.attributes[:name])
153
153
  assert_equal(value, @record[:name])
154
154
  assert_equal(value, @record.name)
155
-
155
+
156
156
  value = "TEST DIFFERENT AGAIN"
157
157
  @record[:name] = value
158
158
  assert_equal(value, @record.attributes[:name])
159
159
  assert_equal(value, @record[:name])
160
160
  assert_equal(value, @record.name)
161
161
  end
162
-
162
+
163
163
  end
164
-
164
+
165
165
  end
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  module Xeroizer
4
4
  module Record
@@ -27,7 +27,7 @@ class ParseParamsTest < Test::Unit::TestCase
27
27
  include TestHelper
28
28
 
29
29
  def setup
30
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
30
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
31
31
  @model = Xeroizer::Record::ParseParamTestModel.new(@client, "ParseParamTest")
32
32
  end
33
33
 
@@ -1,11 +1,11 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  module Xeroizer
4
4
  module Record
5
-
5
+
6
6
  class WhereHashTestModel < BaseModel
7
7
  end
8
-
8
+
9
9
  class WhereHashTest < Base
10
10
 
11
11
  set_primary_key :primary_key_id
@@ -19,32 +19,32 @@ module Xeroizer
19
19
  datetime :datetime1
20
20
 
21
21
  end
22
-
22
+
23
23
  end
24
- end
24
+ end
25
25
 
26
26
  class ParseWhereHashTest < Test::Unit::TestCase
27
27
  include TestHelper
28
-
28
+
29
29
  def setup
30
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
30
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
31
31
  @model = Xeroizer::Record::WhereHashTestModel.new(@client, "WhereHashTest")
32
32
  end
33
-
33
+
34
34
  context "where hash" do
35
-
35
+
36
36
  should "parse valid hash" do
37
37
  @model.send(:parse_where_hash, {
38
- :primary_key_id => 'f7eca431-5c97-4d24-93fd-004bb8a6c644',
39
- :string1 => 'test',
40
- :boolean1 => true,
38
+ :primary_key_id => 'f7eca431-5c97-4d24-93fd-004bb8a6c644',
39
+ :string1 => 'test',
40
+ :boolean1 => true,
41
41
  :integer1 => 10,
42
42
  :decimal1 => 123.45,
43
43
  :date1 => Date.parse("2010-01-05"),
44
44
  :datetime1 => Time.parse("2010-02-30 09:10:20")
45
45
  })
46
46
  end
47
-
47
+
48
48
  should 'have valid expression components' do
49
49
  assert_equal('String1=="abc"', CGI.unescape(@model.send(:parse_where_hash, {:string1 => 'abc'})))
50
50
  assert_equal('String1<>"abc"', CGI.unescape(@model.send(:parse_where_hash, {:string1_is_not => 'abc'})))
@@ -1,16 +1,16 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class RecordAssociationTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  mock_api('Invoices')
9
9
  @client.stubs(:http_put).returns(get_record_xml(:invoice, "762aa45d-4632-45b5-8087-b4f47690665e"))
10
10
  end
11
-
11
+
12
12
  context "belongs_to association" do
13
-
13
+
14
14
  should "auto-load complete record if summary" do
15
15
  invoice = @client.Invoice.first
16
16
  assert_nil(invoice.attributes[:contact].contact_status)
@@ -18,11 +18,11 @@ class RecordAssociationTest < Test::Unit::TestCase
18
18
  assert_not_nil(invoice.contact.contact_status)
19
19
  assert_equal(true, invoice.complete_record_downloaded?)
20
20
  end
21
-
21
+
22
22
  end
23
-
23
+
24
24
  context "has_many association" do
25
-
25
+
26
26
  should "auto-load complete records if summary" do
27
27
  invoice = @client.Invoice.first
28
28
  assert_nil(invoice.attributes[:line_items])
@@ -30,7 +30,7 @@ class RecordAssociationTest < Test::Unit::TestCase
30
30
  assert(invoice.line_items.size > 0, "There should be one or more line items.")
31
31
  assert_equal(true, invoice.complete_record_downloaded?)
32
32
  end
33
-
33
+
34
34
  should "auto-build belongs_to item when passed hash" do
35
35
  invoice = @client.Invoice.build
36
36
  assert_nil(invoice.contact)
@@ -38,7 +38,7 @@ class RecordAssociationTest < Test::Unit::TestCase
38
38
  assert_kind_of(Xeroizer::Record::Contact, invoice.contact)
39
39
  assert_equal("Test Contact", invoice.contact.name)
40
40
  end
41
-
41
+
42
42
  should "auto-build has_many items when passed hash" do
43
43
  contact = @client.Contact.build
44
44
  assert_equal([], contact.phones)
@@ -46,11 +46,11 @@ class RecordAssociationTest < Test::Unit::TestCase
46
46
  assert_kind_of(Xeroizer::Record::Phone, contact.phones.first)
47
47
  assert_equal("1234", contact.phones.first.number)
48
48
  end
49
-
49
+
50
50
  should "auto-build has_many items when passed array" do
51
51
  contact = @client.Contact.build
52
52
  assert_equal([], contact.phones)
53
-
53
+
54
54
  data = [
55
55
  {:type => "DEFAULT", :number => "1111"},
56
56
  {:type => "FAX", :number => "2222"}
@@ -58,12 +58,12 @@ class RecordAssociationTest < Test::Unit::TestCase
58
58
  contact.phones = data.dup
59
59
 
60
60
  assert_equal(2, contact.phones.size)
61
- contact.phones.each_with_index do | phone, index |
61
+ contact.phones.each_with_index do | phone, index |
62
62
  assert_kind_of(Xeroizer::Record::Phone, phone)
63
63
  assert_equal(data[index][:number], phone.number)
64
64
  end
65
65
  end
66
-
66
+
67
67
  should "retain unsaved items after create" do
68
68
  invoice = @client.Invoice.build :type => "ACCREC", :contact => { :name => "A" }
69
69
  invoice.save
@@ -89,5 +89,5 @@ class RecordAssociationTest < Test::Unit::TestCase
89
89
  assert_equal(1, invoice.line_items.size, "There should be one line item.")
90
90
  end
91
91
  end
92
-
92
+
93
93
  end