tokamak 1.1.3 → 1.1.4
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/lib/tokamak/builder/xml.rb +9 -6
- data/lib/tokamak/version.rb +1 -1
- data/test/tokamak/builder/xml_test.rb +24 -0
- metadata +4 -4
data/lib/tokamak/builder/xml.rb
CHANGED
@@ -50,12 +50,15 @@ module Tokamak
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def insert_value(name, prefix, *args, &block)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
53
|
+
# Protected if empty array
|
54
|
+
unless args.size == 1 and args.first == []
|
55
|
+
node = create_element(name.to_s, prefix, *args)
|
56
|
+
node.parent = @parent
|
57
|
+
if block_given?
|
58
|
+
@parent = node
|
59
|
+
block.call
|
60
|
+
@parent = node.parent
|
61
|
+
end
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
data/lib/tokamak/version.rb
CHANGED
@@ -108,6 +108,30 @@ class Tokamak::Builder::XmlTest < Test::Unit::TestCase
|
|
108
108
|
assert_equal "bar" , xml.css("root > foos > id").first.text
|
109
109
|
assert_equal 2 , xml.css("root > foos > id").size
|
110
110
|
end
|
111
|
+
|
112
|
+
def test_values_that_should_be_an_array
|
113
|
+
obj = [{ :foo => ["bar", "zoom"] }]
|
114
|
+
xml = Tokamak::Builder::Xml.build(obj) do |collection|
|
115
|
+
collection.values do |values|
|
116
|
+
values.id "an_id"
|
117
|
+
end
|
118
|
+
|
119
|
+
collection.members do |member, some_foos|
|
120
|
+
member.values do |values|
|
121
|
+
values.ids []
|
122
|
+
some_foos[:foo].each do |id|
|
123
|
+
values.ids id
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
xml = Nokogiri::XML::Document.parse(xml)
|
130
|
+
|
131
|
+
assert_equal "root" , xml.root.name
|
132
|
+
assert_equal "an_id", xml.css("root id").first.text
|
133
|
+
assert_equal ["bar", "zoom"], xml.css("root > member > ids").map { |id| id.text }
|
134
|
+
end
|
111
135
|
|
112
136
|
def test_nested_crazy_values
|
113
137
|
obj = [{ :foo => "bar" }, { :foo => "zue" }]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tokamak
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 4
|
10
|
+
version: 1.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Luis Cipriani
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-17 00:00:00 -02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|