xero_gateway 2.0.13 → 2.0.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,18 +18,30 @@ class AccountTest < Test::Unit::TestCase
18
18
  assert_equal account, result_account
19
19
  end
20
20
 
21
+ def test_build_and_parse_xml_for_bank_accounts
22
+ account = create_test_account(:type => 'BANK', :currency_code => 'NZD')
23
+ account_as_xml = account.to_xml
24
+ assert_match 'CurrencyCode', account_as_xml.to_s
25
+
26
+ account_element = REXML::XPath.first(REXML::Document.new(account_as_xml), "/Account")
27
+ result_account = XeroGateway::Account.from_xml(account_element)
28
+ assert_equal 'BANK', result_account.type
29
+ assert_equal 'NZD', result_account.currency_code
30
+ assert_equal account, result_account
31
+ end
21
32
 
22
33
  private
23
34
 
24
- def create_test_account
35
+ def create_test_account(options={})
25
36
  account = XeroGateway::Account.new(:account_id => "57cedda9")
26
37
  account.code = "200"
27
38
  account.name = "Sales"
28
- account.type = "REVENUE"
39
+ account.type = options[:type] || "REVENUE"
29
40
  account.tax_type = "OUTPUT"
30
41
  account.description = "Income from any normal business activity"
31
42
  account.enable_payments_to_account = false
32
-
43
+ account.currency_code = options[:currency_code] if options[:currency_code]
44
+
33
45
  account
34
46
  end
35
47
  end
