Skip to content

Commit

Permalink
Merge branch 'master' into single-element-array
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonBarnabe committed Aug 16, 2016
2 parents 8dca7a4 + f93d594 commit 6df91c1
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/qbxml/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Qbxml::Types
:qbpos => :qbposxml
}.freeze

FLOAT_CAST = Proc.new {|d| d ? Float(d) : 0.0}
FLOAT_CAST = Proc.new {|d| d ? d.to_f : 0.0}
BOOL_CAST = Proc.new {|d| d ? (d.to_s.downcase == 'true' ? true : false) : false }
DATE_CAST = Proc.new {|d| d ? Date.parse(d).strftime("%Y-%m-%d") : Date.today.strftime("%Y-%m-%d") }
TIME_CAST = Proc.new {|d| d ? Time.parse(d).xmlschema : Time.now.xmlschema }
Expand Down
75 changes: 74 additions & 1 deletion test/unit/xml_to_hash_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,79 @@ def test_array_with_one_element
assert_equal h, qbxml.from_qbxml("<?qbxml version=\"7.0\"?>\n<QBXML>\n <QBXMLMsgsRs>\n <CustomerQueryRs>\n <CustomerRet><ListID>abc</ListID></CustomerRet>\n </CustomerQueryRs>\n </QBXMLMsgsRs>\n</QBXML>\n")
end

def test_float_percentage
qbxml = Qbxml.new
h = {
"qbxml" => {
"xml_attributes" => {},
"qbxml_msgs_rs" => {
"xml_attributes" => {},
"item_query_rs" => {
"xml_attributes" => {
"requestID" => "Retrieve items",
"statusCode" => "0",
"statusSeverity" => "Info",
"statusMessage" => "Status OK",
"iteratorRemainingCount" => "0",
"iteratorID" => "{10c05cbd-b25b-4a85-8aa0-8bce89e6e900}"
},
"item_service_ret" => {
"xml_attributes" => {},
"list_id" => "80000005-1468535148",
"time_created" => "2016-07-14T15:25:48-08:00",
"time_modified" => "2016-07-14T15:25:48-08:00",
"edit_sequence" => "1468535148",
"name" => "let's get intuit",
"full_name" => "let's get intuit",
"is_active" => true,
"sublevel" => 0,
"sales_or_purchase" => {
"xml_attributes" => {},
"price_percent" => 18.0,
"account_ref" => {
"xml_attributes" => {},
"list_id" => "80000015-1457547358",
"full_name" => "Repairs and Maintenance"
}
}
}
}
}
}
}

end
xml = <<-XML
<QBXML>
<QBXMLMsgsRs>
<ItemQueryRs requestID="Retrieve items"
statusCode="0"
statusSeverity="Info"
statusMessage="Status OK"
iteratorRemainingCount="0"
iteratorID="{10c05cbd-b25b-4a85-8aa0-8bce89e6e900}">
<ItemServiceRet>
<ListID>80000005-1468535148</ListID>
<TimeCreated>2016-07-14T15:25:48-08:00</TimeCreated>
<TimeModified>2016-07-14T15:25:48-08:00</TimeModified>
<EditSequence>1468535148</EditSequence>
<Name>let's get intuit</Name>
<FullName>let's get intuit</FullName>
<IsActive>true</IsActive>
<Sublevel>0</Sublevel>
<SalesOrPurchase>
<PricePercent>18.0%</PricePercent>
<AccountRef>
<ListID>80000015-1457547358</ListID>
<FullName>Repairs and Maintenance</FullName>
</AccountRef>
</SalesOrPurchase>
</ItemServiceRet>
</ItemQueryRs>
</QBXMLMsgsRs>
</QBXML>
XML

assert_equal h, qbxml.from_qbxml(xml)
end

end

0 comments on commit 6df91c1

Please sign in to comment.