savon 0.7.9 → 0.8.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. data/.gitignore +9 -0
  2. data/.rspec +1 -0
  3. data/.yardopts +2 -0
  4. data/CHANGELOG.md +332 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE +20 -0
  7. data/README.md +37 -0
  8. data/Rakefile +28 -39
  9. data/autotest/discover.rb +1 -0
  10. data/lib/savon.rb +10 -31
  11. data/lib/savon/client.rb +116 -98
  12. data/lib/savon/core_ext/array.rb +36 -22
  13. data/lib/savon/core_ext/datetime.rb +15 -6
  14. data/lib/savon/core_ext/hash.rb +122 -94
  15. data/lib/savon/core_ext/object.rb +19 -11
  16. data/lib/savon/core_ext/string.rb +62 -57
  17. data/lib/savon/core_ext/symbol.rb +13 -5
  18. data/lib/savon/error.rb +6 -0
  19. data/lib/savon/global.rb +75 -0
  20. data/lib/savon/http/error.rb +42 -0
  21. data/lib/savon/soap.rb +8 -283
  22. data/lib/savon/soap/fault.rb +48 -0
  23. data/lib/savon/soap/request.rb +61 -0
  24. data/lib/savon/soap/response.rb +65 -0
  25. data/lib/savon/soap/xml.rb +132 -0
  26. data/lib/savon/version.rb +2 -2
  27. data/lib/savon/wsdl/document.rb +107 -0
  28. data/lib/savon/wsdl/parser.rb +90 -0
  29. data/lib/savon/wsdl/request.rb +35 -0
  30. data/lib/savon/wsse.rb +42 -104
  31. data/savon.gemspec +26 -0
  32. data/spec/fixtures/response/response_fixture.rb +26 -26
  33. data/spec/fixtures/response/xml/list.xml +18 -0
  34. data/spec/fixtures/wsdl/wsdl_fixture.rb +6 -0
  35. data/spec/fixtures/wsdl/wsdl_fixture.yml +4 -4
  36. data/spec/savon/client_spec.rb +274 -51
  37. data/spec/savon/core_ext/datetime_spec.rb +1 -1
  38. data/spec/savon/core_ext/hash_spec.rb +40 -4
  39. data/spec/savon/core_ext/object_spec.rb +1 -1
  40. data/spec/savon/core_ext/string_spec.rb +0 -12
  41. data/spec/savon/http/error_spec.rb +52 -0
  42. data/spec/savon/savon_spec.rb +90 -0
  43. data/spec/savon/soap/fault_spec.rb +80 -0
  44. data/spec/savon/soap/request_spec.rb +45 -0
  45. data/spec/savon/soap/response_spec.rb +153 -0
  46. data/spec/savon/soap/xml_spec.rb +249 -0
  47. data/spec/savon/soap_spec.rb +4 -177
  48. data/spec/savon/{wsdl_spec.rb → wsdl/document_spec.rb} +54 -17
  49. data/spec/savon/wsdl/request_spec.rb +15 -0
  50. data/spec/savon/wsse_spec.rb +123 -92
  51. data/spec/spec_helper.rb +19 -4
  52. data/spec/support/endpoint.rb +25 -0
  53. metadata +97 -97
  54. data/.autotest +0 -5
  55. data/CHANGELOG +0 -176
  56. data/README.rdoc +0 -64
  57. data/lib/savon/core_ext.rb +0 -8
  58. data/lib/savon/core_ext/net_http.rb +0 -19
  59. data/lib/savon/core_ext/uri.rb +0 -10
  60. data/lib/savon/logger.rb +0 -56
  61. data/lib/savon/request.rb +0 -138
  62. data/lib/savon/response.rb +0 -174
  63. data/lib/savon/wsdl.rb +0 -137
  64. data/lib/savon/wsdl_stream.rb +0 -85
  65. data/spec/basic_spec_helper.rb +0 -11
  66. data/spec/endpoint_helper.rb +0 -23
  67. data/spec/http_stubs.rb +0 -26
  68. data/spec/integration/http_basic_auth_spec.rb +0 -16
  69. data/spec/integration/server.rb +0 -51
  70. data/spec/savon/core_ext/net_http_spec.rb +0 -38
  71. data/spec/savon/core_ext/uri_spec.rb +0 -19
  72. data/spec/savon/request_spec.rb +0 -117
  73. data/spec/savon/response_spec.rb +0 -179
  74. data/spec/spec.opts +0 -4
