xero_gateway-n8vision 2.0.20
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.
- data/Gemfile +12 -0
 - data/LICENSE +14 -0
 - data/README.textile +357 -0
 - data/Rakefile +14 -0
 - data/examples/oauth.rb +25 -0
 - data/examples/partner_app.rb +36 -0
 - data/init.rb +1 -0
 - data/lib/oauth/oauth_consumer.rb +14 -0
 - data/lib/xero_gateway.rb +41 -0
 - data/lib/xero_gateway/account.rb +86 -0
 - data/lib/xero_gateway/accounts_list.rb +73 -0
 - data/lib/xero_gateway/address.rb +96 -0
 - data/lib/xero_gateway/bank_transaction.rb +175 -0
 - data/lib/xero_gateway/ca-certificates.crt +2560 -0
 - data/lib/xero_gateway/contact.rb +203 -0
 - data/lib/xero_gateway/credit_note.rb +220 -0
 - data/lib/xero_gateway/currency.rb +56 -0
 - data/lib/xero_gateway/dates.rb +25 -0
 - data/lib/xero_gateway/error.rb +18 -0
 - data/lib/xero_gateway/exceptions.rb +51 -0
 - data/lib/xero_gateway/gateway.rb +698 -0
 - data/lib/xero_gateway/http.rb +135 -0
 - data/lib/xero_gateway/http_encoding_helper.rb +49 -0
 - data/lib/xero_gateway/invoice.rb +238 -0
 - data/lib/xero_gateway/journal_line.rb +102 -0
 - data/lib/xero_gateway/line_item.rb +125 -0
 - data/lib/xero_gateway/line_item_calculations.rb +51 -0
 - data/lib/xero_gateway/manual_journal.rb +163 -0
 - data/lib/xero_gateway/money.rb +16 -0
 - data/lib/xero_gateway/oauth.rb +92 -0
 - data/lib/xero_gateway/organisation.rb +75 -0
 - data/lib/xero_gateway/partner_app.rb +30 -0
 - data/lib/xero_gateway/payment.rb +43 -0
 - data/lib/xero_gateway/phone.rb +77 -0
 - data/lib/xero_gateway/private_app.rb +17 -0
 - data/lib/xero_gateway/response.rb +43 -0
 - data/lib/xero_gateway/tax_rate.rb +63 -0
 - data/lib/xero_gateway/tracking_category.rb +87 -0
 - data/test/integration/accounts_list_test.rb +109 -0
 - data/test/integration/create_bank_transaction_test.rb +38 -0
 - data/test/integration/create_contact_test.rb +66 -0
 - data/test/integration/create_credit_note_test.rb +49 -0
 - data/test/integration/create_invoice_test.rb +49 -0
 - data/test/integration/create_manual_journal_test.rb +35 -0
 - data/test/integration/get_accounts_test.rb +23 -0
 - data/test/integration/get_bank_transaction_test.rb +51 -0
 - data/test/integration/get_bank_transactions_test.rb +88 -0
 - data/test/integration/get_contact_test.rb +28 -0
 - data/test/integration/get_contacts_test.rb +40 -0
 - data/test/integration/get_credit_note_test.rb +48 -0
 - data/test/integration/get_credit_notes_test.rb +90 -0
 - data/test/integration/get_currencies_test.rb +25 -0
 - data/test/integration/get_invoice_test.rb +48 -0
 - data/test/integration/get_invoices_test.rb +92 -0
 - data/test/integration/get_manual_journal_test.rb +50 -0
 - data/test/integration/get_manual_journals_test.rb +88 -0
 - data/test/integration/get_organisation_test.rb +24 -0
 - data/test/integration/get_tax_rates_test.rb +25 -0
 - data/test/integration/get_tracking_categories_test.rb +27 -0
 - data/test/integration/update_bank_transaction_test.rb +31 -0
 - data/test/integration/update_contact_test.rb +31 -0
 - data/test/integration/update_invoice_test.rb +31 -0
 - data/test/integration/update_manual_journal_test.rb +31 -0
 - data/test/test_helper.rb +217 -0
 - data/test/unit/account_test.rb +47 -0
 - data/test/unit/bank_transaction_test.rb +126 -0
 - data/test/unit/contact_test.rb +97 -0
 - data/test/unit/credit_note_test.rb +284 -0
 - data/test/unit/currency_test.rb +31 -0
 - data/test/unit/gateway_test.rb +119 -0
 - data/test/unit/invoice_test.rb +326 -0
 - data/test/unit/manual_journal_test.rb +93 -0
 - data/test/unit/oauth_test.rb +116 -0
 - data/test/unit/organisation_test.rb +38 -0
 - data/test/unit/tax_rate_test.rb +38 -0
 - data/test/unit/tracking_category_test.rb +52 -0
 - data/xero_gateway-n8vision.gemspec +15 -0
 - metadata +178 -0
 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class GetOrganisationTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              include TestHelper
         
     | 
