xero_gateway 2.3.0 → 2.4.0
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.
- checksums.yaml +4 -4
- data/README.md +87 -82
- data/examples/partner_app.rb +0 -4
- data/examples/private_app.rb +18 -0
- data/lib/xero_gateway/account.rb +29 -12
- data/lib/xero_gateway/bank_transaction.rb +6 -11
- data/lib/xero_gateway/base_record.rb +26 -7
- data/lib/xero_gateway/contact.rb +40 -38
- data/lib/xero_gateway/contact_group.rb +12 -10
- data/lib/xero_gateway/credit_note.rb +42 -50
- data/lib/xero_gateway/gateway.rb +10 -7
- data/lib/xero_gateway/invoice.rb +53 -54
- data/lib/xero_gateway/line_item_calculations.rb +20 -22
- data/lib/xero_gateway/manual_journal.rb +2 -1
- data/lib/xero_gateway/organisation.rb +8 -1
- data/lib/xero_gateway/partner_app.rb +14 -20
- data/lib/xero_gateway/tax_rate.rb +1 -0
- data/lib/xero_gateway/version.rb +1 -1
- data/test/integration/get_invoices_test.rb +31 -22
- data/test/integration/get_organisation_test.rb +8 -7
- data/test/integration/get_tax_rates_test.rb +8 -8
- data/test/test_helper.rb +1 -1
- data/test/unit/account_test.rb +10 -6
- data/test/unit/bank_transaction_test.rb +11 -2
- data/test/unit/contact_test.rb +62 -0
- data/test/unit/credit_note_test.rb +51 -63
- data/test/unit/gateway_test.rb +16 -4
- data/test/unit/invoice_test.rb +91 -55
- data/test/unit/manual_journal_test.rb +7 -7
- data/test/unit/organisation_test.rb +52 -7
- data/test/unit/tax_rate_test.rb +8 -7
- data/xero_gateway.gemspec +7 -2
- metadata +8 -7
data/test/unit/invoice_test.rb
CHANGED
@@ -3,14 +3,45 @@ require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
|
3
3
|
class InvoiceTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
context "with line item totals" do
|
6
|
+
setup do
|
7
|
+
# make sure the invoices think they have a gateway
|
8
|
+
@invoice = create_test_invoice(
|
9
|
+
invoice_id: "a99a9aaa-9999-99a9-9aa9-aaaaaa9a9999",
|
10
|
+
line_items_downloaded: false,
|
11
|
+
total: 6_969_00,
|
12
|
+
total_tax: 1_045.35,
|
13
|
+
sub_total: 5_923.65
|
14
|
+
)
|
15
|
+
@invoice.gateway = stub
|
16
|
+
end
|
6
17
|
|
7
18
|
should "allow setting and reading these as instance variables without downloading line items" do
|
8
|
-
invoice
|
19
|
+
assert !@invoice.line_items_downloaded?
|
9
20
|
|
10
|
-
assert !invoice.line_items_downloaded?
|
11
21
|
XeroGateway::Invoice.any_instance.expects(:download_line_items).never
|
12
|
-
assert_equal 6969_00,
|
22
|
+
assert_equal 6969_00, @invoice.total
|
23
|
+
assert_equal 1_045.35, @invoice.total_tax
|
24
|
+
assert_equal 5_923.65, @invoice.sub_total
|
25
|
+
end
|
26
|
+
|
27
|
+
should "download line items if we call #line_items" do
|
28
|
+
XeroGateway::Invoice.any_instance.expects(:download_line_items).once.returns([])
|
29
|
+
assert_equal [], @invoice.line_items
|
13
30
|
end
|
31
|
+
|
32
|
+
should "also work when creating an invoice from XML" do
|
33
|
+
invoices_response_xml = File.open(File.join(File.dirname(__FILE__), "..", "stub_responses", "invoices.xml")).read
|
34
|
+
invoice_element = REXML::XPath.first(REXML::Document.new(invoices_response_xml), "/Response/Invoices/Invoice")
|
35
|
+
from_xml = XeroGateway::Invoice.from_xml(invoice_element)
|
36
|
+
from_xml.gateway = stub()
|
37
|
+
|
38
|
+
assert !from_xml.line_items_downloaded?
|
39
|
+
XeroGateway::Invoice.any_instance.expects(:download_line_items).never
|
40
|
+
assert_equal 1125.0, from_xml.total
|
41
|
+
assert_equal 125.0, from_xml.total_tax
|
42
|
+
assert_equal 1000.0, from_xml.sub_total
|
43
|
+
end
|
44
|
+
|
14
45
|
end
|
15
46
|
|
16
47
|
context "building and parsing XML" do
|
@@ -32,7 +63,7 @@ class InvoiceTest < Test::Unit::TestCase
|
|
32
63
|
should "work for optional params" do
|
33
64
|
invoice = create_test_invoice(:url => 'http://example.com?with=params&and=more')
|
34
65
|
invoice_element = REXML::XPath.first(REXML::Document.new(invoice.to_xml), "/Invoice")
|
35
|
-
assert_match
|
66
|
+
assert_match(/<Url>http:\/\/example.com\?with=params&and=more<\/Url>/, invoice_element.to_s)
|
36
67
|
|
37
68
|
parsed_invoice = XeroGateway::Invoice.from_xml(invoice_element)
|
38
69
|
assert_equal 'http://example.com?with=params&and=more', parsed_invoice.url
|
@@ -43,41 +74,41 @@ class InvoiceTest < Test::Unit::TestCase
|
|
43
74
|
def test_invoice_sub_total_calculation
|
44
75
|
invoice = create_test_invoice(:line_items_downloaded => true)
|
45
76
|
line_item = invoice.line_items.first
|
46
|
-
|
77
|
+
|
47
78
|
# Make sure that everything adds up to begin with.
|
48
|
-
expected_sub_total = invoice.line_items.inject(BigDecimal.new('0')) { | sum,
|
79
|
+
expected_sub_total = invoice.line_items.inject(BigDecimal.new('0')) { | sum, l | l.line_amount }
|
49
80
|
assert_equal(expected_sub_total, invoice.sub_total)
|
50
|
-
|
81
|
+
|
51
82
|
# Change the sub_total and check that it doesn't modify anything.
|
52
83
|
invoice.sub_total = expected_sub_total * 10
|
53
84
|
assert_equal(expected_sub_total, invoice.sub_total)
|
54
|
-
|
55
|
-
# Change the amount of the first line item and make sure that
|
85
|
+
|
86
|
+
# Change the amount of the first line item and make sure that
|
56
87
|
# everything still continues to add up.
|
57
88
|
line_item.unit_amount = line_item.unit_amount + 10
|
58
89
|
assert_not_equal(expected_sub_total, invoice.sub_total)
|
59
|
-
expected_sub_total = invoice.line_items.inject(BigDecimal.new('0')) { | sum,
|
90
|
+
expected_sub_total = invoice.line_items.inject(BigDecimal.new('0')) { | sum, l | l.line_amount }
|
60
91
|
assert_equal(expected_sub_total, invoice.sub_total)
|
61
92
|
end
|
62
|
-
|
93
|
+
|
63
94
|
# Tests the total_tax calculation and that setting it manually doesn't modify the data.
|
64
95
|
def test_invoice_sub_total_calculation2
|
65
96
|
invoice = create_test_invoice(:line_items_downloaded => true)
|
66
97
|
line_item = invoice.line_items.first
|
67
|
-
|
98
|
+
|
68
99
|
# Make sure that everything adds up to begin with.
|
69
|
-
expected_total_tax = invoice.line_items.inject(BigDecimal.new('0')) { | sum,
|
100
|
+
expected_total_tax = invoice.line_items.inject(BigDecimal.new('0')) { | sum, l | l.tax_amount }
|
70
101
|
assert_equal(expected_total_tax, invoice.total_tax)
|
71
|
-
|
102
|
+
|
72
103
|
# Change the total_tax and check that it doesn't modify anything.
|
73
104
|
invoice.total_tax = expected_total_tax * 10
|
74
105
|
assert_equal(expected_total_tax, invoice.total_tax)
|
75
|
-
|
76
|
-
# Change the tax_amount of the first line item and make sure that
|
106
|
+
|
107
|
+
# Change the tax_amount of the first line item and make sure that
|
77
108
|
# everything still continues to add up.
|
78
109
|
line_item.tax_amount = line_item.tax_amount + 10
|
79
110
|
assert_not_equal(expected_total_tax, invoice.total_tax)
|
80
|
-
expected_total_tax = invoice.line_items.inject(BigDecimal.new('0')) { | sum,
|
111
|
+
expected_total_tax = invoice.line_items.inject(BigDecimal.new('0')) { | sum, l | l.tax_amount }
|
81
112
|
assert_equal(expected_total_tax, invoice.total_tax)
|
82
113
|
end
|
83
114
|
|
@@ -86,16 +117,16 @@ class InvoiceTest < Test::Unit::TestCase
|
|
86
117
|
invoice = create_test_invoice(:line_items_downloaded => true)
|
87
118
|
assert invoice.line_items_downloaded?
|
88
119
|
line_item = invoice.line_items.first
|
89
|
-
|
120
|
+
|
90
121
|
# Make sure that everything adds up to begin with.
|
91
122
|
expected_total = invoice.sub_total + invoice.total_tax
|
92
123
|
assert_equal(expected_total, invoice.total)
|
93
|
-
|
124
|
+
|
94
125
|
# Change the total and check that it doesn't modify anything.
|
95
126
|
invoice.total = expected_total * 10
|
96
127
|
assert_equal(expected_total.to_f, invoice.total.to_f)
|
97
|
-
|
98
|
-
# Change the quantity of the first line item and make sure that
|
128
|
+
|
129
|
+
# Change the quantity of the first line item and make sure that
|
99
130
|
# everything still continues to add up.
|
100
131
|
line_item.quantity = line_item.quantity + 5
|
101
132
|
assert_not_equal(expected_total, invoice.total)
|
@@ -107,53 +138,53 @@ class InvoiceTest < Test::Unit::TestCase
|
|
107
138
|
def test_line_amount_calculation
|
108
139
|
invoice = create_test_invoice
|
109
140
|
line_item = invoice.line_items.first
|
110
|
-
|
141
|
+
|
111
142
|
# Make sure that everything adds up to begin with.
|
112
143
|
expected_amount = line_item.quantity * line_item.unit_amount
|
113
144
|
assert_equal(expected_amount, line_item.line_amount)
|
114
|
-
|
145
|
+
|
115
146
|
# Change the line_amount and check that it doesn't modify anything.
|
116
147
|
line_item.line_amount = expected_amount * 10
|
117
148
|
assert_equal(expected_amount, line_item.line_amount)
|
118
|
-
|
149
|
+
|
119
150
|
# Change the quantity and check that the line_amount has been updated.
|
120
151
|
quantity = line_item.quantity + 2
|
121
152
|
line_item.quantity = quantity
|
122
153
|
assert_not_equal(expected_amount, line_item.line_amount)
|
123
154
|
assert_equal(quantity * line_item.unit_amount, line_item.line_amount)
|
124
155
|
end
|
125
|
-
|
156
|
+
|
126
157
|
# Ensure that the totalling methods don't raise exceptions, even when
|
127
158
|
# invoice.line_items is empty.
|
128
159
|
def test_totalling_methods_when_line_items_empty
|
129
160
|
invoice = create_test_invoice
|
130
161
|
invoice.line_items = []
|
131
|
-
|
162
|
+
|
132
163
|
assert_nothing_raised(Exception) {
|
133
164
|
assert_equal(BigDecimal.new('0'), invoice.sub_total)
|
134
165
|
assert_equal(BigDecimal.new('0'), invoice.total_tax)
|
135
166
|
assert_equal(BigDecimal.new('0'), invoice.total)
|
136
167
|
}
|
137
168
|
end
|
138
|
-
|
169
|
+
|
139
170
|
def test_invoice_type_helper_methods
|
140
171
|
# Test accounts receivable invoices.
|
141
172
|
invoice = create_test_invoice({:invoice_type => 'ACCREC'})
|
142
173
|
assert_equal(true, invoice.accounts_receivable?, "Accounts RECEIVABLE invoice doesn't think it is.")
|
143
174
|
assert_equal(false, invoice.accounts_payable?, "Accounts RECEIVABLE invoice thinks it's payable.")
|
144
|
-
|
175
|
+
|
145
176
|
# Test accounts payable invoices.
|
146
177
|
invoice = create_test_invoice({:invoice_type => 'ACCPAY'})
|
147
178
|
assert_equal(false, invoice.accounts_receivable?, "Accounts PAYABLE invoice doesn't think it is.")
|
148
179
|
assert_equal(true, invoice.accounts_payable?, "Accounts PAYABLE invoice thinks it's receivable.")
|
149
180
|
end
|
150
|
-
|
151
|
-
|
181
|
+
|
182
|
+
|
152
183
|
# Make sure that the create_test_invoice method is working correctly
|
153
184
|
# with all the defaults and overrides.
|
154
185
|
def test_create_test_invoice_defaults_working
|
155
186
|
invoice = create_test_invoice
|
156
|
-
|
187
|
+
|
157
188
|
# Test invoice defaults.
|
158
189
|
assert_equal('ACCREC', invoice.invoice_type)
|
159
190
|
assert_kind_of(Date, invoice.date)
|
@@ -162,19 +193,19 @@ class InvoiceTest < Test::Unit::TestCase
|
|
162
193
|
assert_equal('12345', invoice.invoice_number)
|
163
194
|
assert_equal('MY REFERENCE FOR THIS INVOICE', invoice.reference)
|
164
195
|
assert_equal("Exclusive", invoice.line_amount_types)
|
165
|
-
|
196
|
+
|
166
197
|
# Test the contact defaults.
|
167
198
|
assert_equal('00000000-0000-0000-0000-000000000000', invoice.contact.contact_id)
|
168
199
|
assert_equal('CONTACT NAME', invoice.contact.name)
|
169
|
-
|
200
|
+
|
170
201
|
# Test address defaults.
|
171
202
|
assert_equal('DEFAULT', invoice.contact.address.address_type)
|
172
203
|
assert_equal('LINE 1 OF THE ADDRESS', invoice.contact.address.line_1)
|
173
|
-
|
204
|
+
|
174
205
|
# Test phone defaults.
|
175
206
|
assert_equal('DEFAULT', invoice.contact.phone.phone_type)
|
176
207
|
assert_equal('12345678', invoice.contact.phone.number)
|
177
|
-
|
208
|
+
|
178
209
|
# Test the line_item defaults.
|
179
210
|
assert_equal('A LINE ITEM', invoice.line_items.first.description)
|
180
211
|
assert_equal('200', invoice.line_items.first.account_code)
|
@@ -187,19 +218,19 @@ class InvoiceTest < Test::Unit::TestCase
|
|
187
218
|
# Test overriding an invoice parameter (assume works for all).
|
188
219
|
invoice = create_test_invoice({:invoice_type => 'ACCPAY'})
|
189
220
|
assert_equal('ACCPAY', invoice.invoice_type)
|
190
|
-
|
221
|
+
|
191
222
|
# Test overriding a contact/address/phone parameter (assume works for all).
|
192
223
|
invoice = create_test_invoice({}, {:name => 'OVERRIDDEN NAME', :address => {:line_1 => 'OVERRIDDEN LINE 1'}, :phone => {:number => '999'}})
|
193
224
|
assert_equal('OVERRIDDEN NAME', invoice.contact.name)
|
194
225
|
assert_equal('OVERRIDDEN LINE 1', invoice.contact.address.line_1)
|
195
226
|
assert_equal('999', invoice.contact.phone.number)
|
196
|
-
|
227
|
+
|
197
228
|
# Test overriding line_items with hash.
|
198
229
|
invoice = create_test_invoice({}, {}, {:description => 'OVERRIDDEN LINE ITEM'})
|
199
230
|
assert_equal(1, invoice.line_items.size)
|
200
231
|
assert_equal('OVERRIDDEN LINE ITEM', invoice.line_items.first.description)
|
201
232
|
assert_equal(BigDecimal.new('100'), invoice.line_items.first.unit_amount)
|
202
|
-
|
233
|
+
|
203
234
|
# Test overriding line_items with array of 2 line_items.
|
204
235
|
invoice = create_test_invoice({}, {}, [
|
205
236
|
{:description => 'OVERRIDDEN ITEM 1'},
|
@@ -211,28 +242,28 @@ class InvoiceTest < Test::Unit::TestCase
|
|
211
242
|
assert_equal('OVERRIDDEN ITEM 2', invoice.line_items[1].description)
|
212
243
|
assert_equal(BigDecimal.new('200'), invoice.line_items[1].unit_amount)
|
213
244
|
end
|
214
|
-
|
245
|
+
|
215
246
|
def test_auto_creation_of_associated_contact
|
216
247
|
invoice = create_test_invoice({}, nil) # no contact
|
217
|
-
|
218
|
-
|
248
|
+
assert(!invoice.instance_variable_defined?("@contact"))
|
249
|
+
|
219
250
|
new_contact = invoice.contact
|
220
251
|
assert_kind_of(XeroGateway::Contact, new_contact)
|
221
252
|
end
|
222
|
-
|
253
|
+
|
223
254
|
def test_add_line_item
|
224
255
|
invoice = create_test_invoice({}, {}, nil) # no line_items
|
225
256
|
assert_equal(0, invoice.line_items.size)
|
226
|
-
|
257
|
+
|
227
258
|
line_item_params = {:description => "Test Item 1", :unit_amount => 100}
|
228
|
-
|
259
|
+
|
229
260
|
# Test adding line item by hash
|
230
261
|
line_item = invoice.add_line_item(line_item_params)
|
231
262
|
assert_kind_of(XeroGateway::LineItem, line_item)
|
232
263
|
assert_equal(line_item_params[:description], line_item.description)
|
233
264
|
assert_equal(line_item_params[:unit_amount], line_item.unit_amount)
|
234
265
|
assert_equal(1, invoice.line_items.size)
|
235
|
-
|
266
|
+
|
236
267
|
# Test adding line item by XeroGateway::LineItem
|
237
268
|
line_item = invoice.add_line_item(line_item_params)
|
238
269
|
assert_kind_of(XeroGateway::LineItem, line_item)
|
@@ -253,9 +284,14 @@ class InvoiceTest < Test::Unit::TestCase
|
|
253
284
|
end
|
254
285
|
|
255
286
|
def test_optional_params
|
256
|
-
|
287
|
+
eur_code = "EUR"
|
288
|
+
eur_rate = 1.80
|
289
|
+
|
290
|
+
invoice = create_test_invoice(:url => 'http://example.com', :branding_theme_id => 'a94a78db-5cc6-4e26-a52b-045237e56e6e', :currency_code => eur_code, :currency_rate => eur_rate)
|
257
291
|
assert_equal 'http://example.com', invoice.url
|
258
292
|
assert_equal 'a94a78db-5cc6-4e26-a52b-045237e56e6e', invoice.branding_theme_id
|
293
|
+
assert_equal eur_code, invoice.currency_code
|
294
|
+
assert_equal eur_rate, invoice.currency_rate
|
259
295
|
end
|
260
296
|
|
261
297
|
def test_updated_date_utc
|
@@ -265,7 +301,7 @@ class InvoiceTest < Test::Unit::TestCase
|
|
265
301
|
end
|
266
302
|
|
267
303
|
private
|
268
|
-
|
304
|
+
|
269
305
|
def create_test_invoice(invoice_params = {}, contact_params = {}, line_item_params = [])
|
270
306
|
unless invoice_params.nil?
|
271
307
|
invoice_params = {
|
@@ -279,36 +315,36 @@ class InvoiceTest < Test::Unit::TestCase
|
|
279
315
|
}.merge(invoice_params)
|
280
316
|
end
|
281
317
|
invoice = XeroGateway::Invoice.new(invoice_params || {})
|
282
|
-
|
318
|
+
|
283
319
|
unless contact_params.nil?
|
284
320
|
# Strip out :address key from contact_params to use as the default address.
|
285
321
|
stripped_address = {
|
286
322
|
:address_type => 'DEFAULT',
|
287
323
|
:line_1 => 'LINE 1 OF THE ADDRESS'
|
288
324
|
}.merge(contact_params.delete(:address) || {})
|
289
|
-
|
325
|
+
|
290
326
|
# Strip out :phone key from contact_params to use at the default phone.
|
291
327
|
stripped_phone = {
|
292
328
|
:phone_type => 'DEFAULT',
|
293
329
|
:number => '12345678'
|
294
330
|
}.merge(contact_params.delete(:phone) || {})
|
295
|
-
|
331
|
+
|
296
332
|
contact_params = {
|
297
333
|
:contact_id => '00000000-0000-0000-0000-000000000000', # Just any valid GUID
|
298
334
|
:name => "CONTACT NAME",
|
299
335
|
:first_name => "Bob",
|
300
336
|
:last_name => "Builder"
|
301
337
|
}.merge(contact_params)
|
302
|
-
|
338
|
+
|
303
339
|
# Create invoice.contact from contact_params.
|
304
340
|
invoice.contact = XeroGateway::Contact.new(contact_params)
|
305
341
|
invoice.contact.address = XeroGateway::Address.new(stripped_address)
|
306
342
|
invoice.contact.phone = XeroGateway::Phone.new(stripped_phone)
|
307
343
|
end
|
308
|
-
|
344
|
+
|
309
345
|
unless line_item_params.nil?
|
310
346
|
line_item_params = [line_item_params].flatten # always use an array, even if only a single hash passed in
|
311
|
-
|
347
|
+
|
312
348
|
# At least one line item, make first have some defaults.
|
313
349
|
line_item_params << {} if line_item_params.size == 0
|
314
350
|
line_item_params[0] = {
|
@@ -318,13 +354,13 @@ class InvoiceTest < Test::Unit::TestCase
|
|
318
354
|
:tax_amount => BigDecimal.new("12.5"),
|
319
355
|
:tracking => XeroGateway::TrackingCategory.new(:name => "blah", :options => "hello")
|
320
356
|
}.merge(line_item_params[0])
|
321
|
-
|
357
|
+
|
322
358
|
# Create invoice.line_items from line_item_params
|
323
359
|
line_item_params.each do | line_item |
|
324
360
|
invoice.add_line_item(line_item)
|
325
361
|
end
|
326
362
|
end
|
327
|
-
|
363
|
+
|
328
364
|
invoice
|
329
365
|
end
|
330
366
|
|
@@ -10,7 +10,7 @@ class ManualJournalTest < Test::Unit::TestCase
|
|
10
10
|
# test transaction defaults
|
11
11
|
assert_equal 'POSTED', manual_journal.status
|
12
12
|
assert_kind_of Date, manual_journal.date
|
13
|
-
assert_equal 'test narration', manual_journal.narration
|
13
|
+
assert_equal 'test narration', manual_journal.narration
|
14
14
|
|
15
15
|
# Test the journal_line defaults.
|
16
16
|
journal_line = manual_journal.journal_lines.first
|
@@ -49,8 +49,8 @@ class ManualJournalTest < Test::Unit::TestCase
|
|
49
49
|
assert_equal(journal_line_params[:line_amount], journal_line.line_amount)
|
50
50
|
assert_equal(4, @manual_journal.journal_lines.size)
|
51
51
|
|
52
|
-
# Test that having only 1 journal line fails.
|
53
|
-
@manual_journal.journal_lines = []
|
52
|
+
# Test that having only 1 journal line fails.
|
53
|
+
@manual_journal.journal_lines = []
|
54
54
|
@manual_journal.add_journal_line(journal_line_params)
|
55
55
|
assert !@manual_journal.valid?
|
56
56
|
end
|
@@ -63,10 +63,10 @@ class ManualJournalTest < Test::Unit::TestCase
|
|
63
63
|
manual_journal_as_xml = manual_journal.to_xml
|
64
64
|
manual_journal_element = REXML::XPath.first(REXML::Document.new(manual_journal_as_xml), "/ManualJournal")
|
65
65
|
|
66
|
-
# checking for mandatory fields
|
66
|
+
# checking for mandatory fields
|
67
67
|
assert_xml_field manual_journal_element, 'Date'
|
68
68
|
assert_xml_field manual_journal_element, 'Narration', :value => 'test narration'
|
69
|
-
assert_xml_field manual_journal_element, 'Status', :value => 'POSTED'
|
69
|
+
assert_xml_field manual_journal_element, 'Status', :value => 'POSTED'
|
70
70
|
|
71
71
|
parsed_manual_journal = XeroGateway::ManualJournal.from_xml(manual_journal_element)
|
72
72
|
assert_equal(manual_journal, parsed_manual_journal)
|
@@ -86,8 +86,8 @@ class ManualJournalTest < Test::Unit::TestCase
|
|
86
86
|
private
|
87
87
|
|
88
88
|
def assert_xml_field(xml, field_name, options={})
|
89
|
-
assert_match
|
90
|
-
assert_match
|
89
|
+
assert_match(/#{field_name}/, xml.to_s, "Didn't find the field #{field_name} in the XML document!")
|
90
|
+
assert_match(/#{field_name}.*#{options[:value]}.*#{field_name}/, xml.to_s, "The field #{field_name} was expected to be '#{options[:value]}'!") if options[:value]
|
91
91
|
end
|
92
92
|
|
93
93
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
2
|
|
3
3
|
class OrganisationTest < Test::Unit::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
# Tests that an organisation can be converted into XML that Xero can understand, and then converted back to an organisation
|
6
6
|
def test_build_and_parse_xml
|
7
7
|
org = create_test_organisation
|
8
|
-
|
8
|
+
|
9
9
|
# Generate the XML message
|
10
10
|
org_as_xml = org.to_xml
|
11
11
|
|
@@ -14,14 +14,59 @@ class OrganisationTest < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
# Build a new account from the XML
|
16
16
|
result_org = XeroGateway::Organisation.from_xml(org_element)
|
17
|
-
|
17
|
+
|
18
18
|
# Check the account details
|
19
19
|
assert_equal org, result_org
|
20
20
|
end
|
21
|
-
|
22
|
-
|
21
|
+
|
22
|
+
def test_organisation_with_addresses
|
23
|
+
org = create_test_organisation
|
24
|
+
org.add_address(
|
25
|
+
:address_type => 'POBOX',
|
26
|
+
:line_1 => 'NEW LINE 1',
|
27
|
+
:line_2 => 'NEW LINE 2',
|
28
|
+
:line_3 => 'NEW LINE 3',
|
29
|
+
:line_4 => 'NEW LINE 4',
|
30
|
+
:city => 'NEW CITY',
|
31
|
+
:region => 'NEW REGION',
|
32
|
+
:post_code => '5555',
|
33
|
+
:country => 'Australia'
|
34
|
+
)
|
35
|
+
|
36
|
+
org_as_xml = org.to_xml
|
37
|
+
|
38
|
+
assert org_as_xml.include?("<Addresses><Address>")
|
39
|
+
assert org_as_xml.include?("NEW REGION")
|
40
|
+
|
41
|
+
org_element = REXML::XPath.first(REXML::Document.new(org_as_xml), "/Organisation")
|
42
|
+
result_org = XeroGateway::Organisation.from_xml(org_element)
|
43
|
+
|
44
|
+
assert_equal org, result_org
|
45
|
+
end
|
46
|
+
|
47
|
+
test "should raise if you add an unsupported type as an address" do
|
48
|
+
org = create_test_organisation
|
49
|
+
org.addresses = [ { :a => 123 }]
|
50
|
+
|
51
|
+
assert_raises "UnsupportedAttributeType" do
|
52
|
+
org.to_xml
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
test "works with an empty addresses attribute" do
|
57
|
+
org = create_test_organisation
|
58
|
+
org.addresses = []
|
59
|
+
|
60
|
+
assert org_as_xml = org.to_xml
|
61
|
+
|
62
|
+
org_element = REXML::XPath.first(REXML::Document.new(org_as_xml), "/Organisation")
|
63
|
+
result_org = XeroGateway::Organisation.from_xml(org_element)
|
64
|
+
|
65
|
+
assert_equal org, result_org
|
66
|
+
end
|
67
|
+
|
23
68
|
private
|
24
|
-
|
69
|
+
|
25
70
|
def create_test_organisation
|
26
71
|
XeroGateway::Organisation.new.tap do |org|
|
27
72
|
org.name = "Demo Company (NZ)"
|
@@ -36,4 +81,4 @@ class OrganisationTest < Test::Unit::TestCase
|
|
36
81
|
org.line_of_business = "Graphic Design & Web Development"
|
37
82
|
end
|
38
83
|
end
|
39
|
-
end
|
84
|
+
end
|
data/test/unit/tax_rate_test.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../test_helper.rb')
|
2
2
|
|
3
3
|
class TaxRateTest < Test::Unit::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
# Tests that a tax rate can be converted into XML that Xero can understand, and then converted back to a tax rate
|
6
6
|
def test_build_and_parse_xml
|
7
7
|
tax_rate = create_test_tax_rate
|
8
|
-
|
8
|
+
|
9
9
|
# Generate the XML message
|
10
10
|
tax_rate_as_xml = tax_rate.to_xml
|
11
11
|
|
@@ -14,18 +14,19 @@ class TaxRateTest < Test::Unit::TestCase
|
|
14
14
|
|
15
15
|
# Build a new account from the XML
|
16
16
|
result_tax_rate = XeroGateway::TaxRate.from_xml(tax_rate_element)
|
17
|
-
|
17
|
+
|
18
18
|
# Check the account details
|
19
19
|
assert_equal tax_rate, result_tax_rate
|
20
20
|
end
|
21
|
-
|
22
|
-
|
21
|
+
|
22
|
+
|
23
23
|
private
|
24
|
-
|
24
|
+
|
25
25
|
def create_test_tax_rate
|
26
26
|
XeroGateway::TaxRate.new.tap do |tax_rate|
|
27
27
|
tax_rate.name = "GST on Expenses"
|
28
28
|
tax_rate.tax_type = "INPUT"
|
29
|
+
tax_rate.status = "ACTIVE"
|
29
30
|
tax_rate.can_apply_to_assets = true
|
30
31
|
tax_rate.can_apply_to_equity = true
|
31
32
|
tax_rate.can_apply_to_expenses = true
|
@@ -35,4 +36,4 @@ class TaxRateTest < Test::Unit::TestCase
|
|
35
36
|
tax_rate.effective_rate = 12.500
|
36
37
|
end
|
37
38
|
end
|
38
|
-
end
|
39
|
+
end
|
data/xero_gateway.gemspec
CHANGED
@@ -18,7 +18,12 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_dependency "builder", ">= 3.2.2"
|
20
20
|
s.add_dependency "oauth", ">= 0.3.6"
|
21
|
-
|
21
|
+
|
22
|
+
if RUBY_VERSION > "1.9.3"
|
23
|
+
s.add_dependency "activesupport"
|
24
|
+
else
|
25
|
+
s.add_dependency "activesupport", "< 5"
|
26
|
+
end
|
22
27
|
|
23
28
|
s.add_development_dependency "bundler"
|
24
29
|
s.add_development_dependency "rake"
|
@@ -26,6 +31,6 @@ Gem::Specification.new do |s|
|
|
26
31
|
s.add_development_dependency "test-unit"
|
27
32
|
s.add_development_dependency "mocha"
|
28
33
|
s.add_development_dependency "shoulda"
|
29
|
-
s.add_development_dependency "libxml-ruby"
|
34
|
+
s.add_development_dependency "libxml-ruby", "2.7.0"
|
30
35
|
|
31
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xero_gateway
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Connor
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: builder
|
@@ -142,16 +142,16 @@ dependencies:
|
|
142
142
|
name: libxml-ruby
|
143
143
|
requirement: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
|
-
- -
|
145
|
+
- - '='
|
146
146
|
- !ruby/object:Gem::Version
|
147
|
-
version:
|
147
|
+
version: 2.7.0
|
148
148
|
type: :development
|
149
149
|
prerelease: false
|
150
150
|
version_requirements: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
|
-
- -
|
152
|
+
- - '='
|
153
153
|
- !ruby/object:Gem::Version
|
154
|
-
version:
|
154
|
+
version: 2.7.0
|
155
155
|
description: Enables Ruby based applications to communicate with the Xero API
|
156
156
|
email:
|
157
157
|
- me@nikwakelin.com
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- Rakefile
|
167
167
|
- examples/oauth.rb
|
168
168
|
- examples/partner_app.rb
|
169
|
+
- examples/private_app.rb
|
169
170
|
- lib/oauth/oauth_consumer.rb
|
170
171
|
- lib/xero_gateway.rb
|
171
172
|
- lib/xero_gateway/account.rb
|
@@ -269,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
270
|
version: '0'
|
270
271
|
requirements: []
|
271
272
|
rubyforge_project:
|
272
|
-
rubygems_version: 2.
|
273
|
+
rubygems_version: 2.6.11
|
273
274
|
signing_key:
|
274
275
|
specification_version: 4
|
275
276
|
summary: Enables Ruby based applications to communicate with the Xero API
|