johnreitano-savon 0.7.2.1 → 0.7.7.1

Sign up to get free protection for your applications and to get access to all the features.
data/spec/http_stubs.rb CHANGED
@@ -21,3 +21,6 @@ FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint(:no_namespace), :body =>
21
21
 
22
22
  # WSDL request returning a WSDL document with namespaced SOAP actions.
23
23
  FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint(:namespaced_actions), :body => WSDLFixture.namespaced_actions
24
+
25
+ # WSDL request returning a WSDL document with geotrust SOAP actions.
26
+ FakeWeb.register_uri :get, EndpointHelper.wsdl_endpoint(:geotrust), :body => WSDLFixture.geotrust
@@ -37,7 +37,7 @@ describe Savon::Client do
37
37
 
38
38
  it "should disable the Savon::WSDL when passed a method with an exclamation mark" do
39
39
  @client.wsdl.enabled?.should be_true
40
- [:respond_to?, :operations, :namespace_uri, :soap_endpoint].each do |method|
40
+ [:operations, :namespace_uri, :soap_endpoint].each do |method|
41
41
  Savon::WSDL.any_instance.expects(method).never
42
42
  end
43
43
 
@@ -70,8 +70,12 @@ describe Savon::Client do
70
70
  end
71
71
  end
72
72
 
73
+ it "should have a call method that forwards to method_missing for SOAP actions named after existing methods" do
74
+ @client.call(:authenticate) { |soap| soap.should be_a(Savon::SOAP) }
75
+ end
76
+
73
77
  it "should raise a NoMethodError when the method does not match an available SOAP action or method" do
74
78
  lambda { @client.some_undefined_method }.should raise_error(NoMethodError)
75
79
  end
76
80
 
77
- end
81
+ end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe Array do
4
+
5
+ describe "to_soap_xml" do
6
+ describe "should return SOAP request compatible XML" do
7
+ it "for an Array of Hashes" do
8
+ hash, result = [{ :name => "Eve" }], "<findUser><name>Eve</name></findUser>"
9
+ hash.to_soap_xml("findUser").should == result
10
+ end
11
+
12
+ it "for an Array of Strings and other Objects" do
13
+ hash, result = [:id, :name], "<someValues>id</someValues><someValues>name</someValues>"
14
+ hash.to_soap_xml("someValues").should == result
15
+ end
16
+ end
17
+ end
18
+
19
+ end
@@ -5,7 +5,7 @@ describe DateTime do
5
5
  describe "to_soap_value" do
6
6
  it "returns an xs:dateTime compliant String" do
7
7
  DateTime.new(2012, 03, 22, 16, 22, 33).to_soap_value.
8
- should == "2012-03-22T16:22:33"
8
+ should == "2012-03-22T16:22:33Z"
9
9
  end
10
10
  end
11
11
 
@@ -3,135 +3,175 @@ require "spec_helper"
3
3
  describe Hash do
4
4
 
5
5
  describe "find_soap_body" do
6
- it "returns the content from the 'soap:Body' element" do
7
- { "soap:Envelope" => { "soap:Body" => "content" } }.find_soap_body.should == "content"
6
+ it "should return the content from the 'soap:Body' element" do
7
+ soap_body = { "soap:Envelope" => { "soap:Body" => "content" } }
8
+ soap_body.find_soap_body.should == "content"
8
9
  end
9
10
 
10
- it "returns an empty Hash in case the 'soap:Body' element could not be found" do
11
- { "some_hash" => "content" }.find_soap_body.should == {}
11
+ it "should return an empty Hash in case the 'soap:Body' element could not be found" do
12
+ soap_body = { "some_hash" => "content" }
13
+ soap_body.find_soap_body.should == {}
12
14
  end
13
15
  end
14
16
 
15
17
  describe "to_soap_xml" do
16
- describe "returns SOAP request compatible XML" do
18
+ describe "should return SOAP request compatible XML" do
17
19
  it "for a simple Hash" do
18
- { :some => "user" }.to_soap_xml.should == "<some>user</some>"
20
+ hash, result = { :some => "user" }, "<some>user</some>"
21
+ hash.to_soap_xml.should == result
19
22
  end
20
23
 
21
24
  it "for a nested Hash" do
22
- { :some => { :new => "user" } }.to_soap_xml.
23
- should == "<some><new>user</new></some>"
25
+ hash, result = { :some => { :new => "user" } }, "<some><new>user</new></some>"
26
+ hash.to_soap_xml.should == result
24
27
  end
25
28
 