@@ -0,0 +1,114 @@
1
+ require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
+
3
+ class BankTransactionTest < Test::Unit::TestCase
4
+ include TestHelper
5
+
6
+ context "creating test bank transactions" do
7
+ should "work" do
8
+ bank_transaction = create_test_bank_transaction
9
+
10
+ # test transaction defaults
11
+ assert_equal 'RECEIVE', bank_transaction.type
12
+ assert_kind_of Date, bank_transaction.date
13
+ assert_equal '12345', bank_transaction.reference
14
+ assert_equal 'ACTIVE', bank_transaction.status
15
+
16
+ # Test the contact defaults.
17
+ contact = bank_transaction.contact
18
+ assert_equal '00000000-0000-0000-0000-000000000000', contact.contact_id
19
+ assert_equal 'CONTACT NAME', contact.name
20
+
21
+ # Test address defaults.
22
+ assert_equal 'STREET', contact.address.address_type
23
+ assert_equal 'LINE 1 OF THE ADDRESS', contact.address.line_1
24
+
25
+ # Test phone defaults.
26
+ assert_equal('DEFAULT', contact.phone.phone_type)
27
+ assert_equal('12345678', contact.phone.number)
28
+
29
+ # Test the line_item defaults.
30
+ line_item = bank_transaction.line_items.first
31
+ assert_equal('A LINE ITEM', line_item.description)
32
+ assert_equal('200', line_item.account_code)
33
+ assert_equal(BigDecimal.new('100'), line_item.unit_amount)
34
+ assert_equal(BigDecimal.new('12.5'), line_item.tax_amount)
35
+ end
36
+
37
+ should "allow overriding transaction defaults" do
38
+ assert_equal 'SPEND', create_test_bank_transaction(:type => 'SPEND').type
39
+ end
40
+ end
41
+
42
+ context "adding line items" do
43
+ setup do
44
+ @bank_transaction = create_test_bank_transaction({}, {}, nil) # no line_items
45
+ end
46
+
47
+ should "work" do
48
+ assert_equal(0, @bank_transaction.line_items.size)
49
+
50
+ line_item_params = {:description => "Test Item 1", :unit_amount => 100}
51
+
52
+ # Test adding line item by hash
53
+ line_item = @bank_transaction.add_line_item(line_item_params)
54
+ assert_kind_of(XeroGateway::LineItem, line_item)
55
+ assert_equal(line_item_params[:description], line_item.description)
56
+ assert_equal(line_item_params[:unit_amount], line_item.unit_amount)
57
+ assert_equal(1, @bank_transaction.line_items.size)
58
+
59
+ # Test adding line item by XeroGateway::LineItem
60
+ line_item = @bank_transaction.add_line_item(line_item_params)
61
+ assert_kind_of(XeroGateway::LineItem, line_item)
62
+ assert_equal(line_item_params[:description], line_item.description)
63
+ assert_equal(line_item_params[:unit_amount], line_item.unit_amount)
64
+ assert_equal(2, @bank_transaction.line_items.size)
65
+
66
+ # Test that pushing anything else into add_line_item fails.
67
+ ["invalid", 100, nil, []].each do | invalid_object |
68
+ assert_raise(XeroGateway::Invoice::InvalidLineItemError) { @bank_transaction.add_line_item(invalid_object) }
69
+ assert_equal(2, @bank_transaction.line_items.size)
70
+ end
71
+ end
72
+ end
73
+
74
+
75
+ context "building and parsing XML" do
76
+ should "work vice versa" do
77
+ bank_transaction = create_test_bank_transaction
78
+ bank_transaction_as_xml = bank_transaction.to_xml
79
+ bank_transaction_element = REXML::XPath.first(REXML::Document.new(bank_transaction_as_xml), "/BankTransaction")
80
+
81
+ # checking for mandatory fields
82
+ assert_xml_field bank_transaction_element, 'Type', :value => 'RECEIVE'
83
+ assert_xml_field bank_transaction_element, 'Date'
84
+ assert_xml_field bank_transaction_element, 'Reference', :value => '12345'
85
+ assert_xml_field bank_transaction_element, 'Status', :value => 'ACTIVE'
86
+ assert_xml_field bank_transaction_element, 'Contact', :value => 'CONTACT NAME'
87
+ assert_xml_field bank_transaction_element, 'LineItems', :value => 'A LINE ITEM'
88
+ assert_xml_field bank_transaction_element, 'BankAccount'
89
+
90
+ parsed_bank_transaction = XeroGateway::BankTransaction.from_xml(bank_transaction_element)
91
+ assert_equal(bank_transaction, parsed_bank_transaction)
92
+ end
93
+
94
+ should "work for optional params" do
95
+ bank_transaction = create_test_bank_transaction(:url => 'http://example.com?with=params&and=more')
96
+ bank_transaction_element = REXML::XPath.first(REXML::Document.new(bank_transaction.to_xml), "/BankTransaction")
97
+
98
+ assert_xml_field bank_transaction_element, 'Url', :value => 'http://example.com\?with=params&amp;and=more'
99
+
100
+ parsed_bank_transaction = XeroGateway::BankTransaction.from_xml(bank_transaction_element)
101
+ assert_equal 'http://example.com?with=params&and=more', parsed_bank_transaction.url
102
+ end
103
+ end
104
+
105
+ private
106
+
107
+ def assert_xml_field(xml, field_name, options={})
108
+ assert_match /#{field_name}/, xml.to_s, "Didn't find the field #{field_name} in the XML document!"
109
+ if options[:value]
110
+ assert_match /#{field_name}.*#{options[:value]}.*#{field_name}/, xml.to_s, "The field #{field_name} was expected to be '#{options[:value]}'!"
111
+ end
112
+ end
113
+
114
+ end
@@ -1,39 +1,33 @@
1
1
  require File.join(File.dirname(__FILE__), '../test_helper.rb')
2
2
 
3
3
  class InvoiceTest < Test::Unit::TestCase
4
-
5
- def setup
6
- # @schema = LibXML::XML::Schema.document(LibXML::XML::Document.file(File.join(File.dirname(__FILE__), '../xsd/create_invoice.xsd')))
7
- end
8
4
 
9
- # NB: Xero no longer appears to provide XSDs for their api, check http://blog.xero.com/developer/api/invoices/
10
- #
11
- # Tests that the XML generated from an invoice object validates against the Xero XSD
12
- # def test_build_xml
13
- # invoice = create_test_invoice
14
- #
15
- # message = invoice.to_xml
16
- #
17
- # # Check that the document matches the XSD
18
- # assert LibXML::XML::Parser.string(message).parse.validate_schema(@schema), "The XML document generated did not validate against the XSD"
19
- # end
20
-
21
- # Tests that an invoice can be converted into XML that Xero can understand, and then converted back to an invoice
22
- def test_build_and_parse_xml
23
- invoice = create_test_invoice
24
-
25
- # Generate the XML message
26
- invoice_as_xml = invoice.to_xml
5
+ context "building and parsing XML" do
6
+ should "work vice versa" do
7
+ invoice = create_test_invoice
8
+
9
+ # Generate the XML message
10
+ invoice_as_xml = invoice.to_xml
27
11
 
