savon 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/savon.rb +12 -22
- data/lib/savon/client.rb +26 -63
- data/lib/savon/core_ext.rb +3 -6
- data/lib/savon/core_ext/hash.rb +0 -12
- data/lib/savon/core_ext/string.rb +5 -0
- data/lib/savon/request.rb +17 -15
- data/lib/savon/response.rb +109 -0
- data/lib/savon/soap.rb +67 -33
- data/lib/savon/wsdl.rb +25 -18
- data/lib/savon/wsse.rb +59 -54
- data/spec/fixtures/user_fixture.rb +16 -4
- data/spec/savon/client_spec.rb +20 -129
- data/spec/savon/core_ext/hash_spec.rb +0 -26
- data/spec/savon/core_ext/string_spec.rb +12 -0
- data/spec/savon/request_spec.rb +9 -10
- data/spec/savon/response_spec.rb +133 -0
- data/spec/savon/savon_spec.rb +1 -8
- data/spec/savon/soap_spec.rb +86 -47
- data/spec/savon/wsdl_spec.rb +19 -8
- data/spec/savon/wsse_spec.rb +73 -84
- metadata +5 -5
- data/lib/savon/validation.rb +0 -57
- data/spec/savon/validation_spec.rb +0 -88
@@ -95,32 +95,6 @@ describe Hash do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
describe "to_soap_fault_message" do
|
99
|
-
it "returns a SOAP fault message for SOAP version 1" do
|
100
|
-
soap_fault = {
|
101
|
-
"faultcode" => "soap:Server",
|
102
|
-
"faultstring" => "Fault occurred while processing."
|
103
|
-
}
|
104
|
-
|
105
|
-
soap_fault.to_soap_fault_message.should be_a String
|
106
|
-
soap_fault.to_soap_fault_message.should_not be_empty
|
107
|
-
end
|
108
|
-
|
109
|
-
it "returns a SOAP fault message for SOAP version 2" do
|
110
|
-
soap_fault = {
|
111
|
-
"code" => { "value" => "soap:Server" },
|
112
|
-
"reason" => { "text" => "Fault occurred while processing." }
|
113
|
-
}
|
114
|
-
|
115
|
-
soap_fault.to_soap_fault_message.should be_a String
|
116
|
-
soap_fault.to_soap_fault_message.should_not be_empty
|
117
|
-
end
|
118
|
-
|
119
|
-
it "returns nil in case the Hash does not include a SOAP fault" do
|
120
|
-
{ :soap_fault => false }.to_soap_fault_message.should be_nil
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
98
|
describe "map_soap_response" do
|
125
99
|
it "converts Hash key Strings to snake_case Symbols" do
|
126
100
|
{ "userResponse" => { "accountStatus" => "active" } }.map_soap_response.
|
@@ -2,6 +2,18 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe String do
|
4
4
|
|
5
|
+
describe "self.random" do
|
6
|
+
it "returns a random 100-character String" do
|
7
|
+
String.random.should be_a String
|
8
|
+
String.random.length.should == 100
|
9
|
+
end
|
10
|
+
|
11
|
+
it "returns a random String of a given length" do
|
12
|
+
String.random(50).should be_a String
|
13
|
+
String.random(50).length.should == 50
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
5
17
|
describe "snakecase" do
|
6
18
|
it "converts a lowerCamelCase String to snakecase" do
|
7
19
|
"lowerCamelCase".snakecase.should == "lower_camel_case"
|
data/spec/savon/request_spec.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Savon::Request do
|
4
|
-
before { @request =
|
4
|
+
before { @request = some_request_instance }
|
5
5
|
|
6
|
-
def
|
6
|
+
def some_request_instance
|
7
7
|
Savon::Request.new SpecHelper.some_endpoint
|
8
8
|
end
|
9
9
|
|
10
|
+
def some_soap_instance(options = {})
|
11
|
+
Savon::SOAP.new UserFixture.soap_actions[:find_user]
|
12
|
+
end
|
13
|
+
|
10
14
|
describe "ContentType" do
|
11
15
|
it "contains the ContentType for each supported SOAP version" do
|
12
16
|
Savon::SOAPVersions.each do |soap_version|
|
@@ -53,7 +57,7 @@ describe Savon::Request do
|
|
53
57
|
|
54
58
|
describe "initialize" do
|
55
59
|
it "expects a SOAP endpoint String" do
|
56
|
-
|
60
|
+
some_request_instance
|
57
61
|
end
|
58
62
|
|
59
63
|
it "raises an ArgumentError in case of an invaluid endpoint" do
|
@@ -78,16 +82,11 @@ describe Savon::Request do
|
|
78
82
|
|
79
83
|
describe "soap" do
|
80
84
|
it "executes a SOAP request and returns the Net::HTTPResponse" do
|
81
|
-
soap_response = @request.soap
|
85
|
+
soap_response = @request.soap some_soap_instance
|
82
86
|
|
83
87
|
soap_response.should be_a Net::HTTPResponse
|
84
88
|
soap_response.body.should == UserFixture.user_response
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
88
|
-
|
89
|
-
Savon::SOAP.new UserFixture.soap_actions[:find_user], { :id => 666 },
|
90
|
-
options, UserFixture.namespace_uri
|
91
|
-
end
|
92
|
-
|
93
|
-
end
|
92
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Savon::Response do
|
4
|
+
before { @response = some_response_instance }
|
5
|
+
|
6
|
+
def some_response_instance
|
7
|
+
Savon::Response.new http_response_mock
|
8
|
+
end
|
9
|
+
|
10
|
+
def soap_fault_response_instance
|
11
|
+
Savon::Response.new http_response_mock(200, UserFixture.soap_fault)
|
12
|
+
end
|
13
|
+
|
14
|
+
def http_error_response_instance
|
15
|
+
Savon::Response.new http_response_mock(404, "", "Not found")
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "@raise_errors" do
|
19
|
+
it "defaults to true" do
|
20
|
+
Savon::Response.raise_errors?.should be_true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has accessor methods" do
|
24
|
+
Savon::Response.raise_errors = false
|
25
|
+
Savon::Response.raise_errors?.should == false
|
26
|
+
Savon::Response.raise_errors = true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "initialize" do
|
31
|
+
it "expects a Net::HTTPResponse" do
|
32
|
+
some_response_instance
|
33
|
+
end
|
34
|
+
|
35
|
+
it "raises a Savon::SOAPFault in case of a SOAP fault" do
|
36
|
+
lambda { soap_fault_response_instance }.should raise_error Savon::SOAPFault
|
37
|
+
end
|
38
|
+
|
39
|
+
it "does not raise a Savon::SOAPFault in case the default is turned off" do
|
40
|
+
Savon::Response.raise_errors = false
|
41
|
+
soap_fault_response_instance
|
42
|
+
Savon::Response.raise_errors = true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "raises a Savon::HTTPError in case of an HTTP error" do
|
46
|
+
lambda { http_error_response_instance }.should raise_error Savon::HTTPError
|
47
|
+
end
|
48
|
+
|
49
|
+
it "does not raise a Savon::HTTPError in case the default is turned off" do
|
50
|
+
Savon::Response.raise_errors = false
|
51
|
+
http_error_response_instance
|
52
|
+
Savon::Response.raise_errors = true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "soap_fault?" do
|
57
|
+
before { Savon::Response.raise_errors = false }
|
58
|
+
|
59
|
+
it "does not return true in case the response seems to be ok" do
|
60
|
+
@response.soap_fault?.should_not be_true
|
61
|
+
end
|
62
|
+
|
63
|
+
it "returns true in case of a SOAP fault" do
|
64
|
+
response = soap_fault_response_instance
|
65
|
+
response.soap_fault?.should be_true
|
66
|
+
end
|
67
|
+
|
68
|
+
after { Savon::Response.raise_errors = true }
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "soap_fault" do
|
72
|
+
before { Savon::Response.raise_errors = false }
|
73
|
+
|
74
|
+
it "returns the SOAP fault message in case of a SOAP fault" do
|
75
|
+
response = soap_fault_response_instance
|
76
|
+
response.soap_fault.should == "(soap:Server) Fault occurred while processing."
|
77
|
+
end
|
78
|
+
|
79
|
+
after { Savon::Response.raise_errors = true }
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "http_error?" do
|
83
|
+
before { Savon::Response.raise_errors = false }
|
84
|
+
|
85
|
+
it "does not return true in case the response seems to be ok" do
|
86
|
+
@response.http_error?.should_not be_true
|
87
|
+
end
|
88
|
+
|
89
|
+
it "returns true in case of an HTTP error" do
|
90
|
+
response = http_error_response_instance
|
91
|
+
response.http_error?.should be_true
|
92
|
+
end
|
93
|
+
|
94
|
+
after { Savon::Response.raise_errors = true }
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "http_error" do
|
98
|
+
before { Savon::Response.raise_errors = false }
|
99
|
+
|
100
|
+
it "returns the HTTP error message in case of an HTTP error" do
|
101
|
+
response = http_error_response_instance
|
102
|
+
response.http_error.should == "Not found (404)"
|
103
|
+
end
|
104
|
+
|
105
|
+
after { Savon::Response.raise_errors = true }
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "to_hash" do
|
109
|
+
it "returns the SOAP response body as a Hash" do
|
110
|
+
@response.to_hash.should == UserFixture.response_hash
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "to_xml" do
|
115
|
+
it "returns the SOAP response body" do
|
116
|
+
@response.to_xml.should == UserFixture.user_response
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "to_s (alias)" do
|
121
|
+
it "returns the SOAP response body" do
|
122
|
+
@response.to_s.should == UserFixture.user_response
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def http_response_mock(code = 200, body = UserFixture.user_response, message = "OK")
|
127
|
+
http_response_mock = mock "Net::HTTPResponse"
|
128
|
+
http_response_mock.stubs :code => code.to_s, :message => message,
|
129
|
+
:content_type => "text/html", :body => body
|
130
|
+
http_response_mock
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
data/spec/savon/savon_spec.rb
CHANGED
@@ -2,13 +2,6 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Savon do
|
4
4
|
|
5
|
-
describe "VERSION" do
|
6
|
-
it "contains the current version of the library" do
|
7
|
-
Savon::VERSION.should be_a String
|
8
|
-
Savon::VERSION.should_not be_empty
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
5
|
describe "SOAPVersions" do
|
13
6
|
it "contains an Array of supported SOAP versions" do
|
14
7
|
Savon::SOAPVersions.should be_an Array
|
@@ -34,4 +27,4 @@ describe Savon do
|
|
34
27
|
end
|
35
28
|
end
|
36
29
|
|
37
|
-
end
|
30
|
+
end
|
data/spec/savon/soap_spec.rb
CHANGED
@@ -1,11 +1,28 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Savon::SOAP do
|
4
|
-
before { @soap =
|
4
|
+
before { @soap = some_soap_instance }
|
5
5
|
|
6
|
-
def
|
7
|
-
Savon::SOAP.new UserFixture.soap_actions[:find_user]
|
8
|
-
|
6
|
+
def some_soap_instance
|
7
|
+
Savon::SOAP.new UserFixture.soap_actions[:find_user]
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "SOAPNamespace" do
|
11
|
+
it "contains the SOAP namespace for each supported SOAP version" do
|
12
|
+
Savon::SOAPVersions.each do |soap_version|
|
13
|
+
Savon::SOAP::SOAPNamespace[soap_version].should be_a String
|
14
|
+
Savon::SOAP::SOAPNamespace[soap_version].should_not be_empty
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "ContentType" do
|
20
|
+
it "contains the Content-Types for each supported SOAP version" do
|
21
|
+
Savon::SOAPVersions.each do |soap_version|
|
22
|
+
Savon::SOAP::ContentType[soap_version].should be_a String
|
23
|
+
Savon::SOAP::ContentType[soap_version].should_not be_empty
|
24
|
+
end
|
25
|
+
end
|
9
26
|
end
|
10
27
|
|
11
28
|
describe "@version" do
|
@@ -14,7 +31,7 @@ describe Savon::SOAP do
|
|
14
31
|
end
|
15
32
|
|
16
33
|
it "has accessor methods" do
|
17
|
-
[
|
34
|
+
[2, 1].each do |soap_version|
|
18
35
|
Savon::SOAP.version = soap_version
|
19
36
|
Savon::SOAP.version.should == soap_version
|
20
37
|
end
|
@@ -22,42 +39,93 @@ describe Savon::SOAP do
|
|
22
39
|
end
|
23
40
|
|
24
41
|
describe "initialize" do
|
25
|
-
it "expects
|
26
|
-
|
42
|
+
it "expects a SOAP action map" do
|
43
|
+
some_soap_instance
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "wsse" do
|
48
|
+
it "expects a Savon::WSSE" do
|
49
|
+
@soap.wsse = Savon::WSSE.new
|
27
50
|
end
|
28
51
|
end
|
29
52
|
|
30
53
|
describe "action" do
|
31
|
-
it "
|
32
|
-
@soap.action.should == UserFixture.soap_actions[:find_user]
|
54
|
+
it "is an accessor for the SOAP action" do
|
55
|
+
@soap.action.should == UserFixture.soap_actions[:find_user][:name]
|
56
|
+
|
57
|
+
action = "someAction"
|
58
|
+
@soap.action = action
|
59
|
+
@soap.action.should == action
|
33
60
|
end
|
34
61
|
end
|
35
62
|
|
36
|
-
describe "
|
37
|
-
it "
|
38
|
-
@soap.
|
63
|
+
describe "header" do
|
64
|
+
it "is an accessor for the SOAP header" do
|
65
|
+
@soap.header.should be_a Hash
|
66
|
+
@soap.header.should be_empty
|
67
|
+
|
68
|
+
header = { "specialAuthKey" => "secret" }
|
69
|
+
@soap.header = header
|
70
|
+
@soap.header.should == header
|
39
71
|
end
|
40
72
|
end
|
41
73
|
|
42
74
|
describe "body" do
|
75
|
+
it "expects a SOAP-translatable Hash or an XML String" do
|
76
|
+
@soap.body = { :id => 666 }
|
77
|
+
@soap.body = "<id>666</id>"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "namespaces" do
|
82
|
+
it "defaults to a Hash with xmlns:env set to SOAP 1.1" do
|
83
|
+
soap = some_soap_instance
|
84
|
+
soap.namespaces.should == { "xmlns:env" => Savon::SOAP::SOAPNamespace[1] }
|
85
|
+
end
|
86
|
+
|
87
|
+
it "contains the xmlns:env for SOAP 1.2 if specified" do
|
88
|
+
soap = some_soap_instance
|
89
|
+
soap.version = 2
|
90
|
+
soap.namespaces.should == { "xmlns:env" => Savon::SOAP::SOAPNamespace[2] }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "version" do
|
95
|
+
it "returns the SOAP version from options" do
|
96
|
+
soap = some_soap_instance
|
97
|
+
soap.version = 2
|
98
|
+
soap.version.should == 2
|
99
|
+
end
|
100
|
+
|
101
|
+
it "returns the default SOAP version otherwise" do
|
102
|
+
@soap.version.should == Savon::SOAP.version
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe "to_xml" do
|
43
107
|
before { Savon::SOAP.version = 1 }
|
44
108
|
|
45
109
|
it "returns the XML for a SOAP request" do
|
46
|
-
|
110
|
+
soap = some_soap_instance
|
111
|
+
soap.namespaces["xmlns:wsdl"] = "http://v1_0.ws.user.example.com"
|
112
|
+
soap.body = { :id => 666 }
|
113
|
+
soap.to_xml.should == soap_body
|
47
114
|
end
|
48
115
|
|
49
116
|
it "caches the XML, returning the same Object every time" do
|
50
|
-
@soap.
|
117
|
+
@soap.to_xml.object_id.should == @soap.to_xml.object_id
|
51
118
|
end
|
52
119
|
|
53
120
|
it "uses the SOAP namespace for the SOAP version passed in via options" do
|
54
|
-
soap =
|
55
|
-
soap.
|
121
|
+
soap = some_soap_instance
|
122
|
+
soap.version = 2
|
123
|
+
soap.to_xml.should include Savon::SOAP::SOAPNamespace[2]
|
56
124
|
end
|
57
125
|
|
58
126
|
it "uses the SOAP namespace for the default SOAP version otherwise" do
|
59
127
|
Savon::SOAP.version = 2
|
60
|
-
@soap.
|
128
|
+
@soap.to_xml.should include Savon::SOAP::SOAPNamespace[2]
|
61
129
|
end
|
62
130
|
|
63
131
|
def soap_body
|
@@ -69,33 +137,4 @@ describe Savon::SOAP do
|
|
69
137
|
end
|
70
138
|
end
|
71
139
|
|
72
|
-
|
73
|
-
it "returns the SOAP version from options" do
|
74
|
-
soap = new_soap_instance :soap_version => 2
|
75
|
-
soap.version.should == 2
|
76
|
-
end
|
77
|
-
|
78
|
-
it "returns the default SOAP version otherwise" do
|
79
|
-
@soap.version.should == Savon::SOAP.version
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "SOAPNamespace" do
|
84
|
-
it "contains the SOAP namespace for each supported SOAP version" do
|
85
|
-
Savon::SOAPVersions.each do |soap_version|
|
86
|
-
Savon::SOAP::SOAPNamespace[soap_version].should be_a String
|
87
|
-
Savon::SOAP::SOAPNamespace[soap_version].should_not be_empty
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe "ContentType" do
|
93
|
-
it "contains the Content-Types for each supported SOAP version" do
|
94
|
-
Savon::SOAPVersions.each do |soap_version|
|
95
|
-
Savon::SOAP::ContentType[soap_version].should be_a String
|
96
|
-
Savon::SOAP::ContentType[soap_version].should_not be_empty
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
140
|
+
end
|
data/spec/savon/wsdl_spec.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Savon::WSDL do
|
4
|
-
before { @wsdl =
|
4
|
+
before { @wsdl = some_wsdl_instance }
|
5
|
+
|
6
|
+
def some_wsdl_instance
|
7
|
+
Savon::WSDL.new Savon::Request.new SpecHelper.some_endpoint
|
8
|
+
end
|
5
9
|
|
6
10
|
describe "initialize" do
|
7
11
|
it "expects a Savon::Request object" do
|
8
|
-
|
12
|
+
some_wsdl_instance
|
9
13
|
end
|
10
14
|
end
|
11
15
|
|
@@ -16,8 +20,9 @@ describe Savon::WSDL do
|
|
16
20
|
end
|
17
21
|
|
18
22
|
describe "soap_actions" do
|
19
|
-
it "returns
|
20
|
-
|
23
|
+
it "returns a Hash containing all available SOAP actions, as well as" <<
|
24
|
+
"their original names and inputs" do
|
25
|
+
@wsdl.soap_actions.should == UserFixture.soap_actions
|
21
26
|
end
|
22
27
|
|
23
28
|
it "raises an ArgumentError in case the WSDL seems to be invalid" do
|
@@ -26,9 +31,15 @@ describe Savon::WSDL do
|
|
26
31
|
end
|
27
32
|
end
|
28
33
|
|
29
|
-
describe "
|
30
|
-
it "returns
|
31
|
-
@wsdl.
|
34
|
+
describe "respond_to?" do
|
35
|
+
it "returns true for available SOAP actions" do
|
36
|
+
@wsdl.respond_to?(UserFixture.soap_actions.keys.first).
|
37
|
+
should be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
it "still behaves like usual otherwise" do
|
41
|
+
@wsdl.respond_to?(:object_id).should be_true
|
42
|
+
@wsdl.respond_to?(:some_undefined_method).should be_false
|
32
43
|
end
|
33
44
|
end
|
34
45
|
|
@@ -38,4 +49,4 @@ describe Savon::WSDL do
|
|
38
49
|
end
|
39
50
|
end
|
40
51
|
|
41
|
-
end
|
52
|
+
end
|