@@ -0,0 +1,249 @@
1
+ require "spec_helper"
2
+
3
+ describe Savon::SOAP::XML do
4
+ let(:xml) { Savon::SOAP::XML.new Endpoint.soap, :authenticate, :id => 1 }
5
+
6
+ describe ".to_hash" do
7
+ it "should return a given SOAP response body as a Hash" do
8
+ hash = Savon::SOAP::XML.to_hash ResponseFixture.authentication
9
+ hash[:authenticate_response][:return].should ==
10
+ ResponseFixture.authentication(:to_hash)
11
+ end
12
+
13
+ it "should return a Hash for a SOAP multiRef response" do
14
+ hash = Savon::SOAP::XML.to_hash ResponseFixture.multi_ref
15
+
16
+ hash[:list_response].should be_a(Hash)
17
+ hash[:multi_ref].should be_an(Array)
18
+ end
19
+
20
+ it "should add existing namespaced elements as an array" do
21
+ hash = Savon::SOAP::XML.to_hash ResponseFixture.list
22
+
23
+ hash[:multi_namespaced_entry_response][:history].should be_a(Hash)
24
+ hash[:multi_namespaced_entry_response][:history][:case].should be_an(Array)
25
+ end
26
+ end
27
+
28
+ describe ".new" do
29
+ it "should accept an endpoint, an input tag and a SOAP body" do
30
+ xml = Savon::SOAP::XML.new Endpoint.soap, :authentication, :id => 1
31
+
32
+ xml.endpoint.should == Endpoint.soap
33
+ xml.input.should == :authentication
34
+ xml.body.should == { :id => 1 }
35
+ end
36
+ end
37
+
38
+ describe "#input" do
39
+ it "should set the input tag" do
40
+ xml.input = :test
41
+ xml.input.should == :test
42
+ end
43
+ end
44
+
45
+ describe "#endpoint" do
46
+ it "should set the endpoint to use" do
47
+ xml.endpoint = "http://test.com"
48
+ xml.endpoint.should == "http://test.com"
49
+ end
50
+ end
51
+
52
+ describe "#version" do
53
+ it "should default to SOAP 1.1" do
54
+ xml.version.should == 1
55
+ end
56
+
57
+ it "should default to the global default" do
58
+ Savon.soap_version = 2
59
+ xml.version.should == 2
60
+
61
+ reset_soap_version
62
+ end
63
+
64
+ it "should set the SOAP version to use" do
65
+ xml.version = 2
66
+ xml.version.should == 2
67
+ end
68
+
69
+ it "should raise an ArgumentError in case of an invalid version" do
70
+ lambda { xml.version = 3 }.should raise_error(ArgumentError)
71
+ end
72
+ end
73
+
74
+ describe "#header" do
75
+ it "should default to an empty Hash" do
76
+ xml.header.should == {}
77
+ end
78
+
79
+ it "should set the SOAP header" do
80
+ xml.header = { "MySecret" => "abc" }
81
+ xml.header.should == { "MySecret" => "abc" }
82
+ end
83
+ end
84
+
85
+ describe "#namespaces" do
86
+ it "should default to a Hash containing the namespace for SOAP 1.1" do
87
+ xml.namespaces.should == { "xmlns:env" => "http://schemas.xmlsoap.org/soap/envelope/" }
88
+ end
89
+
90
+ it "should default to a Hash containing the namespace for SOAP 1.2 if that's the current version" do
91
+ xml.version = 2
92
+ xml.namespaces.should == { "xmlns:env" => "http://www.w3.org/2003/05/soap-envelope" }
93
+ end
94
+
95
+ it "should set the SOAP header" do
96
+ xml.namespaces = { "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" }
97
+ xml.namespaces.should == { "xmlns:xsd" => "http://www.w3.org/2001/XMLSchema" }
98
+ end
99
+ end
100
+
101
+ describe "#wsse" do
102
+ it "should set the Savon::WSSE object" do
103
+ xml.wsse = Savon::WSSE.new
104
+ xml.wsse.should be_a(Savon::WSSE)
105
+ end
106
+ end
107
+
108
+ describe "#body" do
109
+ it "should set the SOAP body Hash" do
110
+ xml.body = { :id => 1 }
111
+ xml.to_xml.should include("<id>1</id>")
112
+ end
113
+
114
+ it "should also accepts an XML String" do
115
+ xml.body = "<id>1</id>"
116
+ xml.to_xml.should include("<id>1</id>")
117
+ end
118
+ end
119
+
120
+ describe "#xml" do
121
+ it "lets you specify a completely custom XML String" do
122
+ xml.xml = "<custom>xml</custom>"
123
+ xml.to_xml.should == "<custom>xml</custom>"
124
+ end
125
+
126
+ it "yields a Builder::XmlMarkup object to a given block" do
127
+ xml.xml { |xml| xml.using("Builder") }
128
+ xml.to_xml.should == '<?xml version="1.0" encoding="UTF-8"?><using>Builder</using>'
129
+ end
130
+ end
131
+
132
+ describe "#to_xml" do
133
+ after { reset_soap_version }
134
+
135
+ context "by default" do
136
+ it "should start with an XML declaration" do
137
+ xml.to_xml.should match(/^<\?xml version="1.0" encoding="UTF-8"\?>/)
138
+ end
139
+
140
+ it "should add the xsd namespace" do
141
+ uri = "http://www.w3.org/2001/XMLSchema"
142
+ xml.to_xml.should match(/<env:Envelope (.*)xmlns:xsd="#{uri}"(.*)>/)
143
+ end
144
+
145
+ it "should add the xsi namespace" do
146
+ uri = "http://www.w3.org/2001/XMLSchema-instance"
147
+ xml.to_xml.should match(/<env:Envelope (.*)xmlns:xsi="#{uri}"(.*)>/)
148
+ end
149
+
150
+ it "should have a SOAP envelope tag with a SOAP 1.1 namespace" do
151
+ uri = "http://schemas.xmlsoap.org/soap/envelope/"
152
+ xml.to_xml.should match(/<env:Envelope (.*)xmlns:env="#{uri}"(.*)>/)
153
+ end
154
+
155
+ it "should have a SOAP body containing the SOAP input tag and body Hash" do
156
+ xml.to_xml.should include('<env:Body><authenticate><id>1</id></authenticate></env:Body>')
157
+ end
158
+
159
+ it "should accept a SOAP body as an XML String" do
160
+ xml.body = "<someId>1</someId>"
161
+ xml.to_xml.should include('<env:Body><authenticate><someId>1</someId></authenticate></env:Body>')
162
+ end
163
+
164
+ it "should not contain a SOAP header" do
165
+ xml.to_xml.should_not include('<env:Header')
166
+ end
167
+ end
168
+
169
+ context "with the global SOAP version set to 1.2" do
170
+ it "should contain the namespace for SOAP 1.2" do
171
+ Savon.soap_version = 2
172
+
173
+ uri = "http://www.w3.org/2003/05/soap-envelope"
174
+ xml.to_xml.should match(/<env:Envelope (.*)xmlns:env="#{uri}"(.*)>/)
175
+ reset_soap_version
176
+ end
177
+ end
178
+
179
+ context "with a global and request SOAP version" do
180
+ it "should contain the namespace for the request SOAP version" do
181
+ Savon.soap_version = 2
182
+ xml.version = 1
183
+
184
+ uri = "http://schemas.xmlsoap.org/soap/envelope/"
185
+ xml.to_xml.should match(/<env:Envelope (.*)xmlns:env="#{uri}"(.*)>/)
186
+ reset_soap_version
187
+ end
188
+ end
189
+
190
+ context "using the #namespace and #namespace_identifier" do
191
+ it "should contain the specified namespace" do
192
+ xml.namespace_identifier = :wsdl
193
+ xml.namespace = "http://example.com"
194
+ xml.to_xml.should include('xmlns:wsdl="http://example.com"')
195
+ end
196
+ end
197
+
198
+ context "with WSSE authentication" do
199
+ it "should containg a SOAP header with WSSE authentication details" do
200
+ xml.wsse = Savon::WSSE.new
201
+ xml.wsse.credentials "username", "password"
202
+
203
+ xml.to_xml.should include("<env:Header><wsse:Security")
204
+ xml.to_xml.should include("<wsse:Username>username</wsse:Username>")
205
+ xml.to_xml.should include("password</wsse:Password>")
206
+ end
207
+ end
208
+
209
+ context "with a simple input tag (Symbol)" do
210
+ it "should just add the input tag" do
211
+ xml.input = :simple
212
+ xml.to_xml.should include('<simple><id>1</id></simple>')
213
+ end
214
+ end
215
+
216
+ context "with a simple input tag (Array)" do
217
+ it "should just add the input tag" do
218
+ xml.input = :simple
219
+ xml.to_xml.should include('<simple><id>1</id></simple>')
220
+ end
221
+ end
222
+
223
+ context "with an input tag and a namespace Hash (Array)" do
224
+ it "should contain the input tag with namespaces" do
225
+ xml.input = [:getUser, { "active" => true }]
226
+ xml.to_xml.should include('<getUser active="true"><id>1</id></getUser>')
227
+ end
228
+ end
229
+
230
+ context "with a prefixed input tag (Array)" do
231
+ it "should contain a prefixed input tag" do
232
+ xml.input = [:wsdl, :getUser]
233
+ xml.to_xml.should include('<wsdl:getUser><id>1</id></wsdl:getUser>')
234
+ end
235
+ end
236
+
237
+ context "with a prefixed input tag and a namespace Hash (Array)" do
238
+ it "should contain a prefixed input tag with namespaces" do
239
+ xml.input = [:wsdl, :getUser, { :only_active => false }]
240
+ xml.to_xml.should include('<wsdl:getUser only_active="false"><id>1</id></wsdl:getUser>')
241
+ end
242
+ end
243
+ end
244
+
245
+ def reset_soap_version
246
+ Savon.soap_version = Savon::SOAP::DefaultVersion
247
+ end
248
+
249
+ end
@@ -1,11 +1,6 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Savon::SOAP do
4
- before do
5
- @operation = WSDLFixture.authentication(:operations)[:authenticate]
6
- @action, @input = @operation[:action], @operation[:input]
7
- @soap = Savon::SOAP.new @action, @input, EndpointHelper.soap_endpoint
8
- end
9
4
 