| 
      
 5 
     | 
    
         
            +
              
         
     | 
| 
      
 6 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 7 
     | 
    
         
            +
                @gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
         
     | 
| 
      
 8 
     | 
    
         
            +
                
         
     | 
| 
      
 9 
     | 
    
         
            +
                if STUB_XERO_CALLS
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @gateway.xero_url = "DUMMY_URL"
         
     | 
| 
      
 11 
     | 
    
         
            +
                  
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @gateway.stubs(:http_get).with {|client, url, params| url =~ /Organisation$/ }.returns(get_file_as_string("organisation.xml"))          
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
              
         
     | 
| 
      
 16 
     | 
    
         
            +
              def test_get_organisation
         
     | 
| 
      
 17 
     | 
    
         
            +
                result = @gateway.get_organisation
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert result.success?
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert !result.response_xml.nil?
         
     | 
| 
      
 20 
     | 
    
         
            +
                
         
     | 
| 
      
 21 
     | 
    
         
            +
                assert_equal XeroGateway::Organisation, result.organisation.class
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert_equal "Demo Company (NZ)", result.organisation.name
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,25 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class GetTaxRatesTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              include TestHelper
         
     | 
| 
      
 5 
     | 
    
         
            +
              
         
     | 
| 
      
 6 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 7 
     | 
    
         
            +
                @gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
         
     | 
| 
      
 8 
     | 
    
         
            +
                
         
     | 
| 
      
 9 
     | 
    
         
            +
                if STUB_XERO_CALLS
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @gateway.xero_url = "DUMMY_URL"
         
     | 
| 
      
 11 
     | 
    
         
            +
                  
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @gateway.stubs(:http_get).with {|client, url, params| url =~ /TaxRates$/ }.returns(get_file_as_string("tax_rates.xml"))          
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
              
         
     | 
| 
      
 16 
     | 
    
         
            +
              def test_get_tax_rates
         
     | 
| 
      
 17 
     | 
    
         
            +
                result = @gateway.get_tax_rates
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert result.success?
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert !result.response_xml.nil?
         
     | 
| 
      
 20 
     | 
    
         
            +
                
         
     | 
| 
      
 21 
     | 
    
         
            +
                assert result.tax_rates.size > 0
         
     | 
| 
      
 22 
     | 
    
         
            +
                assert_equal XeroGateway::TaxRate, result.tax_rates.first.class
         
     | 
| 
      
 23 
     | 
    
         
            +
                assert_equal "GST on Expenses", result.tax_rates.first.name
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class GetTrackingCategoriesTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              include TestHelper
         
     | 
| 
      
 5 
     | 
    
         
            +
              
         
     | 
| 
      
 6 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 7 
     | 
    
         
            +
                @gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                if STUB_XERO_CALLS
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @gateway.xero_url = "DUMMY_URL"
         
     | 
| 
      
 11 
     | 
    
         
            +
                  
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @gateway.stubs(:http_get).with {|client, url, params| url =~ /TrackingCategories$/ }.returns(get_file_as_string("tracking_categories.xml"))          
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
              end
         
     | 
| 
      
 15 
     | 
    
         
            +
              
         
     | 
| 
      
 16 
     | 
    
         
            +
              def test_get_tracking_categories
         
     | 
| 
      
 17 
     | 
    
         
            +
                result = @gateway.get_tracking_categories
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert result.success?
         
     | 
| 
      
 19 
     | 
    
         
            +
                assert !result.response_xml.nil?
         
     | 
| 
      
 20 
     | 
    
         
            +
                if STUB_XERO_CALLS
         
     | 
| 
      
 21 
     | 
    
         
            +
                  # When operating against the Xero test environment, there may not be any tracking categories present,
         
     | 
| 
      
 22 
     | 
    
         
            +
                  # so this assertion can only be done when operating against stub responses
         
     | 
| 
      
 23 
     | 
    
         
            +
                  assert_equal 1, result.tracking_categories.size
         
     | 
| 
      
 24 
     | 
    
         
            +
                  assert_equal 4, result.tracking_categories.first.options.size
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
              end
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class UpdateBankTransactionTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              include TestHelper
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 7 
     | 
    
         
            +
                @gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                if STUB_XERO_CALLS
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @gateway.xero_url = "DUMMY_URL"
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  @gateway.stubs(:http_put).with {|client, url, body, params| url =~ /BankTransactions$/ }.returns(get_file_as_string("create_bank_transaction.xml"))
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @gateway.stubs(:http_post).with {|client, url, body, params| url =~ /BankTransactions$/ }.returns(get_file_as_string("bank_transaction.xml"))
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              def test_update_bank_transaction
         
     | 