26
29
  it "for a Hash with multiple keys" do
27
- soap_xml = { :all => "users", :before => "whatever" }.to_soap_xml
28
-
29
- soap_xml.should include("<all>users</all>")
30
- soap_xml.should include("<before>whatever</before>")
30
+ hash = { :all => "users", :before => "whatever" }
31
+ hash.to_soap_xml.should include("<all>users</all>", "<before>whatever</before>")
31
32
  end
32
33
 
33
34
  it "for a Hash containing an Array" do
34
- { :some => ["user", "gorilla"] }.to_soap_xml.
35
- should == "<some>user</some><some>gorilla</some>"
35
+ hash, result = { :some => ["user", "gorilla"] }, "<some>user</some><some>gorilla</some>"
36
+ hash.to_soap_xml.should == result
36
37
  end
37
38
 
38
39
  it "for a Hash containing an Array of Hashes" do
39
- { :some => [{ :new => "user" }, { :old => "gorilla" }] }.to_soap_xml.
40
- should == "<some><new>user</new></some><some><old>gorilla</old></some>"
40
+ hash = { :some => [{ :new => "user" }, { :old => "gorilla" }] }
41
+ result = "<some><new>user</new></some><some><old>gorilla</old></some>"
42
+
43
+ hash.to_soap_xml.should == result
41
44
  end
42
45
  end
43
46
 
44
- it "converts Hash key Symbols to lowerCamelCase" do
45
- { :find_or_create => "user" }.to_soap_xml.
46
- should == "<findOrCreate>user</findOrCreate>"
47
+ it "should convert Hash key Symbols to lowerCamelCase" do
48
+ hash, result = { :find_or_create => "user" }, "<findOrCreate>user</findOrCreate>"
49
+ hash.to_soap_xml.should == result
47
50
  end
48
51
 
49
- it "does not convert Hash key Strings" do
50
- { "find_or_create" => "user" }.to_soap_xml.
51
- should == "<find_or_create>user</find_or_create>"
52
+ it "should not convert Hash key Strings" do
53
+ hash, result = { "find_or_create" => "user" }, "<find_or_create>user</find_or_create>"
54
+ hash.to_soap_xml.should == result
52
55
  end
53
56
 
54
- it "converts DateTime objects to xs:dateTime compliant Strings" do
55
- { :before => DateTime.new(2012, 03, 22, 16, 22, 33) }.to_soap_xml.
56
- should == "<before>" << "2012-03-22T16:22:33" << "</before>"
57
+ it "should convert DateTime objects to xs:dateTime compliant Strings" do
58
+ hash = { :before => DateTime.new(2012, 03, 22, 16, 22, 33) }
59
+ result = "<before>2012-03-22T16:22:33Z</before>"
60
+
61
+ hash.to_soap_xml.should == result
57
62
  end
58
63
 
59
- it "converts Objects responding to to_datetime to xs:dateTime compliant Strings" do
64
+ it "should convert Objects responding to to_datetime to xs:dateTime compliant Strings" do
60
65
  singleton = Object.new
61
66
  def singleton.to_datetime
62
67
  DateTime.new(2012, 03, 22, 16, 22, 33)
63
68
  end
64
69
 
65
- { :before => singleton }.to_soap_xml.
66
- should == "<before>" << "2012-03-22T16:22:33" << "</before>"
70
+ hash, result = { :before => singleton }, "<before>2012-03-22T16:22:33Z</before>"
71
+ hash.to_soap_xml.should == result
67
72
  end
68
73
 
69
- it "calls to_s on Strings even if they respond to to_datetime" do
74
+ it "should call to_s on Strings even if they respond to to_datetime" do
70
75
  object = "gorilla"
71
- object.expects(:to_s).returns object
72
76
  object.expects(:to_datetime).never
73
77
 
74
- { :name => object }.to_soap_xml.should == "<name>gorilla</name>"
78
+ hash, result = { :name => object }, "<name>gorilla</name>"
79
+ hash.to_soap_xml.should == result
75
80
  end
76
81
 
77
- it "call to_s on any other Object" do
82
+ it "should call to_s on any other Object" do
78
83
  [666, true, false, nil].each do |object|
79
84
  { :some => object }.to_soap_xml.should == "<some>#{object}</some>"
80
85
  end
81
86
  end
82
87
 