10
5
  it "should contain the SOAP namespace for each supported SOAP version" do
11
6
  Savon::SOAP::Versions.each do |soap_version|
@@ -14,16 +9,8 @@ describe Savon::SOAP do
14
9
  end
15
10
  end
16
11
 
17
- it "should contain the Content-Types for each supported SOAP version" do
18
- Savon::SOAP::Versions.each do |soap_version|
19
- Savon::SOAP::ContentType[soap_version].should be_a(String)
20
- Savon::SOAP::ContentType[soap_version].should_not be_empty
21
- end
22
- end
23
-
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
12
+ it "should contain a Rage of supported SOAP versions" do
13
+ Savon::SOAP::Versions.should == (1..2)
27
14
  end
28
15
 
29
16
  it "should contain the xs:dateTime format" do
@@ -31,172 +18,12 @@ describe Savon::SOAP do
31
18
  Savon::SOAP::DateTimeFormat.should_not be_empty
32
19
 
33
20
  DateTime.new(2012, 03, 22, 16, 22, 33).strftime(Savon::SOAP::DateTimeFormat).
34
- should == "2012-03-22T16:22:33Z"
21
+ should == "2012-03-22T16:22:33+00:00"
35
22
  end
36
23
 
37
24
  it "should contain a Regexp matching the xs:dateTime format" do