| 
      
 18 
     | 
    
         
            +
                bank_transaction = @gateway.create_bank_transaction(create_test_bank_transaction).bank_transaction
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                today = Date.today
         
     | 
| 
      
 21 
     | 
    
         
            +
                bank_transaction.date = today
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                result = @gateway.update_bank_transaction(bank_transaction)
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                assert result.success?
         
     | 
| 
      
 26 
     | 
    
         
            +
                assert !result.request_xml.nil?
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert !result.response_xml.nil?
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal bank_transaction.bank_transaction_id, result.bank_transaction.bank_transaction_id
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert_equal today, result.bank_transaction.date if !STUB_XERO_CALLS
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class UpdateContactTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              include TestHelper
         
     | 
| 
      
 5 
     | 
    
         
            +
              
         
     | 
| 
      
 6 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 7 
     | 
    
         
            +
                @gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
         
     | 
| 
      
 8 
     | 
    
         
            +
                
         
     | 
| 
      
 9 
     | 
    
         
            +
                if STUB_XERO_CALLS
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @gateway.xero_url = "DUMMY_URL"
         
     | 
| 
      
 11 
     | 
    
         
            +
                  
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @gateway.stubs(:http_put).with {|client, url, body, params| url =~ /Contacts$/ }.returns(get_file_as_string("contact.xml"))          
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @gateway.stubs(:http_post).with {|client, url, body, params| url =~ /Contacts$/ }.returns(get_file_as_string("contact.xml"))          
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
              
         
     | 
| 
      
 17 
     | 
    
         
            +
              def test_update_contact
         
     | 
| 
      
 18 
     | 
    
         
            +
                # Make sure there is a contact in Xero to retrieve
         
     | 
| 
      
 19 
     | 
    
         
            +
                contact = @gateway.create_contact(dummy_contact).contact
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                contact.phone.number = "123 4567"
         
     | 
| 
      
 22 
     | 
    
         
            +
                
         
     | 
| 
      
 23 
     | 
    
         
            +
                result = @gateway.update_contact(contact)
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                assert result.success?
         
     | 
| 
      
 26 
     | 
    
         
            +
                assert !result.request_xml.nil?
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert !result.response_xml.nil?    
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal contact.contact_id, result.contact.contact_id
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert_equal "123 4567", result.contact.phone.number if !STUB_XERO_CALLS
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class UpdateInvoiceTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              include TestHelper
         
     | 
| 
      
 5 
     | 
    
         
            +
              
         
     | 
| 
      
 6 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 7 
     | 
    
         
            +
                @gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
         
     | 
| 
      
 8 
     | 
    
         
            +
                
         
     | 
| 
      
 9 
     | 
    
         
            +
                if STUB_XERO_CALLS
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @gateway.xero_url = "DUMMY_URL"
         
     | 
| 
      
 11 
     | 
    
         
            +
                  
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @gateway.stubs(:http_put).with {|client, url, body, params| url =~ /Invoices$/ }.returns(get_file_as_string("create_invoice.xml"))          
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @gateway.stubs(:http_post).with {|client, url, body, params| url =~ /Invoices$/ }.returns(get_file_as_string("invoice.xml"))          
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
              
         
     | 
| 
      
 17 
     | 
    
         
            +
              def test_update_invoice
         
     | 
| 
      
 18 
     | 
    
         
            +
                invoice = @gateway.create_invoice(dummy_invoice).invoice
         
     | 
| 
      
 19 
     | 
    
         
            +
                
         
     | 
| 
      
 20 
     | 
    
         
            +
                today = Date.today
         
     | 
| 
      
 21 
     | 
    
         
            +
                invoice.due_date = today
         
     | 
| 
      
 22 
     | 
    
         
            +
                
         
     | 
| 
      
 23 
     | 
    
         
            +
                result = @gateway.update_invoice(invoice)
         
     | 
| 
      
 24 
     | 
    
         
            +
                
         
     | 
| 
      
 25 
     | 
    
         
            +
                assert result.success?
         
     | 
| 
      
 26 
     | 
    
         
            +
                assert !result.request_xml.nil?
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert !result.response_xml.nil?    
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal invoice.invoice_id, result.invoice.invoice_id
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert_equal today, result.invoice.due_date if !STUB_XERO_CALLS
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,31 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../test_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class UpdateManualJournalTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              include TestHelper
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              def setup
         
     | 
| 
      
 7 
     | 
    
         
            +
                @gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                if STUB_XERO_CALLS
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @gateway.xero_url = "DUMMY_URL"
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  @gateway.stubs(:http_put).with {|client, url, body, params| url =~ /ManualJournals$/ }.returns(get_file_as_string("create_manual_journal.xml"))
         
     | 
| 
      
 13 
     | 
    
         
            +
                  @gateway.stubs(:http_post).with {|client, url, body, params| url =~ /ManualJournals$/ }.returns(get_file_as_string("manual_journal.xml"))
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              def test_update_manual_journal
         
     | 
