Skip to content

Commit 6df91c1

Browse files
committed
Merge branch 'master' into single-element-array
2 parents 8dca7a4 + f93d594 commit 6df91c1

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

lib/qbxml/types.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Qbxml::Types
55
:qbpos => :qbposxml
66
}.freeze
77

8-
FLOAT_CAST = Proc.new {|d| d ? Float(d) : 0.0}
8+
FLOAT_CAST = Proc.new {|d| d ? d.to_f : 0.0}
99
BOOL_CAST = Proc.new {|d| d ? (d.to_s.downcase == 'true' ? true : false) : false }
1010
DATE_CAST = Proc.new {|d| d ? Date.parse(d).strftime("%Y-%m-%d") : Date.today.strftime("%Y-%m-%d") }
1111
TIME_CAST = Proc.new {|d| d ? Time.parse(d).xmlschema : Time.now.xmlschema }

test/unit/xml_to_hash_test.rb

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,79 @@ def test_array_with_one_element
4646
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")
4747
end
4848

49+
def test_float_percentage
50+
qbxml = Qbxml.new
51+
h = {
52+
"qbxml" => {
53+
"xml_attributes" => {},
54+
"qbxml_msgs_rs" => {
55+
"xml_attributes" => {},
56+
"item_query_rs" => {
57+
"xml_attributes" => {
58+
"requestID" => "Retrieve items",
59+
"statusCode" => "0",
60+
"statusSeverity" => "Info",
61+
"statusMessage" => "Status OK",
62+
"iteratorRemainingCount" => "0",
63+
"iteratorID" => "{10c05cbd-b25b-4a85-8aa0-8bce89e6e900}"
64+
},
65+
"item_service_ret" => {
66+
"xml_attributes" => {},
67+
"list_id" => "80000005-1468535148",
68+
"time_created" => "2016-07-14T15:25:48-08:00",
69+
"time_modified" => "2016-07-14T15:25:48-08:00",
70+
"edit_sequence" => "1468535148",
71+
"name" => "let's get intuit",
72+
"full_name" => "let's get intuit",
73+
"is_active" => true,
74+
"sublevel" => 0,
75+
"sales_or_purchase" => {
76+
"xml_attributes" => {},
77+
"price_percent" => 18.0,
78+
"account_ref" => {
79+
"xml_attributes" => {},
80+
"list_id" => "80000015-1457547358",
81+
"full_name" => "Repairs and Maintenance"
82+
}
83+
}
84+
}
85+
}
86+
}
87+
}
88+
}
4989

50-
end
90+
xml = <<-XML
91+
<QBXML>
92+
<QBXMLMsgsRs>
93+
<ItemQueryRs requestID="Retrieve items"
94+
statusCode="0"
95+
statusSeverity="Info"
96+
statusMessage="Status OK"
97+
iteratorRemainingCount="0"
98+
iteratorID="{10c05cbd-b25b-4a85-8aa0-8bce89e6e900}">
99+
<ItemServiceRet>
100+
<ListID>80000005-1468535148</ListID>
101+
<TimeCreated>2016-07-14T15:25:48-08:00</TimeCreated>
102+
<TimeModified>2016-07-14T15:25:48-08:00</TimeModified>
103+
<EditSequence>1468535148</EditSequence>
104+
<Name>let's get intuit</Name>
105+
<FullName>let's get intuit</FullName>
106+
<IsActive>true</IsActive>
107+
<Sublevel>0</Sublevel>
108+
<SalesOrPurchase>
109+
<PricePercent>18.0%</PricePercent>
110+
<AccountRef>
111+
<ListID>80000015-1457547358</ListID>
112+
<FullName>Repairs and Maintenance</FullName>
113+
</AccountRef>
114+
</SalesOrPurchase>
115+
</ItemServiceRet>
116+
</ItemQueryRs>
117+
</QBXMLMsgsRs>
118+
</QBXML>
119+
XML
51120

121+
assert_equal h, qbxml.from_qbxml(xml)
122+
end
123+
124+
end

0 commit comments

Comments
 (0)