83
- it "preserves the order of Hash keys and values specified through :@inorder" do
84
- { :find_user => { :name => "Lucy", :id => 666, :@inorder => [:id, :name] } }.to_soap_xml.
85
- should == "<findUser><id>666</id><name>Lucy</name></findUser>"
88
+ it "should preserve the order of Hash keys and values specified through :order!" do
89
+ hash = { :find_user => { :name => "Lucy", :id => 666, :order! => [:id, :name] } }
90
+ result = "<findUser><id>666</id><name>Lucy</name></findUser>"
91
+ hash.to_soap_xml.should == result
92
+
93
+ hash = { :find_user => { :mname => "in the", :lname => "Sky", :fname => "Lucy", :order! => [:fname, :mname, :lname] } }
94
+ result = "<findUser><fname>Lucy</fname><mname>in the</mname><lname>Sky</lname></findUser>"
95
+ hash.to_soap_xml.should == result
96
+ end
97
+
98
+ it "should raise an error if the :order! Array does not match the Hash keys" do
99
+ hash = { :name => "Lucy", :id => 666, :order! => [:name] }
100
+ lambda { hash.to_soap_xml }.should raise_error(ArgumentError)
86
101
 
87
- { :find_user => { :by_name => { :mname => "in the", :lname => "Sky", :fname => "Lucy",
88
- :@inorder => [:fname, :mname, :lname] } } }.to_soap_xml. should ==
89
- "<findUser><byName><fname>Lucy</fname><mname>in the</mname><lname>Sky</lname></byName></findUser>"
102
+ hash = { :by_name => { :name => "Lucy", :lname => "Sky", :order! => [:mname, :name] } }
103
+ lambda { hash.to_soap_xml }.should raise_error(ArgumentError)
90
104
  end
91
105
 
92
- it "raises an error if the :@inorder Array does not match the Hash keys" do
93
- lambda { { :name => "Lucy", :id => 666, :@inorder => [:name] }.to_soap_xml }.
94
- should raise_error(RuntimeError)
106
+ it "should add attributes to Hash keys specified through :attributes!" do
107
+ hash = { :find_user => { :person => "Lucy", :attributes! => { :person => { :id => 666 } } } }
108
+ result = '<findUser><person id="666">Lucy</person></findUser>'
109
+ hash.to_soap_xml.should == result
110
+
111
+ hash = { :find_user => { :person => "Lucy", :attributes! => { :person => { :id => 666, :city => "Hamburg" } } } }
112
+ soap_xml = hash.to_soap_xml
113
+ soap_xml.should include('id="666"', 'city="Hamburg"')
114
+ end
95
115
 
96
- lambda { { :by_name => { :name => "Lucy", :lname => "Sky", :@inorder => [:mname, :name] } }.to_soap_xml }.
97
- should raise_error(RuntimeError)
116
+ it "should add attributes to duplicate Hash keys specified through :attributes!" do
117
+ hash = { :find_user => { :person => ["Lucy", "Anna"], :attributes! => { :person => { :id => [1, 3] } } } }
118
+ result = '<findUser><person id="1">Lucy</person><person id="3">Anna</person></findUser>'
119
+ hash.to_soap_xml.should == result
120
+
121
+ hash = { :find_user => { :person => ["Lucy", "Anna"], :attributes! => { :person => { :active => "true" } } } }
122
+ result = '<findUser><person active="true">Lucy</person><person active="true">Anna</person></findUser>'
123
+ hash.to_soap_xml.should == result
98
124
  end
99
125
  end
100
126
 
101
127
  describe "map_soap_response" do
102
- it "converts Hash key Strings to snake_case Symbols" do
103
- { "userResponse" => { "accountStatus" => "active" } }.map_soap_response.
104
- should == { :user_response => { :account_status => "active" } }
128
+ it "should convert Hash key Strings to snake_case Symbols" do
129
+ soap_response = { "userResponse" => { "accountStatus" => "active" } }
130
+ result = { :user_response => { :account_status => "active" } }
131
+
132
+ soap_response.map_soap_response.should == result
105
133
  end
106
134
 
107
- it "strips namespaces from Hash keys" do
108
- { "ns:userResponse" => { "ns2:id" => "666" } }.map_soap_response.
109
- should == { :user_response => { :id => "666" } }
135
+ it "should strip namespaces from Hash keys" do
136
+ soap_response = { "ns:userResponse" => { "ns2:id" => "666" } }
137
+ result = { :user_response => { :id => "666" } }
138
+
139
+ soap_response.map_soap_response.should == result
110
140
  end
111
141
 