28
- # Parse the XML message and retrieve the invoice element
29
- invoice_element = REXML::XPath.first(REXML::Document.new(invoice_as_xml), "/Invoice")
12
+ # Parse the XML message and retrieve the invoice element
13
+ invoice_element = REXML::XPath.first(REXML::Document.new(invoice_as_xml), "/Invoice")
30
14
 
31
- # Build a new invoice from the XML
32
- result_invoice = XeroGateway::Invoice.from_xml(invoice_element)
15
+ # Build a new invoice from the XML
16
+ result_invoice = XeroGateway::Invoice.from_xml(invoice_element)
17
+
18
+ assert_equal(invoice, result_invoice)
19
+ end
33
20
 
34
- assert_equal(invoice, result_invoice)
21
+ should "work for optional params" do
22
+ invoice = create_test_invoice(:url => 'http://example.com?with=params&and=more')
23
+ invoice_element = REXML::XPath.first(REXML::Document.new(invoice.to_xml), "/Invoice")
24
+ assert_match /<Url>http:\/\/example.com\?with=params&amp;and=more<\/Url>/, invoice_element.to_s
25
+
26
+ parsed_invoice = XeroGateway::Invoice.from_xml(invoice_element)
27
+ assert_equal 'http://example.com?with=params&and=more', parsed_invoice.url
28
+ end
35
29
  end
36
-
30
+
37
31
  # Tests the sub_total calculation and that setting it manually doesn't modify the data.
38
32
  def test_invoice_sub_total_calculation
39
33
  invoice = create_test_invoice
@@ -174,6 +168,9 @@ class InvoiceTest < Test::Unit::TestCase
174
168
  assert_equal(BigDecimal.new('100'), invoice.line_items.first.unit_amount)
175
169
  assert_equal(BigDecimal.new('12.5'), invoice.line_items.first.tax_amount)
176
170
 
171
+ # Test optional params
172
+ assert_nil invoice.url
173
+
177
174
  # Test overriding an invoice parameter (assume works for all).
178
175
  invoice = create_test_invoice({:invoice_type => 'ACCPAY'})
179
176
  assert_equal('ACCPAY', invoice.invoice_type)
@@ -241,7 +238,12 @@ class InvoiceTest < Test::Unit::TestCase
241
238
  invoice = XeroGateway::Invoice.new
242
239
  assert_equal(invoice.line_amount_types, 'Exclusive')
243
240
  end
244
-
241
+
242
+ def test_optional_params
243
+ invoice = create_test_invoice(:url => 'http://example.com')
244
+ assert_equal 'http://example.com', invoice.url
245
+ end
246
+
245
247
  private
246
248
 
247
249
  def create_test_invoice(invoice_params = {}, contact_params = {}, line_item_params = [])
@@ -304,4 +306,21 @@ class InvoiceTest < Test::Unit::TestCase
304
306
 
305
307
  invoice
306
308
  end
309
+
310
+ # NB: Xero no longer appears to provide XSDs for their api, check http://blog.xero.com/developer/api/invoices/
311
+ #
312
+ # context "validating against the Xero XSD" do
313
+ # setup do
314
+ # # @schema = LibXML::XML::Schema.document(LibXML::XML::Document.file(File.join(File.dirname(__FILE__), '../xsd/create_invoice.xsd')))
315
+ # end
316
+ #
317
+ # should "succeed" do
318
+ # invoice = create_test_invoice
319
+ # message = invoice.to_xml
320
+ #
321
+ # # Check that the document matches the XSD
322
+ # assert LibXML::XML::Parser.string(message).parse.validate_schema(@schema), "The XML document generated did not validate against the XSD"
323
+ # end
324
+ # end
325
+
307
326
  end
@@ -42,12 +42,16 @@ class OAuthTest < Test::Unit::TestCase
42
42
  xero = XeroGateway::OAuth.new('token', 'secret')
