Sha256: d23cd3d6e355445cba88e424f5d092f5f10c61392e2dd50ab99c49041bad2e9b

Contents?: true

Size: 1.65 KB

Versions: 18

Compression:

Stored size: 1.65 KB

Contents

require File.join(File.dirname(__FILE__), '../test_helper.rb')

class AccountTest < Test::Unit::TestCase
  # Tests that an account can be converted into XML that Xero can understand, and then converted back to an account
  def test_build_and_parse_xml
    account = create_test_account
    
    # Generate the XML message
    account_as_xml = account.to_xml

    # Parse the XML message and retrieve the account element
    account_element = REXML::XPath.first(REXML::Document.new(account_as_xml), "/Account")

    # Build a new account from the XML
    result_account = XeroGateway::Account.from_xml(account_element)
    
    # Check the account details
    assert_equal account, result_account
  end
  
  def test_build_and_parse_xml_for_bank_accounts
    account = create_test_account(:type => 'BANK', :currency_code => 'NZD')
    account_as_xml = account.to_xml
    assert_match 'CurrencyCode', account_as_xml.to_s

    account_element = REXML::XPath.first(REXML::Document.new(account_as_xml), "/Account")
    result_account = XeroGateway::Account.from_xml(account_element)
    assert_equal 'BANK', result_account.type
    assert_equal 'NZD', result_account.currency_code
    assert_equal account, result_account
  end
  
  private
  
  def create_test_account(options={})
    account = XeroGateway::Account.new(:account_id => "57cedda9")
    account.code = "200"
    account.name = "Sales"
    account.type = options[:type] || "REVENUE"
    account.tax_type = "OUTPUT"
    account.description = "Income from any normal business activity"
    account.enable_payments_to_account = false
    account.currency_code = options[:currency_code] if options[:currency_code]

    account
  end
end

Version data entries

18 entries across 18 versions & 3 rubygems

Version Path
xero_gateway-2.3.0 test/unit/account_test.rb
xero_gateway-float-2.1.7 test/unit/account_test.rb
xero_gateway-float-2.1.6 test/unit/account_test.rb
xero_gateway-float-2.1.4 test/unit/account_test.rb
xero_gateway-float-2.1.3 test/unit/account_test.rb
xero_gateway-float-2.1.1 test/unit/account_test.rb
xero_gateway-float-2.0.18 test/unit/account_test.rb
xero_gateway-float-2.0.17 test/unit/account_test.rb
xero_gateway-float-2.0.16 test/unit/account_test.rb
xero_gateway-float-2.0.15 test/unit/account_test.rb
xero_gateway-2.1.0 test/unit/account_test.rb
xero_gateway-n8vision-2.0.20 test/unit/account_test.rb
xero_gateway-2.0.19 test/unit/account_test.rb
xero_gateway-2.0.18 test/unit/account_test.rb
xero_gateway-2.0.17 test/unit/account_test.rb
xero_gateway-2.0.16 test/unit/account_test.rb
xero_gateway-2.0.15 test/unit/account_test.rb
xero_gateway-2.0.14 test/unit/account_test.rb