112
- it "converts Hash keys and values in Arrays" do
113
- { "response" => [{ "name" => "dude" }, { "name" => "gorilla" }] }.map_soap_response.
114
- should == { :response=> [{ :name => "dude" }, { :name => "gorilla" }] }
142
+ it "should convert Hash keys and values in Arrays" do
143
+ soap_response = { "response" => [{ "name" => "dude" }, { "name" => "gorilla" }] }
144
+ result = { :response=> [{ :name => "dude" }, { :name => "gorilla" }] }
145
+
146
+ soap_response.map_soap_response.should == result
115
147
  end
116
148
 
117
- it "converts xsi:nil values to nil Objects" do
118
- { "userResponse" => { "xsi:nil" => "true" } }.map_soap_response.
119
- should == { :user_response => nil }
149
+ it "should convert xsi:nil values to nil Objects" do
150
+ soap_response = { "userResponse" => { "xsi:nil" => "true" } }
151
+ result = { :user_response => nil }
152
+
153
+ soap_response.map_soap_response.should == result
120
154
  end
121
155
 
122
- it "converts Hash values matching the xs:dateTime format into DateTime Objects" do
123
- { "response" => { "at" => "2012-03-22T16:22:33" } }.map_soap_response.
124
- should == { :response => { :at => DateTime.new(2012, 03, 22, 16, 22, 33) } }
156
+ it "should convert Hash values matching the xs:dateTime format into DateTime Objects" do
157
+ soap_response = { "response" => { "at" => "2012-03-22T16:22:33" } }
158
+ result = { :response => { :at => DateTime.new(2012, 03, 22, 16, 22, 33) } }
159
+
160
+ soap_response.map_soap_response.should == result
125
161
  end
126
162
 
127
- it "converts Hash values matching 'true' to TrueClass" do
128
- { "response" => { "active" => "false" } }.map_soap_response.
129
- should == { :response => { :active => false } }
163
+ it "should convert Hash values matching 'true' to TrueClass" do
164
+ soap_response = { "response" => { "active" => "false" } }
165
+ result = { :response => { :active => false } }
166
+
167
+ soap_response.map_soap_response.should == result
130
168
  end
131
169
 
132
- it "converts Hash values matching 'false' to FalseClass" do
133
- { "response" => { "active" => "true" } }.map_soap_response.
134
- should == { :response => { :active => true } }
170
+ it "should convert Hash values matching 'false' to FalseClass" do
171
+ soap_response = { "response" => { "active" => "true" } }
172
+ result = { :response => { :active => true } }
173
+
174
+ soap_response.map_soap_response.should == result
135
175
  end
136
176
  end
137
177
 
@@ -29,7 +29,7 @@ describe Object do
29
29
  DateTime.new(2012, 03, 22, 16, 22, 33)
30
30
  end
31
31
 
32
- singleton.to_soap_value.should == "2012-03-22T16:22:33"
32
+ singleton.to_soap_value.should == "2012-03-22T16:22:33Z"
33
33
  end
34
34
 
35
35
  it "calls to_s unless the Object responds to to_datetime" do
@@ -30,6 +30,21 @@ describe String do
30
30
  end
31
31
  end
32
32
 
33
+ describe "starts_with?" do
34
+ it "should return whether it starts with a given suffix" do
35
+ "authenticate".starts_with?("auth").should be_true
36
+ "authenticate".starts_with?("cate").should be_false
37
+ end
38
+ end
39
+
40
+ describe "ends_with?" do
41
+ it "should return whether it ends with a given suffix" do
42
+ "authenticate!".ends_with?("!").should be_true
43
+ "authenticate".ends_with?("cate").should be_true
44
+ "authenticate".ends_with?("?").should be_false
45
+ end
46
+ end
47
+
33
48
  describe "strip_namespace" do
34
49
  it "strips the namespace from a namespaced String" do
35
50
  "ns:customer".strip_namespace.should == "customer"
@@ -60,8 +75,12 @@ describe String do
60
75
  end
61
76
 
62
77
  describe "to_soap_value" do
63
- it "calls to_s, bypassing Rails to_datetime extension for Strings" do
64
- "string".to_soap_value.should == "string".to_s
78
+ it "should return the string value and escape special characters" do
79
+ "string".to_soap_value.should == "string"
80
+ "<tag>".to_soap_value.should == "&lt;tag&gt;"
81
+ "at&t".to_soap_value.should == "at&amp;t"
82
+ '"quotes"'.to_soap_value.should == "&quot;quotes&quot;"
83
+ "'apos'".to_soap_value.should == "&apos;apos&apos;"
65
84
  end
66
85
  end
67
86
 
