Skip to content

Commit

Permalink
Added spec for new and old attributes syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
skalarproduktraum committed Nov 9, 2013
1 parent b74f0a7 commit 5871720
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions spec/integration/centra_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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?

puts "new syntax: attributes element not present: " + attributes_element_not_present.to_s

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?

puts "new syntax: attributes element not present: " + attributes_element_not_present.to_s

expect(attributes_element_not_present).to eq true
end
end

0 comments on commit 5871720

Please sign in to comment.