Sha256: 7288f9fa5618dd71c74cc545259af8c672ad5e661f5056466dc52c53bc53ffb6

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

require "spec_helper"

module Savon
  describe QualifiedMessage, "#to_hash" do

    context "if a key ends with !" do
      let(:used_namespaces) { {} }
      let(:key_converter) { :camelcase }
      let(:types) { {} }

      it "restores the ! in a key" do
        message = described_class.new(types, used_namespaces, key_converter)
        resulting_hash = message.to_hash({:Metal! => "<Nice/>"}, ["Rock"])

        expect(resulting_hash).to eq({ :Metal! => "<Nice/>" })
      end

      it "properly handles special keys when namespaces are present" do
        used_namespaces = {
          %w(tns Foo) => 'ns',
          %w(tns Foo Bar) => 'ns'
        }

        hash = {
          :foo => {
            :bar => {
              :zing => 'pow'
            },
            :cash => {
              :@attr1 => 'val1',
              :content! => 'Chunky Bacon'
            },
            :attributes! => {
              :bar => { :attr2 => 'val2' },
            },
            :"self_closing/" => '',
            :order! => [:cash, :bar, :"self_closing/"]
          }
        }

        good_result = {
          "ns:Foo" => {
            'ns:Bar' => { :zing => "pow" },
            :cash => {
              :@attr1 => "val1",
              :content! => "Chunky Bacon"
            },
            :attributes! => {
              'ns:Bar' => { :attr2 => 'val2' }
            },
            :"self_closing/" => '',
            :order! => [:cash, 'ns:Bar', :"self_closing/"]
          }
        }

        good_xml = %(<ns:Foo><Cash attr1="val1">Chunky Bacon</Cash><ns:Bar attr2="val2"><Zing>pow</Zing></ns:Bar><SelfClosing/></ns:Foo>)

        message = described_class.new(types, used_namespaces, key_converter)
        resulting_hash = message.to_hash(hash, ['tns'])
        xml = Gyoku.xml(resulting_hash, key_converter: key_converter)

        expect(resulting_hash).to eq good_result
        expect(xml).to eq good_xml
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
savon-2.11.2 spec/savon/qualified_message_spec.rb