Permalink
Browse files

Fix Tracking Category Rendering

  • Loading branch information...
waynerobinson committed Apr 17, 2012
1 parent 0791ac4 commit 503dbb7a4fadb8efe30659b1878dc62fbf099ca4
Showing with 24 additions and 2 deletions.
  1. +6 −0 lib/xeroizer/record/base_model.rb
  2. +2 −2 lib/xeroizer/record/xml_helper.rb
  3. +16 −0 test/unit/models/line_item_test.rb
@@ -13,6 +13,7 @@ class InvaidPermissionError < StandardError; end
class_inheritable_attributes :permissions
class_inheritable_attributes :xml_root_name
+ class_inheritable_attributes :optional_xml_root_name
class_inheritable_attributes :xml_node_name
include BaseModelHttpProxy
@@ -57,6 +58,11 @@ def set_xml_root_name(root_name)
self.xml_root_name = root_name
end
+ # Method to add an extra top-level node to use in has_many associations.
+ def set_optional_xml_root_name(optional_root_name)
+ self.optional_root_name = optional_root_name
+ end
+
end
public
@@ -56,15 +56,15 @@ module InstanceMethods
# Turn a record into its XML representation.
def to_xml(b = Builder::XmlMarkup.new(:indent => 2))
- optional_root_tag(parent.class.xml_root_name, b) do |b|
+ # optional_root_tag(parent.class.xml_root_name, b) do |b|
b.tag!(parent.class.xml_node_name || parent.model_name) {
attributes.each do | key, value |
field = self.class.fields[key]
value = self.send(key) if field[:calculated]
xml_value_from_field(b, field, value) unless value.nil?
end
}
- end
+ # end
end
protected
@@ -1,7 +1,23 @@
require "test_helper"
class LineItemTest < Test::Unit::TestCase
+ include TestHelper
include Xeroizer::Record
+
+ def setup
+ @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
+ end
+
+ it "line_item tracking specified correctly" do
+ invoice = @client.Invoice.build
+ line_item = invoice.add_line_item({})
+
+ line_item.add_tracking(:name => "Name 1", :option => "Option 1")
+ line_item.add_tracking(:name => "Name 2", :option => "Option 2")
+
+ doc = Nokogiri::XML(line_item.to_xml)
+ assert_equal 2, doc.xpath("/LineItem/Tracking/TrackingCategory").size
+ end
it "line_amount equals unit_price times quantity" do
line_item = LineItem.new(nil)

0 comments on commit 503dbb7

Please sign in to comment.