43
43
  consumer = OAuth::Consumer.new('token', 'secret')
44
44
  xero.stubs(:consumer).returns(consumer)
45
-
46
- access_token = mock('access token', :token => 'atoken', :secret => 'asecret')
45
+
46
+ access_token = mock('access token')
47
+ access_token.expects(:token).twice.returns('atoken')
48
+ access_token.expects(:secret).twice.returns('asecret')
49
+ access_token.stubs(:params).returns({})
50
+
47
51
  request_token = mock('request token')
48
52
  request_token.expects(:get_access_token).returns(access_token)
49
53
  OAuth::RequestToken.expects(:new).with(consumer, 'rtoken', 'rsecret').returns(request_token)
50
-
54
+
51
55
  xero.authorize_from_request('rtoken', 'rsecret')
52
56
  assert xero.access_token.is_a? OAuth::AccessToken
53
57
  assert_equal "atoken", xero.access_token.token
@@ -81,9 +85,14 @@ class OAuthTest < Test::Unit::TestCase
81
85
  consumer = OAuth::Consumer.new('token', 'secret')
82
86
  xero.stubs(:consumer).returns(consumer)
83
87
 
84
- access_token = mock('access token', :token => 'atoken', :secret => 'asecret')
88
+ access_token = mock('access token')
89
+ access_token.expects(:token).twice.returns('atoken')
90
+ access_token.expects(:secret).twice.returns('asecret')
91
+ access_token.stubs(:params).returns({})
92
+
85
93
  request_token = mock('request token')
86
94
  request_token.expects(:get_access_token).with(:oauth_verifier => "verifier").returns(access_token)
95
+
87
96
  OAuth::RequestToken.expects(:new).with(consumer, 'rtoken', 'rsecret').returns(request_token)
88
97
 
89
98
  xero.authorize_from_request('rtoken', 'rsecret', :oauth_verifier => "verifier")
data/xero_gateway.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "xero_gateway"
3
- s.version = "2.0.13"
4
- s.date = "2011-09-14"
3
+ s.version = "2.0.14"
4
+ s.date = "2012-05-07"
5
5
  s.summary = "Enables ruby based applications to communicate with the Xero API"
6
6
  s.email = "tim@connorsoftware.com"
7
7
  s.homepage = "http://github.com/tlconnor/xero_gateway"
metadata CHANGED
@@ -1,79 +1,56 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: xero_gateway
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.14
5
5
  prerelease:
6
- segments:
7
- - 2
8
- - 0
9
- - 13
10
- version: 2.0.13
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Tim Connor
14
9
  - Nik Wakelin
15
10
  autorequire:
16
11
  bindir: bin
17
12
  cert_chain: []
18
-
19
- date: 2011-09-14 00:00:00 +12:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
13
+ date: 2012-05-07 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
23
16
  name: builder
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70356902601560 !ruby/object:Gem::Requirement
26
18
  none: false
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- hash: 15
31
- segments:
32
- - 2
33
- - 1
34
- - 2
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
35
22
  version: 2.1.2
36
23
  type: :runtime
37
- version_requirements: *id001
38
- - !ruby/object:Gem::Dependency
39
- name: oauth
40
24
  prerelease: false
41
- requirement: &id002 !ruby/object:Gem::Requirement
25
+ version_requirements: *70356902601560
26
+ - !ruby/object:Gem::Dependency
27
+ name: oauth
28
+ requirement: &70356902601080 !ruby/object:Gem::Requirement
42
29
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 31
47
- segments:
48
- - 0
49
- - 3
50
- - 6
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
51
33
  version: 0.3.6
52
34
  type: :runtime
53
- version_requirements: *id002
54
- - !ruby/object:Gem::Dependency
55
- name: activesupport
56
35
  prerelease: false
57
- requirement: &id003 !ruby/object:Gem::Requirement
36
+ version_requirements: *70356902601080
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
39
+ requirement: &70356902600700 !ruby/object:Gem::Requirement
58
40
  none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
- version: "0"
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
66
45
  type: :runtime
