Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed parsing when the object is the root node.

Signed-off-by: John Nunemaker <nunemaker@gmail.com>
  • Loading branch information...
commit 03d44d496c6a91a23613078e8f3325488ff38902 1 parent 36b5d4b
@galfert galfert authored committed
View
2  lib/happymapper.rb
@@ -73,7 +73,7 @@ def parse(xml, o={})
node.register_default_namespace(namespace.chop)
node.find("#{namespace}#{get_tag_name}")
else
- doc.find(get_tag_name)
+ doc.find("//#{get_tag_name}")
end
collection = create_collection(nodes, namespace)
View
8 spec/fixtures/address.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<address>
+ <street>Milchstrasse</street>
+ <housenumber>23</housenumber>
+ <postcode>26131</postcode>
+ <city>Oldenburg</city>
+ <country code="de">Germany</country>
+</address>
View
25 spec/happymapper_spec.rb
@@ -69,6 +69,16 @@ class Items
end
end
+class Address
+ include HappyMapper
+
+ element :street, String
+ element :postcode, String
+ element :housenumber, String
+ element :city, String
+ element :country, String
+end
+
describe HappyMapper do
describe "being included into another class" do
@@ -202,6 +212,21 @@ class Foo; include HappyMapper end
first.user.followers_count.should == 486
end
end
+
+ describe "#parse (with xml containing the desired element as root node)" do
+ before do
+ file_contents = File.read(File.dirname(__FILE__) + '/fixtures/address.xml')
+ @address = Address.parse(file_contents, :single => true)
+ end
+
+ it "should properly create objects" do
+ @address.street.should == 'Milchstrasse'
+ @address.postcode.should == '26131'
+ @address.housenumber.should == '23'
+ @address.city.should == 'Oldenburg'
+ @address.country.should == 'Germany'
+ end
+ end
# TODO: someone please get xml with namespaces working, kthxbai
describe "#parse (with xml that has namespace)" do
Please sign in to comment.
Something went wrong with that request. Please try again.