Sha256: dbbd9a3eb2a9076f0854062bf22ff337aff0b1f846f6fd5f0a7fbf87b1e180c0

Contents?: true

Size: 1.67 KB

Versions: 131

Compression:

Stored size: 1.67 KB

Contents

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

describe Braintree::Xml::Rexml do
  describe "self.parse" do
    it "typecasts integers" do
      xml = "<root><foo type=\"integer\">123</foo></root>"
      Braintree::Xml::Rexml.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::Rexml.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::Rexml.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::Rexml.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::Rexml.parse(xml).should == {"root"=>{"customers"=>{"type"=>"array", "customer"=>[{"name"=>{"__content__"=>"Adam"}}, {"name"=>{"__content__"=>"Ben"}}]}}}
    end
  end
end

Version data entries

131 entries across 131 versions & 1 rubygems

Version Path
braintree-2.64.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.63.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.62.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.61.1 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.61.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.60.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.59.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.58.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.57.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.56.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.55.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.54.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.50.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.49.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.48.1 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.48.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.47.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.46.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.45.0 spec/unit/braintree/xml/rexml_spec.rb
braintree-2.44.0 spec/unit/braintree/xml/rexml_spec.rb