jnunemaker-happymapper 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/happymapper.gemspec +1 -1
- data/lib/happymapper.rb +11 -1
- data/spec/happymapper_spec.rb +30 -0
- metadata +1 -1
data/happymapper.gemspec
CHANGED
data/lib/happymapper.rb
CHANGED
@@ -75,7 +75,17 @@ module HappyMapper
|
|
75
75
|
else
|
76
76
|
doc.find("//#{get_tag_name}")
|
77
77
|
end
|
78
|
-
|
78
|
+
|
79
|
+
nodes = if namespace
|
80
|
+
node = doc.respond_to?(:root) ? doc.root : doc
|
81
|
+
node.register_default_namespace(namespace.chop)
|
82
|
+
node.find("#{namespace}#{get_tag_name}")
|
83
|
+
else
|
84
|
+
nested = '.' unless doc.respond_to?(:root)
|
85
|
+
path = "#{nested}//#{get_tag_name}"
|
86
|
+
doc.find(path)
|
87
|
+
end
|
88
|
+
|
79
89
|
collection = create_collection(nodes, namespace)
|
80
90
|
|
81
91
|
# per http://libxml.rubyforge.org/rdoc/classes/LibXML/XML/Document.html#M000354
|
data/spec/happymapper_spec.rb
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
|
+
class Place
|
4
|
+
include HappyMapper
|
5
|
+
|
6
|
+
element :name, String
|
7
|
+
end
|
8
|
+
|
9
|
+
class Radar
|
10
|
+
include HappyMapper
|
11
|
+
has_many :places, Place
|
12
|
+
end
|
13
|
+
|
3
14
|
class Post
|
4
15
|
include HappyMapper
|
5
16
|
|
@@ -261,4 +272,23 @@ describe HappyMapper do
|
|
261
272
|
@first.current_condition.icon.should == 'http://deskwx.weatherbug.com/images/Forecast/icons/cond007.gif'
|
262
273
|
end
|
263
274
|
end
|
275
|
+
|
276
|
+
describe "#parse (with xml that has nested elements)" do
|
277
|
+
before do
|
278
|
+
file_contents = File.read(File.dirname(__FILE__) + '/fixtures/radar.xml')
|
279
|
+
@radars = Radar.parse(file_contents)
|
280
|
+
end
|
281
|
+
|
282
|
+
it "should properly create objects" do
|
283
|
+
@first = @radars[0]
|
284
|
+
@first.places.size.should == 1
|
285
|
+
@first.places[0].name.should == 'Store'
|
286
|
+
@second = @radars[1]
|
287
|
+
@second.places.size.should == 0
|
288
|
+
@third = @radars[2]
|
289
|
+
@third.places.size.should == 2
|
290
|
+
@third.places[0].name.should == 'Work'
|
291
|
+
@third.places[1].name.should == 'Home'
|
292
|
+
end
|
293
|
+
end
|
264
294
|
end
|