regenersis-savon 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +639 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +42 -0
- data/Rakefile +7 -0
- data/lib/regenersis-savon.rb +1 -0
- data/lib/savon.rb +15 -0
- data/lib/savon/client.rb +168 -0
- data/lib/savon/core_ext/object.rb +14 -0
- data/lib/savon/core_ext/string.rb +23 -0
- data/lib/savon/error.rb +6 -0
- data/lib/savon/global.rb +115 -0
- data/lib/savon/hooks/group.rb +46 -0
- data/lib/savon/hooks/hook.rb +36 -0
- data/lib/savon/http/error.rb +42 -0
- data/lib/savon/model.rb +103 -0
- data/lib/savon/soap.rb +21 -0
- data/lib/savon/soap/fault.rb +59 -0
- data/lib/savon/soap/request.rb +71 -0
- data/lib/savon/soap/response.rb +109 -0
- data/lib/savon/soap/xml.rb +227 -0
- data/lib/savon/version.rb +5 -0
- data/lib/savon/wasabi/document.rb +41 -0
- data/regenersis-savon.gemspec +35 -0
- data/spec/fixtures/gzip/message.gz +0 -0
- data/spec/fixtures/response/another_soap_fault.xml +14 -0
- data/spec/fixtures/response/authentication.xml +14 -0
- data/spec/fixtures/response/header.xml +13 -0
- data/spec/fixtures/response/list.xml +18 -0
- data/spec/fixtures/response/multi_ref.xml +39 -0
- data/spec/fixtures/response/soap_fault.xml +8 -0
- data/spec/fixtures/response/soap_fault12.xml +18 -0
- data/spec/fixtures/response/taxcloud.xml +1 -0
- data/spec/fixtures/wsdl/authentication.xml +63 -0
- data/spec/fixtures/wsdl/lower_camel.xml +52 -0
- data/spec/fixtures/wsdl/multiple_namespaces.xml +61 -0
- data/spec/fixtures/wsdl/multiple_types.xml +60 -0
- data/spec/fixtures/wsdl/taxcloud.xml +934 -0
- data/spec/savon/client_spec.rb +461 -0
- data/spec/savon/core_ext/object_spec.rb +19 -0
- data/spec/savon/core_ext/string_spec.rb +37 -0
- data/spec/savon/http/error_spec.rb +52 -0
- data/spec/savon/model_spec.rb +194 -0
- data/spec/savon/savon_spec.rb +85 -0
- data/spec/savon/soap/fault_spec.rb +89 -0
- data/spec/savon/soap/request_spec.rb +57 -0
- data/spec/savon/soap/response_spec.rb +224 -0
- data/spec/savon/soap/xml_spec.rb +309 -0
- data/spec/savon/soap_spec.rb +16 -0
- data/spec/savon/wasabi/document_spec.rb +45 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/support/endpoint.rb +25 -0
- data/spec/support/fixture.rb +35 -0
- metadata +323 -0
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Object do
|
4
|
+
|
5
|
+
describe "blank?" do
|
6
|
+
it "returns true for Objects perceived to be blank" do
|
7
|
+
["", false, nil, [], {}].each do |object|
|
8
|
+
object.should be_blank
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
it "returns false for every other Object" do
|
13
|
+
["!blank", true, [:a], {:a => "b"}].each do |object|
|
14
|
+
object.should_not be_blank
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe String do
|
4
|
+
|
5
|
+
describe "snakecase" do
|
6
|
+
it "lowercases one word CamelCase" do
|
7
|
+
"Merb".snakecase.should == "merb"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "makes one underscore snakecase two word CamelCase" do
|
11
|
+
"MerbCore".snakecase.should == "merb_core"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "handles CamelCase with more than 2 words" do
|
15
|
+
"SoYouWantContributeToMerbCore".snakecase.should == "so_you_want_contribute_to_merb_core"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "handles CamelCase with more than 2 capital letter in a row" do
|
19
|
+
"CNN".snakecase.should == "cnn"
|
20
|
+
"CNNNews".snakecase.should == "cnn_news"
|
21
|
+
"HeadlineCNNNews".snakecase.should == "headline_cnn_news"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "does NOT change one word lowercase" do
|
25
|
+
"merb".snakecase.should == "merb"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "leaves snake_case as is" do
|
29
|
+
"merb_core".snakecase.should == "merb_core"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "converts period characters to underscores" do
|
33
|
+
"User.GetEmail".snakecase.should == "user_get_email"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Savon::HTTP::Error do
|
4
|
+
let(:http_error) { Savon::HTTP::Error.new new_response(:code => 404, :body => "Not Found") }
|
5
|
+
let(:no_error) { Savon::HTTP::Error.new new_response }
|
6
|
+
|
7
|
+
it "should be a Savon::Error" do
|
8
|
+
Savon::HTTP::Error.should < Savon::Error
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#http" do
|
12
|
+
it "should return the HTTPI::Response" do
|
13
|
+
http_error.http.should be_an(HTTPI::Response)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#present?" do
|
18
|
+
it "should return true if there was an HTTP error" do
|
19
|
+
http_error.should be_present
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return false unless there was an HTTP error" do
|
23
|
+
no_error.should_not be_present
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
[:message, :to_s].each do |method|
|
28
|
+
describe "##{method}" do
|
29
|
+
it "should return an empty String unless an HTTP error is present" do
|
30
|
+
no_error.send(method).should == ""
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should return the HTTP error message" do
|
34
|
+
http_error.send(method).should == "HTTP error (404): Not Found"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#to_hash" do
|
40
|
+
it "should return the HTTP response details as a Hash" do
|
41
|
+
http_error.to_hash.should == { :code => 404, :headers => {}, :body => "Not Found" }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def new_response(options = {})
|
46
|
+
defaults = { :code => 200, :headers => {}, :body => Fixture.response(:authentication) }
|
47
|
+
response = defaults.merge options
|
48
|
+
|
49
|
+
HTTPI::Response.new response[:code], response[:headers], response[:body]
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Savon::Model do
|
4
|
+
|
5
|
+
let(:model) do
|
6
|
+
Class.new { extend Savon::Model }
|
7
|
+
end
|
8
|
+
|
9
|
+
describe ":model_soap_response hook" do
|
10
|
+
|
11
|
+
before(:all) do
|
12
|
+
model.actions :get_user, "GetAllUsers"
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
Savon.hooks.reject! :test_hook
|
17
|
+
end
|
18
|
+
|
19
|
+
it "can be used for pre-processing SOAP responses" do
|
20
|
+
Savon.hooks.define(:test_hook, :model_soap_response) do |response|
|
21
|
+
"hello #{response}"
|
22
|
+
end
|
23
|
+
|
24
|
+
model.client.stubs(:request).returns("world") #
|
25
|
+
model.get_user.should == "hello world"
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe ".client" do
|
31
|
+
|
32
|
+
it "passes a given block to a new Savon::Client"
|
33
|
+
|
34
|
+
it "memoizes the Savon::Client" do
|
35
|
+
model.client.should equal(model.client)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".endpoint" do
|
41
|
+
|
42
|
+
it "sets the SOAP endpoint" do
|
43
|
+
model.endpoint "http://example.com"
|
44
|
+
model.client.wsdl.endpoint.should == "http://example.com"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
describe ".namespace" do
|
50
|
+
|
51
|
+
it "sets the target namespace" do
|
52
|
+
model.namespace "http://v1.example.com"
|
53
|
+
model.client.wsdl.namespace.should == "http://v1.example.com"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
describe ".document" do
|
59
|
+
|
60
|
+
it "sets the WSDL document" do
|
61
|
+
model.document "http://example.com/?wsdl"
|
62
|
+
model.client.wsdl.document.should == "http://example.com/?wsdl"
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
describe ".headers" do
|
68
|
+
|
69
|
+
it "sets the HTTP headers" do
|
70
|
+
model.headers("Accept-Charset" => "utf-8")
|
71
|
+
model.client.http.headers.should == { "Accept-Charset" => "utf-8" }
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
describe ".basic_auth" do
|
77
|
+
|
78
|
+
it "sets HTTP Basic auth credentials" do
|
79
|
+
model.basic_auth "login", "password"
|
80
|
+
model.client.http.auth.basic.should == ["login", "password"]
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
describe ".wsse_auth" do
|
86
|
+
|
87
|
+
it "sets WSSE auth credentials" do
|
88
|
+
model.wsse_auth "login", "password", :digest
|
89
|
+
|
90
|
+
model.client.wsse.username.should == "login"
|
91
|
+
model.client.wsse.password.should == "password"
|
92
|
+
model.client.wsse.should be_digest
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
describe ".actions" do
|
98
|
+
|
99
|
+
before(:all) do
|
100
|
+
model.actions :get_user, "GetAllUsers"
|
101
|
+
end
|
102
|
+
|
103
|
+
it "defines class methods each action" do
|
104
|
+
model.should respond_to(:get_user, :get_all_users)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "defines instance methods each action" do
|
108
|
+
model.new.should respond_to(:get_user, :get_all_users)
|
109
|
+
end
|
110
|
+
|
111
|
+
context "(class-level)" do
|
112
|
+
|
113
|
+
it "executes SOAP requests with a given body" do
|
114
|
+
model.client.expects(:request).with(:wsdl, :get_user, :body => { :id => 1 })
|
115
|
+
model.get_user :id => 1
|
116
|
+
end
|
117
|
+
|
118
|
+
it "accepts and passes Strings for action names" do
|
119
|
+
model.client.expects(:request).with(:wsdl, "GetAllUsers", :body => { :id => 1 })
|
120
|
+
model.get_all_users :id => 1
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "(instance-level)" do
|
125
|
+
|
126
|
+
it "delegates to the corresponding class method" do
|
127
|
+
model.expects(:get_all_users).with(:active => true)
|
128
|
+
model.new.get_all_users :active => true
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "#client" do
|
136
|
+
|
137
|
+
it "returns the class-level Savon::Client" do
|
138
|
+
model.new.client.should == model.client
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "overwriting action methods" do
|
144
|
+
|
145
|
+
context "(class-level)" do
|
146
|
+
|
147
|
+
let(:supermodel) do
|
148
|
+
supermodel = model.dup
|
149
|
+
supermodel.actions :get_user
|
150
|
+
|
151
|
+
def supermodel.get_user(body = nil, &block)
|
152
|
+
p "super"
|
153
|
+
super
|
154
|
+
end
|
155
|
+
|
156
|
+
supermodel
|
157
|
+
end
|
158
|
+
|
159
|
+
it "works" do
|
160
|
+
supermodel.client.expects(:request).with(:wsdl, :get_user, :body => { :id => 1 })
|
161
|
+
supermodel.expects(:p).with("super") # stupid, but works
|
162
|
+
|
163
|
+
supermodel.get_user :id => 1
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
context "(instance-level)" do
|
169
|
+
|
170
|
+
let(:supermodel) do
|
171
|
+
supermodel = model.dup
|
172
|
+
supermodel.actions :get_user
|
173
|
+
supermodel = supermodel.new
|
174
|
+
|
175
|
+
def supermodel.get_user(body = nil, &block)
|
176
|
+
p "super"
|
177
|
+
super
|
178
|
+
end
|
179
|
+
|
180
|
+
supermodel
|
181
|
+
end
|
182
|
+
|
183
|
+
it "works" do
|
184
|
+
supermodel.client.expects(:request).with(:wsdl, :get_user, :body => { :id => 1 })
|
185
|
+
supermodel.expects(:p).with("super") # stupid, but works
|
186
|
+
|
187
|
+
supermodel.get_user :id => 1
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Savon do
|
4
|
+
|
5
|
+
describe ".configure" do
|
6
|
+
around do |example|
|
7
|
+
Savon.reset_config!
|
8
|
+
example.run
|
9
|
+
Savon.reset_config!
|
10
|
+
Savon.log = false # disable logging
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "log" do
|
14
|
+
it "should default to true" do
|
15
|
+
Savon.log?.should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set whether to log HTTP requests" do
|
19
|
+
Savon.configure { |config| config.log = false }
|
20
|
+
Savon.log?.should be_false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "logger" do
|
25
|
+
it "should set the logger to use" do
|
26
|
+
MyLogger = Class.new
|
27
|
+
Savon.configure { |config| config.logger = MyLogger }
|
28
|
+
Savon.logger.should == MyLogger
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should default to Logger writing to STDOUT" do
|
32
|
+
Savon.logger.should be_a(Logger)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "log_level" do
|
37
|
+
it "should default to :debug" do
|
38
|
+
Savon.log_level.should == :debug
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set the log level to use" do
|
42
|
+
Savon.configure { |config| config.log_level = :info }
|
43
|
+
Savon.log_level.should == :info
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "raise_errors" do
|
48
|
+
it "should default to true" do
|
49
|
+
Savon.raise_errors?.should be_true
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should not raise errors when disabled" do
|
53
|
+
Savon.raise_errors = false
|
54
|
+
Savon.raise_errors?.should be_false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "soap_version" do
|
59
|
+
it "should default to SOAP 1.1" do
|
60
|
+
Savon.soap_version.should == 1
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return 2 if set to SOAP 1.2" do
|
64
|
+
Savon.soap_version = 2
|
65
|
+
Savon.soap_version.should == 2
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should raise an ArgumentError in case of an invalid version" do
|
69
|
+
lambda { Savon.soap_version = 3 }.should raise_error(ArgumentError)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "strip_namespaces" do
|
74
|
+
it "should default to true" do
|
75
|
+
Savon.strip_namespaces?.should == true
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should not strip namespaces when set to false" do
|
79
|
+
Savon.strip_namespaces = false
|
80
|
+
Savon.strip_namespaces?.should == false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Savon::SOAP::Fault do
|
4
|
+
let(:soap_fault) { Savon::SOAP::Fault.new new_response(:body => Fixture.response(:soap_fault)) }
|
5
|
+
let(:soap_fault2) { Savon::SOAP::Fault.new new_response(:body => Fixture.response(:soap_fault12)) }
|
6
|
+
let(:another_soap_fault) { Savon::SOAP::Fault.new new_response(:body => Fixture.response(:another_soap_fault)) }
|
7
|
+
let(:no_fault) { Savon::SOAP::Fault.new new_response }
|
8
|
+
|
9
|
+
it "should be a Savon::Error" do
|
10
|
+
Savon::SOAP::Fault.should < Savon::Error
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#http" do
|
14
|
+
it "should return the HTTPI::Response" do
|
15
|
+
soap_fault.http.should be_an(HTTPI::Response)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#present?" do
|
20
|
+
it "should return true if the HTTP response contains a SOAP 1.1 fault" do
|
21
|
+
soap_fault.should be_present
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should return true if the HTTP response contains a SOAP 1.2 fault" do
|
25
|
+
soap_fault2.should be_present
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return true if the HTTP response contains a SOAP fault with different namespaces" do
|
29
|
+
another_soap_fault.should be_present
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return false unless the HTTP response contains a SOAP fault" do
|
33
|
+
no_fault.should_not be_present
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
[:message, :to_s].each do |method|
|
38
|
+
describe "##{method}" do
|
39
|
+
it "should return an empty String unless a SOAP fault is present" do
|
40
|
+
no_fault.send(method).should == ""
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return a SOAP 1.1 fault message" do
|
44
|
+
soap_fault.send(method).should == "(soap:Server) Fault occurred while processing."
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return a SOAP 1.2 fault message" do
|
48
|
+
soap_fault2.send(method).should == "(soap:Sender) Sender Timeout"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return a SOAP fault message (with different namespaces)" do
|
52
|
+
another_soap_fault.send(method).should == "(ERR_NO_SESSION) Wrong session message"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#to_hash" do
|
58
|
+
it "should return the SOAP response as a Hash unless a SOAP fault is present" do
|
59
|
+
no_fault.to_hash[:authenticate_response][:return][:success].should be_true
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return a SOAP 1.1 fault as a Hash" do
|
63
|
+
soap_fault.to_hash.should == {
|
64
|
+
:fault => {
|
65
|
+
:faultstring => "Fault occurred while processing.",
|
66
|
+
:faultcode => "soap:Server"
|
67
|
+
}
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return a SOAP 1.2 fault as a Hash" do
|
72
|
+
soap_fault2.to_hash.should == {
|
73
|
+
:fault => {
|
74
|
+
:detail => { :max_time => "P5M" },
|
75
|
+
:reason => { :text => "Sender Timeout" },
|
76
|
+
:code => { :value => "soap:Sender", :subcode => { :value => "m:MessageTimeout" } }
|
77
|
+
}
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def new_response(options = {})
|
83
|
+
defaults = { :code => 500, :headers => {}, :body => Fixture.response(:authentication) }
|
84
|
+
response = defaults.merge options
|
85
|
+
|
86
|
+
HTTPI::Response.new response[:code], response[:headers], response[:body]
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|