| 
      
 18 
     | 
    
         
            +
                manual_journal = @gateway.create_manual_journal(create_test_manual_journal).manual_journal
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                today = Date.today
         
     | 
| 
      
 21 
     | 
    
         
            +
                manual_journal.date = today
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                result = @gateway.update_manual_journal(manual_journal)
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                assert result.success?
         
     | 
| 
      
 26 
     | 
    
         
            +
                assert !result.request_xml.nil?
         
     | 
| 
      
 27 
     | 
    
         
            +
                assert !result.response_xml.nil?
         
     | 
| 
      
 28 
     | 
    
         
            +
                assert_equal manual_journal.manual_journal_id, result.manual_journal.manual_journal_id
         
     | 
| 
      
 29 
     | 
    
         
            +
                assert_equal today, result.manual_journal.date if !STUB_XERO_CALLS
         
     | 
| 
      
 30 
     | 
    
         
            +
              end
         
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
    
        data/test/test_helper.rb
    ADDED
    
    | 
         @@ -0,0 +1,217 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require "rubygems"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'mocha'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'shoulda'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            require 'libxml'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            require File.dirname(__FILE__) + '/../lib/xero_gateway.rb' unless defined?(XeroGateway)
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            module TestHelper
         
     | 
| 
      
 12 
     | 
    
         
            +
              # The integration tests can be run against the Xero test environment.  You mush have a company set up in the test
         
     | 
| 
      
 13 
     | 
    
         
            +
              # environment, and you must have set up a customer key for that account.
         
     | 
| 
      
 14 
     | 
    
         
            +
              #
         
     | 
| 
      
 15 
     | 
    
         
            +
              # You can then run the tests against the test environment using the commands (linux or mac):
         
     | 
| 
      
 16 
     | 
    
         
            +
              # export STUB_XERO_CALLS=false  
         
     | 
| 
      
 17 
     | 
    
         
            +
              # rake test
         
     | 
| 
      
 18 
     | 
    
         
            +
              # (this probably won't work under OAuth?)
         
     | 
| 
      
 19 
     | 
    
         
            +
              #
         
     | 
| 
      
 20 
     | 
    
         
            +
              
         
     | 
| 
      
 21 
     | 
    
         
            +
              STUB_XERO_CALLS = ENV["STUB_XERO_CALLS"].nil? ? true : (ENV["STUB_XERO_CALLS"] == "true") unless defined? STUB_XERO_CALLS
         
     | 
| 
      
 22 
     | 
    
         
            +
              
         
     | 
| 
      
 23 
     | 
    
         
            +
              CONSUMER_KEY    = ENV["CONSUMER_KEY"]    || "fake_key"    unless defined?(CONSUMER_KEY)
         
     | 
| 
      
 24 
     | 
    
         
            +
              CONSUMER_SECRET = ENV["CONSUMER_SECRET"] || "fake_secret" unless defined?(CONSUMER_SECRET)
         
     | 
| 
      
 25 
     | 
    
         
            +
              
         
     | 
| 
      
 26 
     | 
    
         
            +
              # Helper constant for checking regex
         
     | 
| 
      
 27 
     | 
    
         
            +
              GUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ unless defined?(GUID_REGEX)
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              
         
     | 
| 
      
 30 
     | 
    
         
            +
              def dummy_invoice(with_line_items = true)
         
     | 
| 
      
 31 
     | 
    
         
            +
                 invoice = XeroGateway::Invoice.new({
         
     | 
| 
      
 32 
     | 
    
         
            +
                   :invoice_type => "ACCREC",
         
     | 
| 
      
 33 
     | 
    
         
            +
                   :date => Time.now,
         
     | 
| 
      
 34 
     | 
    
         
            +
                   :due_date => Date.today + 20,
         
     | 
| 
      
 35 
     | 
    
         
            +
                   :invoice_number => STUB_XERO_CALLS ? "INV-0001" : "#{Time.now.to_f}",
         
     | 
| 
      
 36 
     | 
    
         
            +
                   :reference => "YOUR REFERENCE (NOT NECESSARILY UNIQUE!)",
         
     | 
| 
      
 37 
     | 
    
         
            +
                   :line_items_downloaded => with_line_items
         
     | 
| 
      
 38 
     | 
    
         
            +
                 })
         
     | 
| 
      
 39 
     | 
    
         
            +
                 invoice.contact = dummy_contact
         
     | 
| 
      
 40 
     | 
    
         
            +
                 if with_line_items
         
     | 
