require "spec_helper" describe Gyoku::Array do describe ".to_xml" do it "returns the XML for an Array of Hashes" do array = [{ :name => "adam" }, { :name => "eve" }] result = "adameve" expect(to_xml(array, "user")).to eq(result) end it "returns the XML for an Array of Hashes unwrapped" do array = [{ :name => "adam" }, { :name => "eve" }] result = "adameve" expect(to_xml(array, "user", true, {}, :unwrap => true)).to eq(result) end it "returns the XML for an Array of different Objects" do array = [:symbol, "string", 123] result = "symbolstring123" expect(to_xml(array, "value")).to eq(result) end it "defaults to escape special characters" do array = ["", "adam & eve"] result = "<tag />adam & eve" expect(to_xml(array, "value")).to eq(result) end it "does not escape special characters when told to" do array = ["", "adam & eve"] result = "adam & eve" expect(to_xml(array, "value", false)).to eq(result) end it "adds attributes to a given tag" do array = ["adam", "eve"] result = 'adameve' expect(to_xml(array, "value", :escape_xml, :active => true)).to eq(result) end it "adds attributes to duplicate tags" do array = ["adam", "eve"] result = 'adameve' expect(to_xml(array, "value", :escape_xml, :id => [1, 2])).to eq(result) end it "skips attribute for element without attributes if there are fewer attributes than elements" do array = ["adam", "eve", "serpent"] result = 'adameveserpent' expect(to_xml(array, "value", :escape_xml, :id => [1, 2])).to eq(result) end it "handles nested Arrays" do array = [["one", "two"]] result = "onetwo" expect(to_xml(array, "value")).to eq(result) end end def to_xml(*args) Gyoku::Array.to_xml *args end end