@@ -10,6 +10,10 @@ describe URI::HTTP do
10
10
  it "returns false for non-https URI's" do
11
11
  URI("http://example.com").ssl?.should be_false
12
12
  end
13
+
14
+ it "returns nil for invalid URI's without a scheme" do
15
+ URI("example").ssl?.should be_nil
16
+ end
13
17
  end
14
18
 
15
19
  end
@@ -4,10 +4,8 @@ describe Savon::Request do
4
4
  before { @request = Savon::Request.new EndpointHelper.wsdl_endpoint }
5
5
 
6
6
  it "contains the ContentType for each supported SOAP version" do
7
- Savon::SOAPVersions.each do |soap_version|
8
- Savon::Request::ContentType[soap_version].should be_a(String)
9
- Savon::Request::ContentType[soap_version].should_not be_empty
10
- end
7
+ content_type = { 1 => "text/xml;charset=UTF-8", 2 => "application/soap+xml;charset=UTF-8" }
8
+ content_type.each { |version, type| Savon::Request::ContentType[version].should == type }
11
9
  end
12
10
 
13
11
  # defaults to log request and response. disabled for spec execution
@@ -24,8 +22,8 @@ describe Savon::Request do
24
22
  end
25
23
 
26
24
  it "has both getter and setter for the logger to use (global setting)" do
27
- Savon::Request.logger = nil
28
- Savon::Request.logger.should be_nil
25
+ Savon::Request.logger = {}
26
+ Savon::Request.logger.should be_a(Hash)
29
27
  Savon::Request.logger = Logger.new STDOUT
30
28
  end
31
29
 
@@ -78,12 +76,18 @@ describe Savon::Request do
78
76
  end
79
77
 
80
78
  it "executes a SOAP request and returns the Net::HTTP response" do
81
- soap = Savon::SOAP.new
82
- soap.endpoint = URI EndpointHelper.wsdl_endpoint
79
+ operation = WSDLFixture.authentication(:operations)[:authenticate]
80
+ action, input = operation[:action], operation[:input]
81
+ soap = Savon::SOAP.new action, input, EndpointHelper.soap_endpoint
83
82
  soap_response = @request.soap soap
84
83
 
85
84
  soap_response.should be_a(Net::HTTPResponse)
86
85
  soap_response.body.should == ResponseFixture.authentication
87
86
  end
88
87
 
88
+ it "should not include host when creating HTTP requests" do
89
+ request = @request.send(:request, :wsdl)
90
+ request.path.should_not include("example.com")
91
+ end
92
+
89
93
  end
@@ -2,170 +2,200 @@ require "spec_helper"
2
2
 
3
3
  describe Savon::SOAP do
4
4
  before do
5
- @soap = Savon::SOAP.new
6
- @soap.action = WSDLFixture.authentication(:operations)[:authenticate][:action]
5
+ @operation = WSDLFixture.authentication(:operations)[:authenticate]
6
+ @action, @input = @operation[:action], @operation[:input]
7
+ @soap = Savon::SOAP.new @action, @input, EndpointHelper.soap_endpoint
7
8
  end
8
9
 
9
- it "contains the SOAP namespace for each supported SOAP version" do
10
- Savon::SOAPVersions.each do |soap_version|
11
- Savon::SOAP::SOAPNamespace[soap_version].should be_a(String)
12
- Savon::SOAP::SOAPNamespace[soap_version].should_not be_empty
10
+ it "should contain the SOAP namespace for each supported SOAP version" do
11
+ Savon::SOAP::Versions.each do |soap_version|
12
+ Savon::SOAP::Namespace[soap_version].should be_a(String)
13
+ Savon::SOAP::Namespace[soap_version].should_not be_empty
13
14
  end
14
15
  end
15
16
 
16
- it "contains the Content-Types for each supported SOAP version" do
17
- Savon::SOAPVersions.each do |soap_version|
17
+ it "should contain the Content-Types for each supported SOAP version" do
18
+ Savon::SOAP::Versions.each do |soap_version|
18
19
  Savon::SOAP::ContentType[soap_version].should be_a(String)
19
20
  Savon::SOAP::ContentType[soap_version].should_not be_empty
20
21
  end
21
22
  end
22
23
 
23
- it "defaults to SOAP 1.1" do
24
- Savon::SOAP.version.should == 1
24
+ it "should contain an Array of supported SOAP versions" do
25
+ Savon::SOAP::Versions.should be_an(Array)
26
+ Savon::SOAP::Versions.should_not be_empty
25
27
  end
26
28
 