| 
      
 41 
     | 
    
         
            +
                   invoice.line_items << XeroGateway::LineItem.new(
         
     | 
| 
      
 42 
     | 
    
         
            +
                     :description => "THE DESCRIPTION OF THE LINE ITEM",
         
     | 
| 
      
 43 
     | 
    
         
            +
                     :unit_amount => 1000,
         
     | 
| 
      
 44 
     | 
    
         
            +
                     :tax_amount => 125,
         
     | 
| 
      
 45 
     | 
    
         
            +
                     :tracking => [
         
     | 
| 
      
 46 
     | 
    
         
            +
                        XeroGateway::TrackingCategory.new(:name => "THE FIRST  TRACKING CATEGORY FOR THE LINE ITEM", :options => ["a", "b"]),
         
     | 
| 
      
 47 
     | 
    
         
            +
                        XeroGateway::TrackingCategory.new(:name => "THE SECOND TRACKING CATEGORY FOR THE LINE ITEM", :options => "c")
         
     | 
| 
      
 48 
     | 
    
         
            +
                     ]
         
     | 
| 
      
 49 
     | 
    
         
            +
                   )
         
     | 
| 
      
 50 
     | 
    
         
            +
                 end
         
     | 
| 
      
 51 
     | 
    
         
            +
                 invoice
         
     | 
| 
      
 52 
     | 
    
         
            +
              end
         
     | 
| 
      
 53 
     | 
    
         
            +
                  
         
     | 
| 
      
 54 
     | 
    
         
            +
              def dummy_credit_note(with_line_items = true)
         
     | 
| 
      
 55 
     | 
    
         
            +
                 credit_note = XeroGateway::CreditNote.new({
         
     | 
| 
      
 56 
     | 
    
         
            +
                   :type => "ACCRECCREDIT",
         
     | 
| 
      
 57 
     | 
    
         
            +
                   :date => Time.now,
         
     | 
| 
      
 58 
     | 
    
         
            +
                   :credit_note_number => STUB_XERO_CALLS ? "CN-0153" : "#{Time.now.to_f}",
         
     | 
| 
      
 59 
     | 
    
         
            +
                   :reference => "YOUR REFERENCE (NOT NECESSARILY UNIQUE!)",
         
     | 
| 
      
 60 
     | 
    
         
            +
                   :line_items_downloaded => with_line_items
         
     | 
| 
      
 61 
     | 
    
         
            +
                 })
         
     | 
| 
      
 62 
     | 
    
         
            +
                 credit_note.contact = dummy_contact
         
     | 
| 
      
 63 
     | 
    
         
            +
                 if with_line_items
         
     | 
| 
      
 64 
     | 
    
         
            +
                   credit_note.line_items << XeroGateway::LineItem.new(
         
     | 
| 
      
 65 
     | 
    
         
            +
                     :description => "THE DESCRIPTION OF THE LINE ITEM",
         
     | 
| 
      
 66 
     | 
    
         
            +
                     :unit_amount => 1000,
         
     | 
| 
      
 67 
     | 
    
         
            +
                     :tax_amount => 125,
         
     | 
| 
      
 68 
     | 
    
         
            +
                     :tracking => [
         
     | 
| 
      
 69 
     | 
    
         
            +
                        XeroGateway::TrackingCategory.new(:name => "THE FIRST  TRACKING CATEGORY FOR THE LINE ITEM", :options => ["a", "b"]),
         
     | 
| 
      
 70 
     | 
    
         
            +
                        XeroGateway::TrackingCategory.new(:name => "THE SECOND TRACKING CATEGORY FOR THE LINE ITEM", :options => "c")
         
     | 
| 
      
 71 
     | 
    
         
            +
                     ]
         
     | 
| 
      
 72 
     | 
    
         
            +
                   )
         
     | 
| 
      
 73 
     | 
    
         
            +
                 end
         
     | 
| 
      
 74 
     | 
    
         
            +
                 credit_note
         
     | 
| 
      
 75 
     | 
    
         
            +
              end
         
     | 
| 
      
 76 
     | 
    
         
            +
                  
         
     | 
| 
      
 77 
     | 
    
         
            +
              def dummy_contact
         
     | 
| 
      
 78 
     | 
    
         
            +
                unique_id = Time.now.to_f
         
     | 
| 
      
 79 
     | 
    
         
            +
                contact = XeroGateway::Contact.new(:name => STUB_XERO_CALLS ? "CONTACT NAME" : "THE NAME OF THE CONTACT #{unique_id}")
         
     | 
| 
      
 80 
     | 
    
         
            +
                contact.email = "bob#{unique_id}@example.com"
         
     | 
| 
      
 81 
     | 
    
         
            +
                contact.phone.number = "12345"
         
     | 
| 
      
 82 
     | 
    
         
            +
                contact.address.line_1 = "LINE 1 OF THE ADDRESS"
         
     | 
| 
      
 83 
     | 
    
         
            +
                contact.address.line_2 = "LINE 2 OF THE ADDRESS"
         
     | 
| 
      
 84 
     | 
    
         
            +
                contact.address.line_3 = "LINE 3 OF THE ADDRESS"
         
     | 
