soap-object 0.6.5 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,22 @@
1
-
2
- module SoapObject
3
- module Factory
4
-
5
- def using(cls, &block)
6
- @the_service = find_service(cls)
7
- block.call @the_service if block
8
- @the_service
9
- end
10
-
11
- private
12
-
13
- def find_service(cls)
14
- services[cls] = cls.new unless services[cls]
15
- services[cls]
16
- end
17
-
18
- def services
19
- @services ||= {}
20
- end
21
- end
22
- end
1
+
2
+ module SoapObject
3
+ module Factory
4
+
5
+ def using(cls, &block)
6
+ @the_service = find_service(cls)
7
+ block.call @the_service if block
8
+ @the_service
9
+ end
10
+
11
+ private
12
+
13
+ def find_service(cls)
14
+ services[cls] = cls.new(Savon) unless services[cls]
15
+ services[cls]
16
+ end
17
+
18
+ def services
19
+ @services ||= {}
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ module SoapObject
2
+ class SslOptions
3
+ attr_accessor :verify_mode, :version
4
+
5
+ def initialize
6
+ yield self if block_given?
7
+ end
8
+
9
+ def options
10
+ build_options
11
+ end
12
+
13
+ private
14
+
15
+ def build_options
16
+ options = {}
17
+ options[:ssl_verify_mode] = verify_mode if verify_mode
18
+ options[:ssl_version] = version if version
19
+ options
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
- module Soap
2
- module Object
3
- VERSION = "0.6.5"
4
- end
5
- end
1
+ module Soap
2
+ module Object
3
+ VERSION = "0.6.6"
4
+ end
5
+ end
data/soap-object.gemspec CHANGED
@@ -1,24 +1,24 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'soap-object/version'
5
-
6
- Gem::Specification.new do |gem|
7
- gem.name = "soap-object"
8
- gem.version = Soap::Object::VERSION
9
- gem.authors = ["Jeffrey S. Morgan", "Doug Morgan"]
10
- gem.email = ["jeff.morgan@leandog.com", "douglas.morgan3405@gmail.com"]
11
- gem.description = %q{Wrapper around SOAP service calls to make it easy to test}
12
- gem.summary = %q{Wrapper around SOAP service calls to make it easy to test}
13
- gem.homepage = "http://github.com/cheezy/soap-object"
14
-
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
19
-
20
- gem.add_dependency 'savon', '>= 2.2.0'
21
-
22
- gem.add_development_dependency 'rspec', '>= 2.12.0'
23
- gem.add_development_dependency 'cucumber', '>= 1.2.0'
24
- end
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soap-object/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "soap-object"
8
+ gem.version = Soap::Object::VERSION
9
+ gem.authors = ["Jeffrey S. Morgan", "Doug Morgan"]
10
+ gem.email = ["jeff.morgan@leandog.com", "douglas.morgan3405@gmail.com"]
11
+ gem.description = %q{Wrapper around SOAP service calls to make it easy to test}
12
+ gem.summary = %q{Wrapper around SOAP service calls to make it easy to test}
13
+ gem.homepage = "http://github.com/cheezy/soap-object"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'savon', '>= 2.2.0'
21
+
22
+ gem.add_development_dependency 'rspec', '>= 2.12.0'
23
+ gem.add_development_dependency 'cucumber', '>= 1.2.0'
24
+ end
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+
3
+ class TestSoapObjectWithProperties
4
+ include SoapObject
5
+
6
+ wsdl 'http://blah.com'
7
+ proxy 'http://proxy.com:8080'
8
+ open_timeout 10
9
+ read_timeout 20
10
+ soap_header 'Token' => 'secret'
11
+ encoding 'UTF-16'
12
+ basic_auth 'steve', 'secret'
13
+ digest_auth 'digest', 'auth'
14
+ log_level :error
15
+ soap_version 2
16
+ end
17
+
18
+ class WithoutClientProperties
19
+ include SoapObject
20
+ end
21
+
22
+ describe SoapObject do
23
+ let(:client) { double('client') }
24
+ let(:platform) {double('savon')}
25
+
26
+ before do
27
+ allow(platform).to receive(:client).and_return(client)
28
+ end
29
+
30
+ context 'when creating new instances' do
31
+
32
+ it 'should know when it is connected to service' do
33
+ subject = TestSoapObjectWithProperties.new(platform)
34
+
35
+ expect(subject).to be_connected
36
+ end
37
+
38
+ it 'should initialize the client using the wsdl' do
39
+ expect(platform).to receive(:client).with(hash_including(wsdl: 'http://blah.com'))
40
+
41
+ TestSoapObjectWithProperties.new(platform)
42
+ end
43
+
44
+ it 'should allow one to setup a proxy' do
45
+ expect(platform).to receive(:client).with(hash_including(proxy: 'http://proxy.com:8080'))
46
+
47
+ TestSoapObjectWithProperties.new(platform)
48
+ end
49
+
50
+ it 'should allow one to set an open timeout' do
51
+ expect(platform).to receive(:client).with(hash_including(open_timeout: 10))
52
+
53
+ TestSoapObjectWithProperties.new(platform)
54
+ end
55
+
56
+ it 'should allow one to set a read timeout' do
57
+ expect(platform).to receive(:client).with(hash_including(read_timeout: 20))
58
+
59
+ TestSoapObjectWithProperties.new(platform)
60
+ end
61
+
62
+ it 'should allow one to set a soap header' do
63
+ expect(platform).to receive(:client).with(hash_including(soap_header: {'Token' => 'secret'}))
64
+
65
+ TestSoapObjectWithProperties.new(platform)
66
+ end
67
+
68
+ it 'should allow one to set the encoding' do
69
+ expect(platform).to receive(:client).with(hash_including(encoding: 'UTF-16'))
70
+
71
+ TestSoapObjectWithProperties.new(platform)
72
+ end
73
+
74
+ it 'should allow one to use basic authentication' do
75
+ expect(platform).to receive(:client).with(hash_including(basic_auth: ['steve', 'secret']))
76
+
77
+ TestSoapObjectWithProperties.new(platform)
78
+ end
79
+
80
+ it 'should allow one to use digest authentication' do
81
+ expect(platform).to receive(:client).with(hash_including(digest_auth: ['digest', 'auth']))
82
+
83
+ TestSoapObjectWithProperties.new(platform)
84
+ end
85
+
86
+ it 'should enable logging when logging level set' do
87
+ expect(platform).to receive(:client).with(hash_including(log: true))
88
+
89
+ TestSoapObjectWithProperties.new(platform)
90
+ end
91
+
92
+ it 'should allow one to set the log level' do
93
+ expect(platform).to receive(:client).with(hash_including(log_level: :error))
94
+
95
+ TestSoapObjectWithProperties.new(platform)
96
+ end
97
+
98
+ it 'should use pretty format for xml when logging' do
99
+ expect(platform).to receive(:client).with(hash_including(pretty_print_xml: true))
100
+
101
+ TestSoapObjectWithProperties.new(platform)
102
+ end
103
+
104
+ it 'should allow one to set the soap version' do
105
+ expect(platform).to receive(:client).with(hash_including(soap_version: 2))
106
+
107
+ TestSoapObjectWithProperties.new(platform)
108
+ end
109
+
110
+ end
111
+
112
+ context 'when creating new instances with out client property overrides' do
113
+
114
+ it 'should set SSL version to 3 by default' do
115
+ expect(platform).to receive(:client).with(hash_including(ssl_version: :SSLv3))
116
+
117
+ WithoutClientProperties.new(platform)
118
+ end
119
+
120
+ it 'should disable SSL verification by default' do
121
+ expect(platform).to receive(:client).with(hash_including(ssl_verify_mode: :none))
122
+
123
+ WithoutClientProperties.new(platform)
124
+ end
125
+
126
+ it 'should disable logging by default' do
127
+ expect(platform).to receive(:client).with(hash_including(log: false))
128
+
129
+ WithoutClientProperties.new(platform)
130
+ end
131
+ end
132
+ end
@@ -1,35 +1,35 @@
1
- require 'spec_helper'
2
-
3
- class TestSoapObject
4
- include SoapObject
5
-
6
- wsdl 'http://blah.com'
7
- end
8
-
9
- class TestWorld
10
- include SoapObject::Factory
11
- end
12
-
13
- describe 'SoapObject factory' do
14
- context "when using the factory to create to service" do
15
- let(:world) { TestWorld.new }
16
-
17
- it "should create a valid service object" do
18
- service = world.using(TestSoapObject)
19
- expect(service).to be_instance_of TestSoapObject
20
- end
21
-
22
- it "should create a valid service and invoke a block" do
23
- world.using(TestSoapObject) do |service|
24
- expect(service).to be_instance_of TestSoapObject
25
- end
26
- end
27
-
28
- it "should create the service the first time we use it" do
29
- obj = TestSoapObject.new
30
- expect(TestSoapObject).to receive(:new).once.and_return(obj)
31
- world.using(TestSoapObject)
32
- world.using(TestSoapObject)
33
- end
34
- end
35
- end
1
+ require 'spec_helper'
2
+
3
+ class TestSoapObject
4
+ include SoapObject
5
+
6
+ wsdl 'http://blah.com'
7
+ end
8
+
9
+ class TestWorld
10
+ include SoapObject::Factory
11
+ end
12
+
13
+ describe SoapObject::Factory do
14
+ context "when using the factory to create to service" do
15
+ let(:world) { TestWorld.new }
16
+
17
+ it "should create a valid service object" do
18
+ service = world.using(TestSoapObject)
19
+ expect(service).to be_instance_of TestSoapObject
20
+ end
21
+
22
+ it "should create a valid service and invoke a block" do
23
+ world.using(TestSoapObject) do |service|
24
+ expect(service).to be_instance_of TestSoapObject
25
+ end
26
+ end
27
+
28
+ it "should create the service the first time we use it" do
29
+ obj = TestSoapObject
30
+ expect(TestSoapObject).to receive(:new).with(Savon).once.and_return(obj)
31
+ world.using(TestSoapObject)
32
+ world.using(TestSoapObject)
33
+ end
34
+ end
35
+ end
@@ -1,150 +1,31 @@
1
- require 'spec_helper'
2
-
3
- class TestSoapObjectWithProperties
4
- include SoapObject
5
-
6
- wsdl 'http://blah.com'
7
- proxy 'http://proxy.com:8080'
8
- open_timeout 10
9
- read_timeout 20
10
- soap_header 'Token' => 'secret'
11
- encoding 'UTF-16'
12
- basic_auth 'steve', 'secret'
13
- digest_auth 'digest', 'auth'
14
- log_level :error
15
- soap_version 2
16
- end
17
-
18
- class WithoutClientProperties
19
- include SoapObject
20
- end
21
-
22
- describe SoapObject do
23
- let(:client) { double('client') }
24
- let(:subject) { TestSoapObjectWithProperties.new }
25
-
26
- context 'when creating new instances' do
27
- before do
28
- allow(Savon).to receive(:client).and_return(client)
29
- end
30
-
31
- it 'should initialize the client using the wsdl' do
32
- expect(subject.send(:client_properties)[:wsdl]).to eq('http://blah.com')
33
- end
34
-
35
- it 'should know when it is connected to service' do
36
- expect(subject).to be_connected
37
- end
38
-
39
- it 'should allow one to setup a proxy' do
40
- expect(subject.send(:client_properties)[:proxy]).to eq('http://proxy.com:8080')
41
- end
42
-
43
- it 'should allow one to set an open timeout' do
44
- expect(subject.send(:client_properties)[:open_timeout]).to eq(10)
45
- end
46
-
47
- it 'should allow one to set a read timeout' do
48
- expect(subject.send(:client_properties)[:read_timeout]).to eq(20)
49
- end
50
-
51
- it 'should allow one to set a soap header' do
52
- expect(subject.send(:client_properties)[:soap_header]).to eq({'Token' => 'secret'})
53
- end
54
-
55
- it 'should allow one to set the encoding' do
56
- expect(subject.send(:client_properties)[:encoding]).to eq('UTF-16')
57
- end
58
-
59
- it 'should allow one to use basic authentication' do
60
- expect(subject.send(:client_properties)[:basic_auth]).to eq(['steve', 'secret'])
61
- end
62
-
63
- it 'should allow one to use digest authentication' do
64
- expect(subject.send(:client_properties)[:digest_auth]).to eq(['digest', 'auth'])
65
- end
66
-
67
- it 'should disable logging when no logging level set' do
68
- expect(WithoutClientProperties.new.send(:client_properties)[:log]).to eq(false)
69
- end
70
-
71
- it 'should enable logging when logging level set' do
72
- expect(subject.send(:client_properties)[:log]).to eq(true)
73
- end
74
-
75
- it 'should allow one to set the log level' do
76
- expect(subject.send(:client_properties)[:log_level]).to eq(:error)
77
- end
78
-
79
- it 'should use pretty format for xml when logging' do
80
- expect(subject.send(:client_properties)[:pretty_print_xml]).to eq(true)
81
- end
82
-
83
- it 'should allow one to set the soap version' do
84
- expect(subject.send(:client_properties)[:soap_version]).to eq(2)
85
- end
86
-
87
- it 'should disable SSL verification by default' do
88
- expect(WithoutClientProperties.new.send(:client_properties)[:ssl_verify_mode]).to eq(:none)
89
- end
90
-
91
- it 'should set SSL version to 3 by default' do
92
- expect(WithoutClientProperties.new.send(:client_properties)[:ssl_version]).to eq(:SSLv3)
93
- end
94
-
95
- context 'with ssl_verification' do
96
-
97
- class WithSslVerification
98
- include SoapObject
99
- ssl_verification true
100
- end
101
-
102
- class WithoutSslVerification
103
- include SoapObject
104
- ssl_verification false
105
- end
106
-
107
- it 'should allow one to explicitly disable SSL verification' do
108
- expect(WithoutSslVerification.new.send(:client_properties)[:ssl_verify_mode]).to eq(:none)
109
- end
110
-
111
- it 'should allow one to enable SSL verification' do
112
- expect(WithSslVerification.new.send(:client_properties)[:ssl_verify_mode]).to be_nil
113
- end
114
- end
115
-
116
- context 'with ssl version' do
117
- class WithSslVersion
118
- include SoapObject
119
- ssl_version :SSLv2
120
-
121
- end
122
-
123
- it 'should allow one to set SSL version' do
124
- expect(WithSslVersion.new.send(:client_properties)[:ssl_version]).to eq(:SSLv2)
125
- end
126
- end
127
-
128
- end
129
-
130
-
131
- context 'when calling methods on the service' do
132
- let(:response) { double('response') }
133
-
134
- before do
135
- expect(Savon).to receive(:client).and_return(client)
136
- expect(response).to receive(:to_xml)
137
- end
138
-
139
- it 'should make a valid request' do
140
- expect(client).to receive(:call).with(:fake_call, message: {data_key: 'some_value'}).and_return(response)
141
- subject.fake_call data_key: 'some_value'
142
- end
143
-
144
- it 'should make a valid request with custom xml' do
145
- expected_xml = '<xml><envelope/><data></data></envelope></xml>'
146
- expect(client).to receive(:call).with(anything, xml: expected_xml).and_return(response)
147
- subject.fake_call expected_xml
148
- end
149
- end
150
- end
1
+ require 'spec_helper'
2
+
3
+ class WithoutClientProperties
4
+ include SoapObject
5
+ end
6
+
7
+ describe SoapObject do
8
+
9
+ context 'when calling methods on the service' do
10
+ let(:response) { double('response') }
11
+ let(:client) { double('client') }
12
+ let(:platform) {double('savon')}
13
+ let(:subject) { WithoutClientProperties.new(platform) }
14
+
15
+ before do
16
+ expect(platform).to receive(:client).and_return(client)
17
+ expect(response).to receive(:to_xml)
18
+ end
19
+
20
+ it 'should make a valid request' do
21
+ expect(client).to receive(:call).with(:fake_call, message: {data_key: 'some_value'}).and_return(response)
22
+ subject.fake_call data_key: 'some_value'
23
+ end
24
+
25
+ it 'should make a valid request with custom xml' do
26
+ expected_xml = '<xml><envelope/><data></data></envelope></xml>'
27
+ expect(client).to receive(:call).with(anything, xml: expected_xml).and_return(response)
28
+ subject.fake_call expected_xml
29
+ end
30
+ end
31
+ end