27
- it "has both getter and setter for the SOAP version to use (global setting)" do
28
- [2, 1].each do |soap_version|
29
- Savon::SOAP.version = soap_version
30
- Savon::SOAP.version.should == soap_version
31
- end
32
- end
29
+ it "should contain the xs:dateTime format" do
30
+ Savon::SOAP::DateTimeFormat.should be_a(String)
31
+ Savon::SOAP::DateTimeFormat.should_not be_empty
33
32
 
34
- it "has a setter for the Savon::WSSE" do
35
- @soap.wsse = Savon::WSSE.new
33
+ DateTime.new(2012, 03, 22, 16, 22, 33).strftime(Savon::SOAP::DateTimeFormat).
34
+ should == "2012-03-22T16:22:33Z"
36
35
  end
37
36
 
38
- it "is has both getter and setter for the SOAP action" do
39
- @soap.action.should == WSDLFixture.authentication(:operations)[:authenticate][:action]
40
-
41
- @soap.action = "someAction"
42
- @soap.action.should == "someAction"
37
+ it "should contain a Regexp matching the xs:dateTime format" do
38
+ Savon::SOAP::DateTimeRegexp.should be_a(Regexp)
39
+ (Savon::SOAP::DateTimeRegexp === "2012-03-22T16:22:33").should be_true
43
40
  end
44
41
 
45
- it "has a setter for the SOAP input" do
46
- @soap.input = "FindUserRequest"
42
+ it "should default to SOAP 1.1" do
43
+ Savon::SOAP.version.should == 1
47
44
  end
48
45
 
49
- it "has both getter and setter for global SOAP headers" do
50
- header = { "some" => "header" }
51
- Savon::SOAP.header = header
52
- Savon::SOAP.header.should == header
46
+ describe "xml returned via to_xml" do
47
+ before do
48
+ @xml_declaration = '<?xml version="1.0" encoding="UTF-8"?>'
49
+ @namespace = { "xmlns:ns" => "http://example.com" }
50
+ @namespace_string = 'xmlns:ns="http://example.com"'
51
+ @namespaces = { "xmlns:ns" => "http://ns.example.com", "xmlns:ns2" => "http://ns2.example.com" }
52
+
53
+ # reset to defaults
54
+ Savon::SOAP.version = 1
55
+ Savon::SOAP.header = {}
56
+ Savon::SOAP.namespaces = {}
57
+ end
53
58
 
54
- Savon::SOAP.header = {}
55
- end
59
+ it "should contain an xml declaration" do
60
+ @soap.to_xml.should include(@xml_declaration)
61
+ end
56
62
 
57
- it "has both getter and setter for the SOAP header" do
58
- @soap.header.should be_a(Hash)
59
- @soap.header.should be_empty
63
+ # namespaces
60
64
 
61
- @soap.header = { "specialAuthKey" => "secret" }
62
- @soap.header.should == { "specialAuthKey" => "secret" }
63
- end
65
+ it "should contain the namespace for SOAP 1.1" do
66
+ @soap.to_xml.should include('xmlns:env="' + Savon::SOAP::Namespace[1] + '"')
67
+ end
64
68
 
65
- it "has a getter for the SOAP body, expecting a Hash or an XML String" do
66
- @soap.body = { :id => 666 }
67
- @soap.body = "<id>666</id>"
68
- end
69
+ it "should contain the namespace for SOAP 1.2 when defined globally" do
70
+ Savon::SOAP.version = 2
71
+ @soap.to_xml.should include('xmlns:env="' + Savon::SOAP::Namespace[2] + '"')
72
+ end
69
73
 
70
- it "has a setter for specifying a Hash of namespaces" do
71
- namespaces = { "xmlns:env" => "http://example.com" }
72
- @soap.namespaces = namespaces
73
- @soap.namespaces.should == namespaces
74
- end
74
+ it "should contain the namespace for SOAP 1.2 when defined per request" do
75
+ @soap.version = 2
76
+ @soap.to_xml.should include('xmlns:env="' + Savon::SOAP::Namespace[2] + '"')
77
+ end
75
78
 
76
- describe "has a getter for namespaces" do
77
- it "which defaults to include the SOAP 1.1 namespace" do
78
- @soap.namespaces.should == { "xmlns:env" => Savon::SOAP::SOAPNamespace[1] }
79
+ it "should containg a xmlns:wsdl namespace defined via the :namespace shortcut method" do
80
+ @soap.namespace = "http://wsdl.example.com"
81
+ @soap.to_xml.should include('xmlns:wsdl="http://wsdl.example.com"')
79
82
  end