| 
      
 85 
     | 
    
         
            +
                contact.address.line_4 = "LINE 4 OF THE ADDRESS"
         
     | 
| 
      
 86 
     | 
    
         
            +
                contact.address.city = "WELLINGTON"
         
     | 
| 
      
 87 
     | 
    
         
            +
                contact.address.region = "WELLINGTON"
         
     | 
| 
      
 88 
     | 
    
         
            +
                contact.address.country = "NEW ZEALAND"
         
     | 
| 
      
 89 
     | 
    
         
            +
                contact.address.post_code = "6021"
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                contact
         
     | 
| 
      
 92 
     | 
    
         
            +
              end
         
     | 
| 
      
 93 
     | 
    
         
            +
              
         
     | 
| 
      
 94 
     | 
    
         
            +
              def get_file_as_string(filename)
         
     | 
| 
      
 95 
     | 
    
         
            +
                data = ''
         
     | 
| 
      
 96 
     | 
    
         
            +
                f = File.open(File.dirname(__FILE__) + "/stub_responses/" + filename, "r") 
         
     | 
| 
      
 97 
     | 
    
         
            +
                f.each_line do |line|
         
     | 
| 
      
 98 
     | 
    
         
            +
                  data += line
         
     | 
| 
      
 99 
     | 
    
         
            +
                end
         
     | 
| 
      
 100 
     | 
    
         
            +
                f.close
         
     | 
| 
      
 101 
     | 
    
         
            +
                return data
         
     | 
| 
      
 102 
     | 
    
         
            +
              end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
              def create_test_bank_transaction(params={}, contact_params={}, line_item_params={})
         
     | 
| 
      
 105 
     | 
    
         
            +
                params = {
         
     | 
| 
      
 106 
     | 
    
         
            +
                  :type       => 'RECEIVE',
         
     | 
| 
      
 107 
     | 
    
         
            +
                  :date       => Date.today,
         
     | 
| 
      
 108 
     | 
    
         
            +
                  :reference  => '12345',
         
     | 
| 
      
 109 
     | 
    
         
            +
                  :status     => 'ACTIVE',
         
     | 
| 
      
 110 
     | 
    
         
            +
                }.merge(params)
         
     | 
| 
      
 111 
     | 
    
         
            +
                bank_transaction = XeroGateway::BankTransaction.new(params)
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                bank_transaction.contact = create_test_contact(contact_params)
         
     | 
| 
      
 114 
     | 
    
         
            +
                add_test_line_items(bank_transaction, line_item_params)
         
     | 
| 
      
 115 
     | 
    
         
            +
                bank_transaction.bank_account = create_test_account
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
                bank_transaction
         
     | 
| 
      
 118 
     | 
    
         
            +
              end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
              def add_test_line_items(bank_transaction, line_item_params={})
         
     | 
| 
      
 121 
     | 
    
         
            +
                if line_item_params
         
     | 
| 
      
 122 
     | 
    
         
            +
                  line_item_params = [line_item_params].flatten # always use an array, even if only a single hash passed in
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
                  # At least one line item, make first have some defaults.
         
     | 
| 
      
 125 
     | 
    
         
            +
                  line_item_params << {} if line_item_params.size == 0
         
     | 
| 
      
 126 
     | 
    
         
            +
                  line_item_params[0] = {
         
     | 
| 
      
 127 
     | 
    
         
            +
                    :description  => "A LINE ITEM",
         
     | 
| 
      
 128 
     | 
    
         
            +
                    :account_code => "200",
         
     | 
| 
      
 129 
     | 
    
         
            +
                    :unit_amount  => BigDecimal.new("100"),
         
     | 
| 
      
 130 
     | 
    
         
            +
                    :tax_amount   => BigDecimal.new("12.5"),
         
     | 
| 
      
 131 
     | 
    
         
            +
                    :tracking     => XeroGateway::TrackingCategory.new(:name => "blah", :options => "hello")
         
     | 
| 
      
 132 
     | 
    
         
            +
                  }.merge(line_item_params[0])
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
                  # Create line_items from line_item_params
         
     | 
| 
      
 135 
     | 
    
         
            +
                  line_item_params.each do |line_item|
         
     | 
| 
      
 136 
     | 
    
         
            +
                    bank_transaction.add_line_item(line_item)
         
     | 
| 
      
 137 
     | 
    
         
            +
                  end
         
     | 
| 
      
 138 
     | 
    
         
            +
                end
         
     | 
| 
      
 139 
     | 
    
         
            +
                bank_transaction
         
     | 
| 
      
 140 
     | 
    
         
            +
              end
         
     | 
| 
      
 141 
     | 
    
         
            +
             
     | 
| 
      
 142 
     | 
    
         
            +
              def create_test_account
         
     | 
| 
      
 143 
     | 
    
         
            +
                account = XeroGateway::Account.new(:account_id => "57cedda9")
         
     | 
