Permalink
Browse files

merge

  • Loading branch information...
1 parent bbbe07b commit dd356f824bd96a861eaa056bf0868afed197f79a @fisherwebdev committed Jan 29, 2012
Showing with 37 additions and 1 deletion.
  1. +1 −0 .gitignore
  2. +8 −1 lib/multi_xml.rb
  3. +28 −0 spec/parser_shared_example.rb
View
@@ -8,3 +8,4 @@ coverage/*
doc/*
log/*
pkg/*
+/nbproject/private/
View
@@ -182,8 +182,15 @@ def typecast_xml_value(value)
case value
when Hash
if value['type'] == 'array'
+
+ # this commented-out suggestion helps to avoid the multiple attribute
+ # problem, but it breaks when there is only one item in the array.
+ #
+ # from: https://github.com/jnunemaker/httparty/issues/102
+ #
+ # _, entries = value.detect { |k, v| k != 'type' && v.is_a?(Array) }
_, entries = value.detect {|key, _| key != 'type'}
-
+
if entries.nil? || (entries.is_a?(String) && entries.strip.empty?)
[]
else
@@ -391,6 +391,34 @@
MultiXml.parse(@xml)['users'].should == ["Erik Michaels-Ober", "Wynn Netherland"]
end
end
+
+ context "with an attribute type=\"array\" in addtion to other attributes" do
+ before do
+ @xml = '<users type="array" foo="bar"><user>Erik Michaels-Ober</user><user>Wynn Netherland</user></users>'
+ end
+
+ it "should return an Array" do
+ MultiXml.parse(@xml)['users'].should be_a(Array)
+ end
+
+ it "should return the correct array" do
+ MultiXml.parse(@xml)['users'].should == ["Erik Michaels-Ober", "Wynn Netherland"]
+ end
+ end
+
+ context "with an attribute type=\"array\" containing only one item" do
+ before do
+ @xml = '<users type="array"><user>Erik Michaels-Ober</user></users>'
+ end
+
+ it "should return an Array" do
+ MultiXml.parse(@xml)['users'].should be_a(Array)
+ end
+
+ it "should return the correct array" do
+ MultiXml.parse(@xml)['users'].should == ["Erik Michaels-Ober"]
+ end
+ end
%w(integer boolean date datetime yaml file).each do |type|
context "with an empty attribute type=\"#{type}\"" do

0 comments on commit dd356f8

Please sign in to comment.