80
83
 
81
- it "which contains the SOAP 1.2 namespace if specified" do
82
- @soap.version = 2
83
- @soap.namespaces.should == { "xmlns:env" => Savon::SOAP::SOAPNamespace[2] }
84
+ it "should accept custom namespaces when defined globally" do
85
+ Savon::SOAP.namespaces = @namespace
86
+ @soap.to_xml.should include("<env:Envelope " + @namespace_string)
84
87
  end
85
- end
86
88
 
87
- it "has both getter and setter for global namespaces" do
88
- namespaces = { "some" => "namespace" }
89
- Savon::SOAP.namespaces = namespaces
90
- Savon::SOAP.namespaces.should == namespaces
89
+ it "should accept custom namespaces when defined per request" do
90
+ @soap.namespaces = @namespace
91
+ @soap.to_xml.should include("<env:Envelope " + @namespace_string)
92
+ end
91
93
 
92
- Savon::SOAP.namespaces = {}
93
- end
94
+ it "should merge global and per request namespaces" do
95
+ Savon::SOAP.namespaces = @namespaces
96
+ @soap.namespaces = @namespace
97
+ @soap.to_xml.should include(
98
+ 'xmlns:ns="http://example.com"',
99
+ 'xmlns:ns2="http://ns2.example.com"'
100
+ )
101
+ end
94
102
 
95
- it "has a convenience method for setting the 'xmlns:wsdl' namespace" do
96
- @soap.namespaces.should == { "xmlns:env" => "http://schemas.xmlsoap.org/soap/envelope/" }
103
+ # header
97
104
 
98
- @soap.namespace = "http://example.com"
99
- @soap.namespaces.should include("xmlns:env" => "http://schemas.xmlsoap.org/soap/envelope/")
100
- @soap.namespaces.should include("xmlns:wsdl" => "http://example.com")
101
- end
105
+ it "should not contain a header tag unless specified" do
106
+ @soap.to_xml.should_not include("<env:Header>")
107
+ end
102
108
 
103
- it "has both getter and setter for the SOAP endpoint" do
104
- @soap.endpoint.should be_nil
109
+ it "should accept a custom (String) header defined globally" do
110
+ Savon::SOAP.header = "<key>value</key>"
111
+ @soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
112
+ end
105
113
 
106
- soap_endpoint = URI EndpointHelper.soap_endpoint
107
- @soap.endpoint = soap_endpoint
108
- @soap.endpoint.should == soap_endpoint
109
- end
114
+ it "should accept a custom (Hash) header defined globally" do
115
+ Savon::SOAP.header[:key] = "value"
116
+ @soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
117
+ end
110
118
 
111
- it "has a getter for the SOAP version to use which defaults to SOAP 1.1" do
112
- @soap.version.should == Savon::SOAP.version
113
- end
119
+ it "should accept a custom (String) header defined per request" do
120
+ @soap.header = "<key>value</key>"
121
+ @soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
122
+ end
114
123
 
115
- it "has a setter for specifying the SOAP version to use" do
116
- @soap.version = 2
117
- @soap.version.should == 2
118
- end
124
+ it "should accept a custom (Hash) header defined per request" do
125
+ @soap.header[:key] = "value"
126
+ @soap.to_xml.should include("<env:Header><key>value</key></env:Header>")
127
+ end
119
128
 
120
- describe "to_xml" do
121
- after { Savon::SOAP.version = 1 }
129
+ it "should merge global and per request headers defined as Strings" do
130
+ Savon::SOAP.header = "<key2>other value</key2>"
131
+ @soap.header = "<key>value</key>"
132
+ @soap.to_xml.should include(
133
+ "<env:Header><key2>other value</key2><key>value</key></env:Header>"
134
+ )
135
+ end
122
136
 
123
- it "returns the XML for a SOAP request" do
124
- @soap.namespaces["xmlns:wsdl"] = "http://v1_0.ws.auth.order.example.com/"
125
- @soap.body = { :id => 666 }
137
+ it "should merge global and per request headers defined as Hashes" do
138
+ Savon::SOAP.header = { :key => "value", :key2 => "global value" }
139
+ @soap.header[:key2] = "request value"
140
+ @soap.to_xml.should include(
141
+ "<env:Header><key>value</key><key2>request value</key2></env:Header>"
142
+ )
143
+ end
126
144
 
