Sha256: 3cc30540c7ce4ac1a501511a8106abfaa14a66102febc887db9c3dd0c27d0a3d

Contents?: true

Size: 1.95 KB

Versions: 29

Compression:

Stored size: 1.95 KB

Contents

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

class TrackingCategoryTest < Test::Unit::TestCase
  # Tests that a tracking category can be converted into XML that Xero can understand, and then converted back to a tracking category
  def test_build_and_parse_xml
    tracking_category = create_test_tracking_category
    
    # Generate the XML message
    tracking_category_as_xml = tracking_category.to_xml

    # Parse the XML message and retrieve the tracking category element
    tracking_category_element = REXML::XPath.first(REXML::Document.new(tracking_category_as_xml), "/TrackingCategory")

    # Build a new tracking category from the XML
    result_tracking_category = XeroGateway::TrackingCategory.from_xml(tracking_category_element)
    
    # Check the tracking category details
    assert_equal tracking_category, result_tracking_category
  end

  def test_build_and_parse_xml_from_line_item
    tracking_category = create_test_line_item_tracking_category

    # Generate the XML message
    tracking_category_as_xml = tracking_category.to_xml_for_invoice_messages

    # Parse the XML message and retrieve the tracking category element
    tracking_category_element = REXML::XPath.first(REXML::Document.new(tracking_category_as_xml), "/TrackingCategory")

    # Build a new tracking category from the XML
    result_tracking_category = XeroGateway::TrackingCategory.from_xml(tracking_category_element)

    # Check the tracking category details
    assert_equal tracking_category, result_tracking_category
  end
  
  private
  
  def create_test_tracking_category
    tracking_category = XeroGateway::TrackingCategory.new
    tracking_category.name = "REGION"
    tracking_category.options = ["NORTH", "SOUTH", "CENTRAL"]
    tracking_category
  end

  def create_test_line_item_tracking_category
    tracking_category = XeroGateway::TrackingCategory.new
    tracking_category.name = "REGION"
    tracking_category.options = ["NORTH"]
    tracking_category
  end
end

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
xero_gateway-2.0.15 test/unit/tracking_category_test.rb
xero_gateway-2.0.14 test/unit/tracking_category_test.rb
xero_gateway-2.0.13 test/unit/tracking_category_test.rb
xero_gateway-2.0.12 test/unit/tracking_category_test.rb
xero_gateway-2.0.11 test/unit/tracking_category_test.rb
xero_gateway-2.0.10 test/unit/tracking_category_test.rb
xero_gateway-2.0.9 test/unit/tracking_category_test.rb
xero_gateway-2.0.8 test/unit/tracking_category_test.rb
xero_gateway-2.0.7 test/unit/tracking_category_test.rb