Sha256: 37e90db79c91f50dfac7f15c1518dbb3c135ac06805eb39a6ec56f6ba1a65741

Contents?: true

Size: 1.68 KB

Versions: 136

Compression:

Stored size: 1.68 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")

describe Braintree::Xml::Libxml do
  describe "self.parse" do
    it "typecasts integers" do
      xml = "<root><foo type=\"integer\">123</foo></root>"
      Braintree::Xml::Libxml.parse(xml).should == {"root"=>{"foo"=>{"__content__"=>"123", "type"=>"integer"}}}
    end

    it "works with dashes or underscores" do
      xml = <<-END
        <root>
          <dash-es />
          <under_scores />
        </root>
      END
      Braintree::Xml::Libxml.parse(xml).should == {"root"=>{"dash-es"=>{}, "under_scores"=>{}}}
    end

    it "uses nil if nil=true, otherwise uses empty string" do
      xml = <<-END
        <root>
          <a_nil_value nil="true"></a_nil_value>
          <an_empty_string></an_empty_string>
        </root>
      END
      Braintree::Xml::Libxml.parse(xml).should == {"root"=>{"a_nil_value"=>{"nil"=>"true"}, "an_empty_string"=>{}}}
    end

    it "typecasts dates and times" do
      xml = <<-END
        <root>
          <created-at type="datetime">2009-10-28T10:19:49Z</created-at>
        </root>
      END
      Braintree::Xml::Libxml.parse(xml).should == {"root"=>{"created-at"=>{"__content__"=>"2009-10-28T10:19:49Z", "type"=>"datetime"}}}
    end

    it "builds an array if type=array" do
      xml = <<-END
        <root>
          <customers type="array">
            <customer><name>Adam</name></customer>
            <customer><name>Ben</name></customer>
          </customers>
        </root>
      END
      Braintree::Xml::Libxml.parse(xml).should == {"root"=>{"customers"=>{"type"=>"array", "customer"=>[{"name"=>{"__content__"=>"Adam"}}, {"name"=>{"__content__"=>"Ben"}}]}}}
    end
  end
end

Version data entries

136 entries across 136 versions & 1 rubygems

Version Path
braintree-2.30.2 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.30.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.29.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.28.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.27.1 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.27.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.26.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.25.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.24.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.23.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.22.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.21.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.20.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.19.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.18.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.17.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.16.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.15.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.14.0 spec/unit/braintree/xml/libxml_spec.rb
braintree-2.13.4 spec/unit/braintree/xml/libxml_spec.rb