67
- version_requirements: *id003
46
+ prerelease: false
47
+ version_requirements: *70356902600700
68
48
  description: Enables ruby based applications to communicate with the Xero API
69
49
  email: tim@connorsoftware.com
70
50
  executables: []
71
-
72
51
  extensions: []
73
-
74
52
  extra_rdoc_files: []
75
-
76
- files:
53
+ files:
77
54
  - Gemfile
78
55
  - LICENSE
79
56
  - Rakefile
@@ -86,6 +63,7 @@ files:
86
63
  - lib/xero_gateway/account.rb
87
64
  - lib/xero_gateway/accounts_list.rb
88
65
  - lib/xero_gateway/address.rb
66
+ - lib/xero_gateway/bank_transaction.rb
89
67
  - lib/xero_gateway/contact.rb
90
68
  - lib/xero_gateway/credit_note.rb
91
69
  - lib/xero_gateway/currency.rb
@@ -97,6 +75,7 @@ files:
97
75
  - lib/xero_gateway/http_encoding_helper.rb
98
76
  - lib/xero_gateway/invoice.rb
99
77
  - lib/xero_gateway/line_item.rb
78
+ - lib/xero_gateway/line_item_calculations.rb
100
79
  - lib/xero_gateway/money.rb
101
80
  - lib/xero_gateway/oauth.rb
102
81
  - lib/xero_gateway/organisation.rb
@@ -109,10 +88,13 @@ files:
109
88
  - lib/xero_gateway/tracking_category.rb
110
89
  - lib/xero_gateway.rb
111
90
  - test/integration/accounts_list_test.rb
91
+ - test/integration/create_bank_transaction_test.rb
112
92
  - test/integration/create_contact_test.rb
113
93
  - test/integration/create_credit_note_test.rb
114
94
  - test/integration/create_invoice_test.rb
115
95
  - test/integration/get_accounts_test.rb
96
+ - test/integration/get_bank_transaction_test.rb
97
+ - test/integration/get_bank_transactions_test.rb
116
98
  - test/integration/get_contact_test.rb
117
99
  - test/integration/get_contacts_test.rb
118
100
  - test/integration/get_credit_note_test.rb
@@ -123,10 +105,12 @@ files:
123
105
  - test/integration/get_organisation_test.rb
124
106
  - test/integration/get_tax_rates_test.rb
125
107
  - test/integration/get_tracking_categories_test.rb
108
+ - test/integration/update_bank_transaction_test.rb
126
109
  - test/integration/update_contact_test.rb
127
110
  - test/integration/update_invoice_test.rb
128
111
  - test/test_helper.rb
129
112
  - test/unit/account_test.rb
113
+ - test/unit/bank_transaction_test.rb
130
114
  - test/unit/contact_test.rb
131
115
  - test/unit/credit_note_test.rb
132
116
  - test/unit/currency_test.rb
@@ -137,39 +121,28 @@ files:
137
121
  - test/unit/tax_rate_test.rb
138
122
  - test/unit/tracking_category_test.rb
139
123
  - lib/xero_gateway/ca-certificates.crt
140
- has_rdoc: true
141
124
  homepage: http://github.com/tlconnor/xero_gateway
142
125
  licenses: []
143
-
144
126
  post_install_message:
145
127
  rdoc_options: []
146
-
147
- require_paths:
128
+ require_paths:
148
129
  - lib
149
- required_ruby_version: !ruby/object:Gem::Requirement
130
+ required_ruby_version: !ruby/object:Gem::Requirement
150
131
  none: false
151
- requirements:
152
- - - ">="
153
- - !ruby/object:Gem::Version
154
- hash: 3
155
- segments:
156
- - 0
157
- version: "0"
158
- required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ! '>='
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
137
  none: false
160
- requirements:
161
- - - ">="
162
- - !ruby/object:Gem::Version
163
- hash: 3
164
- segments:
165
- - 0
166
- version: "0"
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
167
142
  requirements: []
168
-
169
143
  rubyforge_project:
170
- rubygems_version: 1.6.2
144
+ rubygems_version: 1.8.10
171
145
  signing_key:
172
146
  specification_version: 3
173
147
  summary: Enables ruby based applications to communicate with the Xero API
174
148
  test_files: []
175
-