jsonbuilder 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/builder/hash_structure.rb +1 -0
- data/lib/jsonbuilder.rb +1 -1
- data/spec/builder/hash_structure_spec.rb +18 -0
- metadata +1 -1
@@ -82,6 +82,7 @@ module Builder
|
|
82
82
|
|
83
83
|
def _explore_key_and_args(key, *args)
|
84
84
|
key = (args.first.is_a?(Symbol) ? "#{key}:#{args.shift}" : key.to_s).gsub(/[-:]/, "_").to_sym
|
85
|
+
args.reject! { |arg| arg.nil? }
|
85
86
|
if args.size > 1 && !args[0].is_a?(Hash)
|
86
87
|
args[0] = StackableHash.new.replace(@default_content_key => args[0])
|
87
88
|
end
|
data/lib/jsonbuilder.rb
CHANGED
@@ -23,6 +23,24 @@ describe Builder::HashStructure do
|
|
23
23
|
builder.target!.should == {:atom_name => "atom:name", :thr_in_reply_to => "thr:in-reply-to", :dc_creator => "dc:creator"}
|
24
24
|
end
|
25
25
|
|
26
|
+
it "should support root attributes" do
|
27
|
+
builder = Builder::HashStructure.new
|
28
|
+
# XML :: <root><tag>value</tag></root>
|
29
|
+
builder.root(:id => 1) do
|
30
|
+
builder.tag "value"
|
31
|
+
end
|
32
|
+
builder.target!.should == {:id => 1, :tag => "value"}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should ignore nil attributes" do
|
36
|
+
builder = Builder::HashStructure.new
|
37
|
+
# XML :: <root><tag>value</tag></root>
|
38
|
+
builder.root(nil) do
|
39
|
+
builder.tag "value"
|
40
|
+
end
|
41
|
+
builder.target!.should == {:tag => "value"}
|
42
|
+
end
|
43
|
+
|
26
44
|
it "should remove the root tag" do
|
27
45
|
builder = Builder::HashStructure.new
|
28
46
|
# XML :: <root><tag>value</tag></root>
|