38
25
  Savon::SOAP::DateTimeRegexp.should be_a(Regexp)
39
26
  (Savon::SOAP::DateTimeRegexp === "2012-03-22T16:22:33").should be_true
40
27
  end
41
-
42
- it "should default to SOAP 1.1" do
43
- Savon::SOAP.version.should == 1
44
- end
45
-
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
58
-
59
- it "should contain an xml declaration" do
60
- @soap.to_xml.should include(@xml_declaration)
61
- end
62
-
63
- # namespaces
64
-
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
68
-
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
73
-
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
78
-
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"')
82
- end
83
-
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)
87
- end
88
-
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
93
-
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
102
-
103
- # header
104
-
105
- it "should not contain a header tag unless specified" do
106
- @soap.to_xml.should_not include("<env:Header>")
107
- end
108
-
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
113
-
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
118
-
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
123
-
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
128
-
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
136
-
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 match(
141
- /<env:Header>(<key>value<\/key><key2>request value<\/key2>|<key2>request value<\/key2><key>value<\/key>)<\/env:Header>/
142
- )
143
- end
144
-
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>")
151
- end
152
-
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>')
158
- end
159
-
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>')
163
- end
164
-
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">')
169
- end
170
-
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
177
-
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)
181
- end
182
-
183
- # xml
184
-
185
- it "should be a completely custom XML when specified" do
186
- @soap.xml = "custom SOAP body"
187
- @soap.to_xml.should == @soap.xml
188
- end
189
-
190
- # safety check
191
-
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
- )
199
- end
200
- end
28
+
201
29
  end
202
-