127
- @soap.to_xml.should include('xmlns:wsdl="http://v1_0.ws.auth.order.example.com/"')
128
- @soap.to_xml.should include('xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"')
129
- @soap.to_xml.should include('<wsdl:authenticate><id>666</id></wsdl:authenticate>')
145
+ it "should use the :header method from a given WSSE object to include a WSSE header" do
146
+ wsse = "some compliant object"
147
+ wsse.stubs(:header).returns("<wsse>authentication</wsse>")
148
+
149
+ @soap.wsse = wsse
150
+ @soap.to_xml.should include("<env:Header><wsse>authentication</wsse></env:Header>")
130
151
  end
131
152
 
132
- it "caches the XML, returning the same Object every time" do
133
- @soap.to_xml.object_id.should == @soap.to_xml.object_id
153
+ # input tag
154
+
155
+ it "should contain a :wsdl namespaced input tag matching the :input property on instantiation" do
156
+ @soap = Savon::SOAP.new "someAction", "someInput", EndpointHelper.soap_endpoint
157
+ @soap.to_xml.should include('<wsdl:someInput>')
134
158
  end
135
159
 
136
- it "uses the SOAP namespace for the specified SOAP version" do
137
- @soap.version = 2
138
- @soap.to_xml.should include(Savon::SOAP::SOAPNamespace[2])
160
+ it "should fall back to using the :action property whem :input is blank" do
161
+ @soap = Savon::SOAP.new "someAction", "", EndpointHelper.soap_endpoint
162
+ @soap.to_xml.should include('<wsdl:someAction>')
139
163
  end
140
164
 
141
- it "uses the SOAP namespace for the default SOAP version otherwise" do
142
- Savon::SOAP.version = 2
143
- @soap.to_xml.should include(Savon::SOAP::SOAPNamespace[2])
165
+ it "should containg namespaces defined via an input tag Array containing the tag name and a Hash of namespaces" do
166
+ input = ["someInput", { "otherNs" => "http://otherns.example.com" }]
167
+ @soap = Savon::SOAP.new "someAction", input, EndpointHelper.soap_endpoint
168
+ @soap.to_xml.should include('<wsdl:someInput otherNs="http://otherns.example.com">')
144
169
  end
145
170
 
146
- it "merges global and per request headers defined as Hashes" do
147
- Savon::SOAP.header = { "API-KEY" => "secret", "SOME-KEY" => "something" }
148
- @soap.header["SOME-KEY"] = "somethingelse"
171
+ # xml body
172
+
173
+ it "should contain the SOAP body defined as a Hash" do
174
+ @soap.body = { :someTag => "some value" }
175
+ @soap.to_xml.should include("<someTag>some value</someTag>")
176
+ end
149
177
 
150
- @soap.to_xml.should include("<API-KEY>secret</API-KEY>")
151
- @soap.to_xml.should include("<SOME-KEY>somethingelse</SOME-KEY>")
178
+ it "should contain the SOAP body defined as an Object responding to :to_s" do
179
+ @soap.body = "<someTag>some value</someTag>"
180
+ @soap.to_xml.should include(@soap.body)
152
181
  end
153
182
 
154
- it "joins global and per request headers defined as Strings" do
155
- Savon::SOAP.header = "<API-KEY>secret</API-KEY>"
156
- @soap.header = "<SOME-KEY>somethingelse</SOME-KEY>"
183
+ # xml
157
184
 
158
- @soap.to_xml.should include("<API-KEY>secret</API-KEY>")
159
- @soap.to_xml.should include("<SOME-KEY>somethingelse</SOME-KEY>")
185
+ it "should be a completely custom XML when specified" do
186
+ @soap.xml = "custom SOAP body"
187
+ @soap.to_xml.should == @soap.xml
160
188
  end
161
189
 
162
- it "merges the global and per request namespaces" do
163
- Savon::SOAP.namespaces = { "xmlns:wsdl" => "namespace", "xmlns:v1" => "v1namespace" }
164
- @soap.namespaces["xmlns:v1"] = "newV1namespace"
190
+ # safety check
165
191
 
166
- @soap.to_xml.should include('xmlns:wsdl="namespace"')
167
- @soap.to_xml.should include('xmlns:v1="newV1namespace"')
192
+ it "should be a valid SOAP request" do
193
+ @soap.to_xml.should include(
194
+ @xml_declaration +
195
+ '<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">' <<
196
+ '<env:Body><wsdl:authenticate></wsdl:authenticate></env:Body>' <<
197
+ '</env:Envelope>'
198
+ )
168
199
  end
169
200
  end
170
-
171
- end
201
+ end