Sha256: bfac02158c1797497e1a8720433ad5a704a33020b461630d3a31ac94aae1a614

Contents?: true

Size: 1.81 KB

Versions: 8

Compression:

Stored size: 1.81 KB

Contents

require 'spec_helper'

module LogInterceptor
  @@intercepted_request = ""
  def self.debug(message)
    # save only the first XMLly message
    if message.include? "xml version"
      @@intercepted_request = message if @@intercepted_request == ""
    end
  end

  def self.info(message)
  end

  def self.get_intercepted_request
    @@intercepted_request
  end

  def self.reset_intercepted_request
    @@intercepted_request = ""
  end
end

describe 'Correct translation of attributes to XML' do
  it "new :@attr syntax: correctly maps a Ruby Hash to XML attributes" do
    LogInterceptor.reset_intercepted_request

    client = Savon.client(
      :wsdl => "http://mt205.sabameeting.com/CWS/CWS.asmx?WSDL",
      :logger => LogInterceptor
    )

    response = nil
    begin
      response = call_and_fail_gracefully(client, :add_new_user, :message => { :user => { :@userID => "test" } })
    rescue
    end

    xml_doc = Nokogiri::XML(LogInterceptor.get_intercepted_request)
    xml_doc.remove_namespaces!

    attributes_element_not_present = xml_doc.xpath("//AddNewUser/attributes").blank?
    expect(attributes_element_not_present).to eq true
  end

  it "old :attributes! syntax: correctly maps a Ruby Hash to XML attributes" do
    LogInterceptor.reset_intercepted_request

    client = Savon.client(
      :wsdl => "http://mt205.sabameeting.com/CWS/CWS.asmx?WSDL",
      :logger => LogInterceptor
    )

    response = nil
    begin
      response = call_and_fail_gracefully(client, :add_new_user, :message => { :user => {}, :attributes! => { :user => { :userID => "test" } } })
    rescue
    end

    xml_doc = Nokogiri::XML(LogInterceptor.get_intercepted_request)
    xml_doc.remove_namespaces!

    attributes_element_not_present = xml_doc.xpath("//AddNewUser/attributes").blank?
    expect(attributes_element_not_present).to eq true
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
savon-2.11.2 spec/integration/centra_spec.rb
savon-SU-2.11.1b spec/integration/centra_spec.rb
savon-SU-2.11.1 spec/integration/centra_spec.rb
savon-2.11.1 spec/integration/centra_spec.rb
savon-2.11.0 spec/integration/centra_spec.rb
savon-2.10.1 spec/integration/centra_spec.rb
savon-2.10.0 spec/integration/centra_spec.rb
savon-2.9.0 spec/integration/centra_spec.rb