Sha256: e61ce375d930fdbceec8019fc42f29e2b6eacdbe4405b1048b0b379fbd54a390

Contents?: true

Size: 1.65 KB

Versions: 28

Compression:

Stored size: 1.65 KB

Contents

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

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

    it "works with dashes or underscores" do
      xml = <<-END
        <root>
          <dash-es />
          <under_scores />
        </root>
      END
      xml.should parse_to(: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
      xml.should parse_to(:root => {:a_nil_value => nil, :an_empty_string => ""})
    end

    it "typecasts datetimes" do
      xml = <<-END
        <root>
          <created-at type="datetime">2009-10-28T10:19:49Z</created-at>
        </root>
      END
      xml.should parse_to(:root => {:created_at => Time.utc(2009, 10, 28, 10, 19, 49)})
    end

    it "doesn't typecast dates" do
      xml = <<-END
        <root>
          <created-at type="date">2009-10-28</created-at>
        </root>
      END
      xml.should parse_to(:root => {:created_at => "2009-10-28"})
    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
      xml.should parse_to(:root => {:customers => [{:name => "Adam"}, {:name => "Ben"}]})
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
braintree-2.46.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.45.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.44.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.43.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.42.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.41.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.40.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.39.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.38.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.37.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.36.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.35.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.34.1 spec/unit/braintree/xml/parser_spec.rb
braintree-2.34.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.33.1 spec/unit/braintree/xml/parser_spec.rb
braintree-2.33.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.32.1 spec/unit/braintree/xml/parser_spec.rb
braintree-2.31.0 spec/unit/braintree/xml/parser_spec.rb
braintree-2.30.2 spec/unit/braintree/xml/parser_spec.rb
braintree-2.30.0 spec/unit/braintree/xml/parser_spec.rb