| 
      
 144 
     | 
    
         
            +
                account.code = "200"
         
     | 
| 
      
 145 
     | 
    
         
            +
                account.name = "Sales"
         
     | 
| 
      
 146 
     | 
    
         
            +
                account.type = "REVENUE"
         
     | 
| 
      
 147 
     | 
    
         
            +
                account.tax_type = "OUTPUT"
         
     | 
| 
      
 148 
     | 
    
         
            +
                account.description = "Income from any normal business activity"
         
     | 
| 
      
 149 
     | 
    
         
            +
                account.enable_payments_to_account = false
         
     | 
| 
      
 150 
     | 
    
         
            +
                account
         
     | 
| 
      
 151 
     | 
    
         
            +
              end
         
     | 
| 
      
 152 
     | 
    
         
            +
             
     | 
| 
      
 153 
     | 
    
         
            +
              def create_test_contact(contact_params={})
         
     | 
| 
      
 154 
     | 
    
         
            +
                # Strip out :address key from contact_params to use as the default address.
         
     | 
| 
      
 155 
     | 
    
         
            +
                stripped_address = {
         
     | 
| 
      
 156 
     | 
    
         
            +
                  :address_type => 'STREET',
         
     | 
| 
      
 157 
     | 
    
         
            +
                  :line_1       => 'LINE 1 OF THE ADDRESS'
         
     | 
| 
      
 158 
     | 
    
         
            +
                }.merge(contact_params.delete(:address) || {})
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
                # Strip out :phone key from contact_params to use at the default phone.
         
     | 
| 
      
 161 
     | 
    
         
            +
                stripped_phone = {
         
     | 
| 
      
 162 
     | 
    
         
            +
                  :phone_type => 'DEFAULT',
         
     | 
| 
      
 163 
     | 
    
         
            +
                  :number     => '12345678'
         
     | 
| 
      
 164 
     | 
    
         
            +
                }.merge(contact_params.delete(:phone) || {})
         
     | 
| 
      
 165 
     | 
    
         
            +
             
     | 
| 
      
 166 
     | 
    
         
            +
                contact_params = {
         
     | 
| 
      
 167 
     | 
    
         
            +
                  :contact_id => '00000000-0000-0000-0000-000000000000', # Just any valid GUID
         
     | 
| 
      
 168 
     | 
    
         
            +
                  :name       => "CONTACT NAME",
         
     | 
| 
      
 169 
     | 
    
         
            +
                  :first_name => "Bob",
         
     | 
| 
      
 170 
     | 
    
         
            +
                  :last_name  => "Builder"
         
     | 
| 
      
 171 
     | 
    
         
            +
                }.merge(contact_params)
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                contact = XeroGateway::Contact.new(contact_params)
         
     | 
| 
      
 174 
     | 
    
         
            +
                contact.address = XeroGateway::Address.new(stripped_address)
         
     | 
| 
      
 175 
     | 
    
         
            +
                contact.phone = XeroGateway::Phone.new(stripped_phone)
         
     | 
| 
      
 176 
     | 
    
         
            +
                contact
         
     | 
| 
      
 177 
     | 
    
         
            +
              end
         
     | 
| 
      
 178 
     | 
    
         
            +
             
     | 
| 
      
 179 
     | 
    
         
            +
              def create_test_manual_journal(params={}, journal_line_params={})
         
     | 
| 
      
 180 
     | 
    
         
            +
                params = {      
         
     | 
| 
      
 181 
     | 
    
         
            +
                  :date       => Date.today,
         
     | 
| 
      
 182 
     | 
    
         
            +
                  :narration  => 'test narration',
         
     | 
| 
      
 183 
     | 
    
         
            +
                  :status     => 'POSTED'
         
     | 
| 
      
 184 
     | 
    
         
            +
                }.merge(params)
         
     | 
| 
      
 185 
     | 
    
         
            +
                manual_journal = XeroGateway::ManualJournal.new(params)
         
     | 
| 
      
 186 
     | 
    
         
            +
                add_test_journal_lines(manual_journal, journal_line_params)
         
     | 
| 
      
 187 
     | 
    
         
            +
              end
         
     | 
| 
      
 188 
     | 
    
         
            +
             
     | 
| 
      
 189 
     | 
    
         
            +
              def add_test_journal_lines(manual_journal, journal_line_params)
         
     | 
| 
      
 190 
     | 
    
         
            +
                if journal_line_params
         
     | 
| 
      
 191 
     | 
    
         
            +
                  journal_line_params = [journal_line_params].flatten # always use an array, even if only a single hash passed in
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
                  # At least one line item, make first have some defaults.
         
     | 
| 
      
 194 
     | 
    
         
            +
                  journal_line_params << {} if journal_line_params.size == 0
         
     | 
| 
      
 195 
     | 
    
         
            +
                  journal_line_params[0] = {
         
     | 
| 
      
 196 
     | 
    
         
            +
                    :description  => "FIRST LINE",
         
     | 
| 
      
 197 
     | 
    
         
            +
                    :account_code => "200",
         
     | 
| 
      
 198 
     | 
    
         
            +
                    :line_amount  => BigDecimal.new("100"),
         
     | 
| 
      
 199 
     | 
    
         
            +
                    :tracking     => XeroGateway::TrackingCategory.new(:name => "blah", :options => "hello")
         
     | 
| 
      
 200 
     | 
    
         
            +
                  }.merge(journal_line_params[0])
         
     | 
| 
      
 201 
     | 
    
         
            +
                  params_line_1 = journal_line_params[1] || {}
         
     | 
| 
      
 202 
     | 
    
         
            +
                  journal_line_params[1] = {
         
     | 
| 
      
 203 
     | 
    
         
            +
                    :description  => "SECOND LINE",
         
     | 
| 
      
 204 
     | 
    
         
            +
                    :account_code => "200",
         
     | 
| 
      
 205 
     | 
    
         
            +
                    :line_amount  => BigDecimal.new("-100"),        
         
     | 
| 
      
 206 
     | 
    
         
            +
                    :tracking     => XeroGateway::TrackingCategory.new(:name => "blah2", :options => "hello2")
         
     | 
| 
      
 207 
     | 
    
         
            +
                  }.merge(params_line_1)      
         
     | 
| 
      
 208 
     | 
    
         
            +
             
     | 
| 
      
 209 
     | 
    
         
            +
                  # Create line_items from line_item_params
         
     | 
| 
      
 210 
     | 
    
         
            +
                  journal_line_params.each do |journal_line|
         
     | 
| 
      
 211 
     | 
    
         
            +
                    manual_journal.add_journal_line(journal_line)
         
     | 
| 
      
 212 
     | 
    
         
            +
                  end
         
     | 
| 
      
 213 
     | 
    
         
            +
                end
         
     | 
| 
      
 214 
     | 
    
         
            +
                manual_journal
         
     | 
| 
      
 215 
     | 
    
         
            +
              end
         
     | 
| 
      
 216 
     | 
    
         
            +
             
     | 
| 
      
 217 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,47 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.join(File.dirname(__FILE__), '../test_helper.rb')
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            class AccountTest < Test::Unit::TestCase
         
     | 
| 
      
 4 
     | 
    
         
            +
              # Tests that an account can be converted into XML that Xero can understand, and then converted back to an account
         
     | 
| 
      
 5 
     | 
    
         
            +
              def test_build_and_parse_xml
         
     | 
| 
      
 6 
     | 
    
         
            +
                account = create_test_account
         
     | 
| 
      
 7 
     | 
    
         
            +
                
         
     | 
| 
      
 8 
     | 
    
         
            +
                # Generate the XML message
         
     | 
| 
      
 9 
     | 
    
         
            +
                account_as_xml = account.to_xml
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                # Parse the XML message and retrieve the account element
         
     | 
| 
      
 12 
     | 
    
         
            +
                account_element = REXML::XPath.first(REXML::Document.new(account_as_xml), "/Account")
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                # Build a new account from the XML
         
     | 
| 
      
 15 
     | 
    
         
            +
                result_account = XeroGateway::Account.from_xml(account_element)
         
     | 
| 
      
 16 
     | 
    
         
            +
                
         
     | 
| 
      
 17 
     | 
    
         
            +
                # Check the account details
         
     | 
| 
      
 18 
     | 
    
         
            +
                assert_equal account, result_account
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 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
         
     | 
| 
      
 32 
     | 
    
         
            +
              
         
     | 
| 
      
 33 
     | 
    
         
            +
              private
         
     | 
| 
      
 34 
     | 
    
         
            +
              
         
     | 
| 
      
 35 
     | 
    
         
            +
              def create_test_account(options={})
         
     | 
| 
      
 36 
     | 
    
         
            +
                account = XeroGateway::Account.new(:account_id => "57cedda9")
         
     | 
| 
      
 37 
     | 
    
         
            +
                account.code = "200"
         
     | 
| 
      
 38 
     | 
    
         
            +
                account.name = "Sales"
         
     | 
| 
      
 39 
     | 
    
         
            +
                account.type = options[:type] || "REVENUE"
         
     | 
| 
      
 40 
     | 
    
         
            +
                account.tax_type = "OUTPUT"
         
     | 
| 
      
 41 
     | 
    
         
            +
                account.description = "Income from any normal business activity"
         
     | 
| 
      
 42 
     | 
    
         
            +
                account.enable_payments_to_account = false
         
     | 
| 
      
 43 
     | 
    
         
            +
                account.currency_code = options[:currency_code] if options[:currency_code]
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                account
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     |