smooth_operator 1.22.0 → 1.22.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/smooth_operator/operator.rb +6 -0
- data/lib/smooth_operator/operators/connection_wrapper.rb +15 -0
- data/lib/smooth_operator/operators/faraday.rb +6 -6
- data/lib/smooth_operator/operators/typhoeus.rb +22 -12
- data/lib/smooth_operator/version.rb +1 -1
- data/smooth_operator.gemspec +1 -1
- data/spec/smooth_operator/persistence_spec.rb +24 -4
- data/spec/smooth_operator/remote_call_spec.rb +102 -82
- data/spec/support/test_server.rb +7 -7
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDIzN2MyYjYyZjgxODA1Y2I4OWFmYjQzMTUxNTY5YjAwY2UzYzgwZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGNhYTkwN2QwMWUxOTY2YTBlZGVlOTg4YTYwNWQ5MWQzYWJlMzNkNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTgxMzMwZDVlYjc2MmUzZmJhYjFhNGUxZWU4MGIwYjIwMmEzYjczMWNhMDZi
|
10
|
+
NjA3NTExMDI4OGM5ZTE4MjIyNmQzYjc0YjhlYmJiN2QyY2NkMGU3NGIyZWEy
|
11
|
+
MmZmYzU1MjMwZDhiNTlkYTNiYjIzZDJmZDJkZjczMzE5MzYwYzY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGMyOWJjYzkxMzFkMzQxYjBlMzBkZGMyNDA0MjFiMTNiOTliYWI4YmFiZjMx
|
14
|
+
ZjE4YzFjZTZhNWEzYjc4NjAxZTcwYTllNTQ0NmY3Yzg0NzZmM2M4NzEyZWYy
|
15
|
+
MjIzNzkxNzkzMmYyZWJmZGRiNDEyMjlhYzFlNzRhZjUzMzU2ZGY=
|
@@ -2,6 +2,7 @@ require "smooth_operator/remote_call/base"
|
|
2
2
|
require "smooth_operator/operators/faraday"
|
3
3
|
require "smooth_operator/operators/typhoeus"
|
4
4
|
require "smooth_operator/remote_call/errors/timeout"
|
5
|
+
require "smooth_operator/operators/connection_wrapper"
|
5
6
|
require "smooth_operator/remote_call/errors/connection_failed"
|
6
7
|
|
7
8
|
module SmoothOperator
|
@@ -95,6 +96,10 @@ module SmoothOperator
|
|
95
96
|
end
|
96
97
|
end
|
97
98
|
|
99
|
+
def generate_parallel_connection
|
100
|
+
Operators::Typhoeus.generate_parallel_connection
|
101
|
+
end
|
102
|
+
|
98
103
|
protected ################# PROTECTED ####################
|
99
104
|
|
100
105
|
def before_request(http_verb, relative_path, data, options)
|
@@ -111,6 +116,7 @@ module SmoothOperator
|
|
111
116
|
if options[:parallel_connection].nil?
|
112
117
|
Operators::Faraday
|
113
118
|
else
|
119
|
+
options[:connection] = options.delete(:parallel_connection)
|
114
120
|
Operators::Typhoeus
|
115
121
|
end
|
116
122
|
end
|
@@ -17,11 +17,11 @@ module SmoothOperator
|
|
17
17
|
def generate_connection(adapter = nil, options = nil)
|
18
18
|
adapter ||= :net_http
|
19
19
|
|
20
|
-
::Faraday.new(url: options[:endpoint]) do |builder|
|
20
|
+
ConnectionWrapper.new(::Faraday.new(url: options[:endpoint]) do |builder|
|
21
21
|
builder.options[:timeout] = options[:timeout].to_i unless Helpers.blank?(options[:timeout])
|
22
22
|
builder.request :url_encoded
|
23
23
|
builder.adapter adapter
|
24
|
-
end
|
24
|
+
end)
|
25
25
|
end
|
26
26
|
|
27
27
|
def make_the_call(http_verb, resource_path, params, body, options)
|
@@ -49,8 +49,8 @@ module SmoothOperator
|
|
49
49
|
|
50
50
|
def strip_options(options)
|
51
51
|
request_options = options.delete(:request_options) || {}
|
52
|
-
|
53
|
-
connection = options.delete(:connection) || generate_connection(nil, options)
|
52
|
+
|
53
|
+
connection = (options.delete(:connection) || generate_connection(nil, options)).connection
|
54
54
|
|
55
55
|
[connection, request_options, options]
|
56
56
|
end
|
@@ -61,9 +61,9 @@ module SmoothOperator
|
|
61
61
|
|
62
62
|
def request_configuration(request, request_options, options, params, body)
|
63
63
|
request_options.each { |key, value| request.options.send("#{key}=", value) }
|
64
|
-
|
64
|
+
|
65
65
|
options[:headers].each { |key, value| request.headers[key] = value }
|
66
|
-
|
66
|
+
|
67
67
|
params.each { |key, value| request.params[key] = value }
|
68
68
|
|
69
69
|
request.body = body
|
@@ -9,27 +9,38 @@ module SmoothOperator
|
|
9
9
|
|
10
10
|
extend self
|
11
11
|
|
12
|
+
def generate_parallel_connection
|
13
|
+
generate_connection
|
14
|
+
end
|
15
|
+
|
16
|
+
def generate_connection(adapter = nil, options = nil)
|
17
|
+
ConnectionWrapper.new(::Typhoeus::Hydra::hydra)
|
18
|
+
end
|
19
|
+
|
12
20
|
def make_the_call(http_verb, resource_path, params, body, options)
|
13
21
|
request = ::Typhoeus::Request.new *typhoeus_request_args(http_verb, resource_path, params, body, options)
|
14
|
-
|
15
|
-
hydra = options[:hydra] || ::Typhoeus::Hydra::hydra
|
16
22
|
|
17
|
-
|
23
|
+
hydra = (options[:connection] || generate_connection).connection
|
24
|
+
|
25
|
+
request_result = nil
|
18
26
|
|
19
27
|
hydra.queue(request)
|
20
28
|
|
21
|
-
request.on_complete do |typhoeus_response|
|
22
|
-
|
29
|
+
request.on_complete do |typhoeus_response|
|
30
|
+
remote_call = remote_call(typhoeus_response)
|
23
31
|
|
24
|
-
|
32
|
+
if block_given?
|
33
|
+
request_result = yield(remote_call)
|
34
|
+
else
|
35
|
+
request_result = remote_call
|
36
|
+
end
|
25
37
|
end
|
26
38
|
|
27
|
-
hydra.run if Helpers.blank?(options[:
|
39
|
+
hydra.run if Helpers.blank?(options[:connection])
|
28
40
|
|
29
|
-
|
41
|
+
request_result
|
30
42
|
end
|
31
43
|
|
32
|
-
|
33
44
|
protected ################ PROTECTED ################
|
34
45
|
|
35
46
|
def typhoeus_request_args(http_verb, relative_path, params, body, options)
|
@@ -46,7 +57,6 @@ module SmoothOperator
|
|
46
57
|
end.new(typhoeus_response)
|
47
58
|
end
|
48
59
|
|
49
|
-
|
50
60
|
private ################### PRIVATE ###############
|
51
61
|
|
52
62
|
def build_typhoeus_options(http_verb, params, body, options)
|
@@ -55,7 +65,7 @@ module SmoothOperator
|
|
55
65
|
typhoeus_options[:timeout] = options[:timeout] if Helpers.present?(options[:timeout])
|
56
66
|
|
57
67
|
typhoeus_options[:body] = body if Helpers.present?(body)
|
58
|
-
|
68
|
+
|
59
69
|
typhoeus_options[:params] = params if Helpers.present?(params)
|
60
70
|
|
61
71
|
typhoeus_options[:userpwd] = "#{options[:endpoint_user]}:#{options[:endpoint_pass]}" if Helpers.present?(options[:endpoint_user])
|
@@ -65,7 +75,7 @@ module SmoothOperator
|
|
65
75
|
|
66
76
|
def url(options, relative_path)
|
67
77
|
url = options[:endpoint]
|
68
|
-
|
78
|
+
|
69
79
|
slice = url[-1] != '/' ? '/' : ''
|
70
80
|
|
71
81
|
url = "#{url}#{slice}#{relative_path}" if Helpers.present?(relative_path)
|
data/smooth_operator.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.3"
|
25
25
|
|
26
|
-
spec.add_dependency "json", '~> 1.
|
26
|
+
spec.add_dependency "json", '~> 1.5'
|
27
27
|
spec.add_dependency "faraday", "~> 0.8"
|
28
28
|
spec.add_dependency "typhoeus", "~> 0.6"
|
29
29
|
|
@@ -23,7 +23,12 @@ shared_examples_for "persistent remote call" do
|
|
23
23
|
let(:method_arguments) { ['', { status: 200 }] }
|
24
24
|
|
25
25
|
it "it should return true" do
|
26
|
-
execute_method
|
26
|
+
result = execute_method
|
27
|
+
|
28
|
+
if !(method_to_execute.to_s =~ /create/)
|
29
|
+
expect(result).to be true
|
30
|
+
end
|
31
|
+
|
27
32
|
expect(subject.last_remote_call.ok?).to be true
|
28
33
|
expect(subject.last_remote_call.status).to be true
|
29
34
|
end
|
@@ -40,7 +45,12 @@ shared_examples_for "persistent remote call" do
|
|
40
45
|
let(:method_arguments) { ['', { status: 422 }] }
|
41
46
|
|
42
47
|
it "it should return false" do
|
43
|
-
execute_method
|
48
|
+
result = execute_method
|
49
|
+
|
50
|
+
if !(method_to_execute.to_s =~ /create/)
|
51
|
+
expect(result).to be false
|
52
|
+
end
|
53
|
+
|
44
54
|
expect(subject.last_remote_call.not_processed?).to be true
|
45
55
|
expect(subject.last_remote_call.status).to be false
|
46
56
|
end
|
@@ -57,7 +67,12 @@ shared_examples_for "persistent remote call" do
|
|
57
67
|
let(:method_arguments) { ['', { status: 404 }] }
|
58
68
|
|
59
69
|
it "it should return nil" do
|
60
|
-
execute_method
|
70
|
+
result = execute_method
|
71
|
+
|
72
|
+
if !(method_to_execute.to_s =~ /create/)
|
73
|
+
expect(result).to be nil
|
74
|
+
end
|
75
|
+
|
61
76
|
expect(subject.last_remote_call.client_error?).to be true
|
62
77
|
expect(subject.last_remote_call.error?).to be true
|
63
78
|
expect(subject.last_remote_call.status).to be nil
|
@@ -73,7 +88,12 @@ shared_examples_for "persistent remote call" do
|
|
73
88
|
let(:method_arguments) { ['', { status: 500 }] }
|
74
89
|
|
75
90
|
it "it should return nil" do
|
76
|
-
execute_method
|
91
|
+
result = execute_method
|
92
|
+
|
93
|
+
if !(method_to_execute.to_s =~ /create/)
|
94
|
+
expect(result).to be nil
|
95
|
+
end
|
96
|
+
|
77
97
|
expect(subject.last_remote_call.server_error?).to be true
|
78
98
|
expect(subject.last_remote_call.error?).to be true
|
79
99
|
expect(subject.last_remote_call.status).to be_nil
|
@@ -1,289 +1,305 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe SmoothOperator::RemoteCall do
|
4
|
-
subject { UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts)) }
|
5
4
|
|
6
5
|
context "when the server response has a http code in the 200 range" do
|
7
|
-
before
|
6
|
+
before(:all) do
|
7
|
+
@subject = UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts))
|
8
|
+
@subject.save(nil, { status: 200 })
|
9
|
+
end
|
8
10
|
|
9
11
|
it "#ok? should return true" do
|
10
|
-
expect(subject.last_remote_call.ok?).to be true
|
12
|
+
expect(@subject.last_remote_call.ok?).to be true
|
11
13
|
end
|
12
14
|
|
13
15
|
it "#not_processed? should return false" do
|
14
|
-
expect(subject.last_remote_call.not_processed?).to be false
|
16
|
+
expect(@subject.last_remote_call.not_processed?).to be false
|
15
17
|
end
|
16
18
|
|
17
19
|
it "#client_error? should return false" do
|
18
|
-
expect(subject.last_remote_call.client_error?).to be false
|
20
|
+
expect(@subject.last_remote_call.client_error?).to be false
|
19
21
|
end
|
20
22
|
|
21
23
|
it "#server_error? should return false" do
|
22
|
-
expect(subject.last_remote_call.server_error?).to be false
|
24
|
+
expect(@subject.last_remote_call.server_error?).to be false
|
23
25
|
end
|
24
26
|
|
25
27
|
it "#error? should return false" do
|
26
|
-
expect(subject.last_remote_call.error?).to be false
|
28
|
+
expect(@subject.last_remote_call.error?).to be false
|
27
29
|
end
|
28
30
|
|
29
31
|
it "#not_found? should return false" do
|
30
|
-
expect(subject.last_remote_call.not_found?).to be false
|
32
|
+
expect(@subject.last_remote_call.not_found?).to be false
|
31
33
|
end
|
32
34
|
|
33
35
|
it "#timeout? should return false" do
|
34
|
-
expect(subject.last_remote_call.timeout?).to be false
|
36
|
+
expect(@subject.last_remote_call.timeout?).to be false
|
35
37
|
end
|
36
38
|
|
37
39
|
it "#connection_failed? should return false" do
|
38
|
-
expect(subject.last_remote_call.connection_failed?).to be false
|
40
|
+
expect(@subject.last_remote_call.connection_failed?).to be false
|
39
41
|
end
|
40
42
|
|
41
43
|
it "#status should return true" do
|
42
|
-
expect(subject.last_remote_call.status).to be true
|
44
|
+
expect(@subject.last_remote_call.status).to be true
|
43
45
|
end
|
44
46
|
end
|
45
47
|
|
46
48
|
context "when the server response has a http code in the 400 range (not 422, 404)" do
|
47
|
-
before
|
49
|
+
before(:all) do
|
50
|
+
@subject = UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts))
|
51
|
+
@subject.save(nil, { status: 400 })
|
52
|
+
end
|
48
53
|
|
49
54
|
it "#ok? should return false" do
|
50
|
-
expect(subject.last_remote_call.ok?).to be false
|
55
|
+
expect(@subject.last_remote_call.ok?).to be false
|
51
56
|
end
|
52
57
|
|
53
58
|
it "#not_processed? should return false" do
|
54
|
-
expect(subject.last_remote_call.not_processed?).to be false
|
59
|
+
expect(@subject.last_remote_call.not_processed?).to be false
|
55
60
|
end
|
56
61
|
|
57
62
|
it "#client_error? should return true" do
|
58
|
-
expect(subject.last_remote_call.client_error?).to be true
|
63
|
+
expect(@subject.last_remote_call.client_error?).to be true
|
59
64
|
end
|
60
65
|
|
61
66
|
it "#server_error? should return false" do
|
62
|
-
expect(subject.last_remote_call.server_error?).to be false
|
67
|
+
expect(@subject.last_remote_call.server_error?).to be false
|
63
68
|
end
|
64
69
|
|
65
70
|
it "#error? should return true" do
|
66
|
-
expect(subject.last_remote_call.error?).to be true
|
71
|
+
expect(@subject.last_remote_call.error?).to be true
|
67
72
|
end
|
68
73
|
|
69
74
|
it "#not_found? should return false" do
|
70
|
-
expect(subject.last_remote_call.not_found?).to be false
|
75
|
+
expect(@subject.last_remote_call.not_found?).to be false
|
71
76
|
end
|
72
77
|
|
73
78
|
it "#timeout? should return false" do
|
74
|
-
expect(subject.last_remote_call.timeout?).to be false
|
79
|
+
expect(@subject.last_remote_call.timeout?).to be false
|
75
80
|
end
|
76
81
|
|
77
82
|
it "#connection_failed? should return false" do
|
78
|
-
expect(subject.last_remote_call.connection_failed?).to be false
|
83
|
+
expect(@subject.last_remote_call.connection_failed?).to be false
|
79
84
|
end
|
80
85
|
|
81
86
|
it "#status should return nil" do
|
82
|
-
expect(subject.last_remote_call.status).to be nil
|
87
|
+
expect(@subject.last_remote_call.status).to be nil
|
83
88
|
end
|
84
89
|
end
|
85
90
|
|
86
91
|
context "when the server response has a http is 404" do
|
87
|
-
before
|
92
|
+
before(:all) do
|
93
|
+
@subject = UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts))
|
94
|
+
@subject.save(nil, { status: 404 })
|
95
|
+
end
|
88
96
|
|
89
97
|
it "#ok? should return false" do
|
90
|
-
expect(subject.last_remote_call.ok?).to be false
|
98
|
+
expect(@subject.last_remote_call.ok?).to be false
|
91
99
|
end
|
92
100
|
|
93
101
|
it "#not_processed? should return false" do
|
94
|
-
expect(subject.last_remote_call.not_processed?).to be false
|
102
|
+
expect(@subject.last_remote_call.not_processed?).to be false
|
95
103
|
end
|
96
104
|
|
97
105
|
it "#client_error? should return true" do
|
98
|
-
expect(subject.last_remote_call.client_error?).to be true
|
106
|
+
expect(@subject.last_remote_call.client_error?).to be true
|
99
107
|
end
|
100
108
|
|
101
109
|
it "#server_error? should return false" do
|
102
|
-
expect(subject.last_remote_call.server_error?).to be false
|
110
|
+
expect(@subject.last_remote_call.server_error?).to be false
|
103
111
|
end
|
104
112
|
|
105
113
|
it "#error? should return true" do
|
106
|
-
expect(subject.last_remote_call.error?).to be true
|
114
|
+
expect(@subject.last_remote_call.error?).to be true
|
107
115
|
end
|
108
116
|
|
109
117
|
it "#not_found? should return true" do
|
110
|
-
expect(subject.last_remote_call.not_found?).to be true
|
118
|
+
expect(@subject.last_remote_call.not_found?).to be true
|
111
119
|
end
|
112
120
|
|
113
121
|
it "#timeout? should return false" do
|
114
|
-
expect(subject.last_remote_call.timeout?).to be false
|
122
|
+
expect(@subject.last_remote_call.timeout?).to be false
|
115
123
|
end
|
116
124
|
|
117
125
|
it "#connection_failed? should return false" do
|
118
|
-
expect(subject.last_remote_call.connection_failed?).to be false
|
126
|
+
expect(@subject.last_remote_call.connection_failed?).to be false
|
119
127
|
end
|
120
128
|
|
121
129
|
it "#status should return nil" do
|
122
|
-
expect(subject.last_remote_call.status).to be nil
|
130
|
+
expect(@subject.last_remote_call.status).to be nil
|
123
131
|
end
|
124
132
|
end
|
125
133
|
|
126
134
|
context "when the server response has a http is 422" do
|
127
|
-
before
|
135
|
+
before(:all) do
|
136
|
+
@subject = UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts))
|
137
|
+
@subject.save(nil, { status: 422 })
|
138
|
+
end
|
128
139
|
|
129
140
|
it "#ok? should return false" do
|
130
|
-
expect(subject.last_remote_call.ok?).to be false
|
141
|
+
expect(@subject.last_remote_call.ok?).to be false
|
131
142
|
end
|
132
143
|
|
133
144
|
it "#not_processed? should return true" do
|
134
|
-
expect(subject.last_remote_call.not_processed?).to be true
|
145
|
+
expect(@subject.last_remote_call.not_processed?).to be true
|
135
146
|
end
|
136
147
|
|
137
148
|
it "#client_error? should return true" do
|
138
|
-
expect(subject.last_remote_call.client_error?).to be true
|
149
|
+
expect(@subject.last_remote_call.client_error?).to be true
|
139
150
|
end
|
140
151
|
|
141
152
|
it "#server_error? should return false" do
|
142
|
-
expect(subject.last_remote_call.server_error?).to be false
|
153
|
+
expect(@subject.last_remote_call.server_error?).to be false
|
143
154
|
end
|
144
155
|
|
145
156
|
it "#error? should return false" do
|
146
|
-
expect(subject.last_remote_call.error?).to be false
|
157
|
+
expect(@subject.last_remote_call.error?).to be false
|
147
158
|
end
|
148
159
|
|
149
160
|
it "#not_found? should return false" do
|
150
|
-
expect(subject.last_remote_call.not_found?).to be false
|
161
|
+
expect(@subject.last_remote_call.not_found?).to be false
|
151
162
|
end
|
152
163
|
|
153
164
|
it "#timeout? should return false" do
|
154
|
-
expect(subject.last_remote_call.timeout?).to be false
|
165
|
+
expect(@subject.last_remote_call.timeout?).to be false
|
155
166
|
end
|
156
167
|
|
157
168
|
it "#connection_failed? should return false" do
|
158
|
-
expect(subject.last_remote_call.connection_failed?).to be false
|
169
|
+
expect(@subject.last_remote_call.connection_failed?).to be false
|
159
170
|
end
|
160
171
|
|
161
172
|
it "#status should return false" do
|
162
|
-
expect(subject.last_remote_call.status).to be false
|
173
|
+
expect(@subject.last_remote_call.status).to be false
|
163
174
|
end
|
164
175
|
end
|
165
176
|
|
166
177
|
context "when the server response has a http code in the 500 range" do
|
167
|
-
before
|
178
|
+
before(:all) do
|
179
|
+
@subject = UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts))
|
180
|
+
@subject.save(nil, { status: 500 })
|
181
|
+
end
|
168
182
|
|
169
183
|
it "#ok? should return false" do
|
170
|
-
expect(subject.last_remote_call.ok?).to be false
|
184
|
+
expect(@subject.last_remote_call.ok?).to be false
|
171
185
|
end
|
172
186
|
|
173
187
|
it "#not_processed? should return false" do
|
174
|
-
expect(subject.last_remote_call.not_processed?).to be false
|
188
|
+
expect(@subject.last_remote_call.not_processed?).to be false
|
175
189
|
end
|
176
190
|
|
177
191
|
it "#client_error? should return false" do
|
178
|
-
expect(subject.last_remote_call.client_error?).to be false
|
192
|
+
expect(@subject.last_remote_call.client_error?).to be false
|
179
193
|
end
|
180
194
|
|
181
195
|
it "#server_error? should return true" do
|
182
|
-
expect(subject.last_remote_call.server_error?).to be true
|
196
|
+
expect(@subject.last_remote_call.server_error?).to be true
|
183
197
|
end
|
184
198
|
|
185
199
|
it "#error? should return true" do
|
186
|
-
expect(subject.last_remote_call.error?).to be true
|
200
|
+
expect(@subject.last_remote_call.error?).to be true
|
187
201
|
end
|
188
202
|
|
189
203
|
it "#not_found? should return false" do
|
190
|
-
expect(subject.last_remote_call.not_found?).to be false
|
204
|
+
expect(@subject.last_remote_call.not_found?).to be false
|
191
205
|
end
|
192
206
|
|
193
207
|
it "#timeout? should return false" do
|
194
|
-
expect(subject.last_remote_call.timeout?).to be false
|
208
|
+
expect(@subject.last_remote_call.timeout?).to be false
|
195
209
|
end
|
196
210
|
|
197
211
|
it "#connection_failed? should return false" do
|
198
|
-
expect(subject.last_remote_call.connection_failed?).to be false
|
212
|
+
expect(@subject.last_remote_call.connection_failed?).to be false
|
199
213
|
end
|
200
214
|
|
201
215
|
it "#status should return nil" do
|
202
|
-
expect(subject.last_remote_call.status).to be nil
|
216
|
+
expect(@subject.last_remote_call.status).to be nil
|
203
217
|
end
|
204
218
|
end
|
205
219
|
|
206
220
|
context "when the connection is broken" do
|
207
|
-
|
208
|
-
|
209
|
-
|
221
|
+
before(:all) do
|
222
|
+
@subject = User::BrokenConnection.new
|
223
|
+
@subject.save
|
224
|
+
end
|
210
225
|
|
211
226
|
it "#ok? should return false" do
|
212
|
-
expect(subject.last_remote_call.ok?).to be false
|
227
|
+
expect(@subject.last_remote_call.ok?).to be false
|
213
228
|
end
|
214
229
|
|
215
230
|
it "#not_processed? should return false" do
|
216
|
-
expect(subject.last_remote_call.not_processed?).to be false
|
231
|
+
expect(@subject.last_remote_call.not_processed?).to be false
|
217
232
|
end
|
218
233
|
|
219
234
|
it "#client_error? should return false" do
|
220
|
-
expect(subject.last_remote_call.client_error?).to be false
|
235
|
+
expect(@subject.last_remote_call.client_error?).to be false
|
221
236
|
end
|
222
237
|
|
223
238
|
it "#server_error? should return true" do
|
224
|
-
expect(subject.last_remote_call.server_error?).to be true
|
239
|
+
expect(@subject.last_remote_call.server_error?).to be true
|
225
240
|
end
|
226
241
|
|
227
242
|
it "#error? should return true" do
|
228
|
-
expect(subject.last_remote_call.error?).to be true
|
243
|
+
expect(@subject.last_remote_call.error?).to be true
|
229
244
|
end
|
230
245
|
|
231
246
|
it "#not_found? should return false" do
|
232
|
-
expect(subject.last_remote_call.not_found?).to be false
|
247
|
+
expect(@subject.last_remote_call.not_found?).to be false
|
233
248
|
end
|
234
249
|
|
235
250
|
it "#timeout? should return false" do
|
236
|
-
expect(subject.last_remote_call.timeout?).to be false
|
251
|
+
expect(@subject.last_remote_call.timeout?).to be false
|
237
252
|
end
|
238
253
|
|
239
254
|
it "#connection_failed? should return true" do
|
240
|
-
expect(subject.last_remote_call.connection_failed?).to be true
|
255
|
+
expect(@subject.last_remote_call.connection_failed?).to be true
|
241
256
|
end
|
242
257
|
|
243
258
|
it "#status should return nil" do
|
244
|
-
expect(subject.last_remote_call.status).to be nil
|
259
|
+
expect(@subject.last_remote_call.status).to be nil
|
245
260
|
end
|
246
261
|
end
|
247
262
|
|
248
|
-
context "when the connection exceeds the timeout" do
|
249
|
-
|
250
|
-
|
251
|
-
|
263
|
+
context "when the connection exceeds the timeout", current: true do
|
264
|
+
before(:all) do
|
265
|
+
@subject = User::TimeoutConnection.new
|
266
|
+
@subject.save('/timeout')
|
267
|
+
end
|
252
268
|
|
253
269
|
it "#ok? should return false" do
|
254
|
-
expect(subject.last_remote_call.ok?).to be false
|
270
|
+
expect(@subject.last_remote_call.ok?).to be false
|
255
271
|
end
|
256
272
|
|
257
273
|
it "#not_processed? should return false" do
|
258
|
-
expect(subject.last_remote_call.not_processed?).to be false
|
274
|
+
expect(@subject.last_remote_call.not_processed?).to be false
|
259
275
|
end
|
260
276
|
|
261
277
|
it "#client_error? should return false" do
|
262
|
-
expect(subject.last_remote_call.client_error?).to be false
|
278
|
+
expect(@subject.last_remote_call.client_error?).to be false
|
263
279
|
end
|
264
280
|
|
265
281
|
it "#server_error? should return true" do
|
266
|
-
expect(subject.last_remote_call.server_error?).to be true
|
282
|
+
expect(@subject.last_remote_call.server_error?).to be true
|
267
283
|
end
|
268
284
|
|
269
285
|
it "#error? should return true" do
|
270
|
-
expect(subject.last_remote_call.error?).to be true
|
286
|
+
expect(@subject.last_remote_call.error?).to be true
|
271
287
|
end
|
272
288
|
|
273
289
|
it "#not_found? should return false" do
|
274
|
-
expect(subject.last_remote_call.not_found?).to be false
|
290
|
+
expect(@subject.last_remote_call.not_found?).to be false
|
275
291
|
end
|
276
292
|
|
277
293
|
it "#timeout? should return true" do
|
278
|
-
expect(subject.last_remote_call.timeout?).to be true
|
294
|
+
expect(@subject.last_remote_call.timeout?).to be true
|
279
295
|
end
|
280
296
|
|
281
297
|
it "#connection_failed? should return false" do
|
282
|
-
expect(subject.last_remote_call.connection_failed?).to be false
|
298
|
+
expect(@subject.last_remote_call.connection_failed?).to be false
|
283
299
|
end
|
284
300
|
|
285
301
|
it "#status should return nil" do
|
286
|
-
expect(subject.last_remote_call.status).to be nil
|
302
|
+
expect(@subject.last_remote_call.status).to be nil
|
287
303
|
end
|
288
304
|
end
|
289
305
|
|
@@ -299,20 +315,24 @@ describe SmoothOperator::RemoteCall do
|
|
299
315
|
|
300
316
|
describe "#http_status" do
|
301
317
|
context "when a server connection is established" do
|
302
|
-
before
|
318
|
+
before do
|
319
|
+
@subject = UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts))
|
320
|
+
@subject.save(nil, { status: 422 })
|
321
|
+
end
|
303
322
|
|
304
323
|
it "it should return the server's http response code" do
|
305
|
-
expect(subject.last_remote_call.http_status).to be 422
|
324
|
+
expect(@subject.last_remote_call.http_status).to be 422
|
306
325
|
end
|
307
326
|
end
|
308
327
|
|
309
328
|
context "when a server connection fails" do
|
310
|
-
|
311
|
-
|
312
|
-
|
329
|
+
before do
|
330
|
+
@subject = User::TimeoutConnection.new
|
331
|
+
@subject.save('/timeout')
|
332
|
+
end
|
313
333
|
|
314
334
|
it "should return 0" do
|
315
|
-
expect(subject.last_remote_call.http_status).to be 0
|
335
|
+
expect(@subject.last_remote_call.http_status).to be 0
|
316
336
|
end
|
317
337
|
end
|
318
338
|
end
|
data/spec/support/test_server.rb
CHANGED
@@ -38,7 +38,7 @@ class TestServer < Sinatra::Base
|
|
38
38
|
|
39
39
|
get '/users' do
|
40
40
|
users = [FactoryGirl.attributes_for(:user_with_address_and_posts), FactoryGirl.attributes_for(:user_with_address_and_posts)]
|
41
|
-
|
41
|
+
|
42
42
|
users[0][:id] = 1
|
43
43
|
users[1][:id] = 2
|
44
44
|
|
@@ -63,10 +63,10 @@ class TestServer < Sinatra::Base
|
|
63
63
|
users = [{ id: 1, users: nested_users}, { id: 2, users: nested_users}]
|
64
64
|
|
65
65
|
data = { page: 1, total: 6, users: users }
|
66
|
-
|
66
|
+
|
67
67
|
json data
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
get '/users/bad_json' do
|
71
71
|
'ok'
|
72
72
|
end
|
@@ -79,7 +79,7 @@ class TestServer < Sinatra::Base
|
|
79
79
|
user_data = { user: FactoryGirl.attributes_for(:user_with_address_and_posts), status: 1 }
|
80
80
|
json user_data
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
|
84
84
|
put '/users/:id/send_error' do
|
85
85
|
data_with_error = { id: 1, errors: [{ first_name: ["can't be blank"] }] }
|
@@ -90,7 +90,7 @@ class TestServer < Sinatra::Base
|
|
90
90
|
post '/users' do
|
91
91
|
common_response
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
post '/users/timeout' do
|
95
95
|
# sleep 2 # for typhoeus tests
|
96
96
|
sleep 1
|
@@ -100,7 +100,7 @@ class TestServer < Sinatra::Base
|
|
100
100
|
put '/users/:id' do
|
101
101
|
common_response
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
patch '/users/:id' do
|
105
105
|
common_response
|
106
106
|
end
|
@@ -123,7 +123,7 @@ class TestServer < Sinatra::Base
|
|
123
123
|
data.delete('id')
|
124
124
|
|
125
125
|
query_params = (params[:query_string_param] == 'true')
|
126
|
-
|
126
|
+
|
127
127
|
internal_data_match = params[:user] ? (params[:user] == data) : true
|
128
128
|
|
129
129
|
json({ user: { server_response: true }, http_verb: env["REQUEST_METHOD"].downcase, internal_data_match: internal_data_match, query_params: query_params })
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smooth_operator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.22.
|
4
|
+
version: 1.22.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- João Gonçalves
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
33
|
+
version: '1.5'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '1.
|
40
|
+
version: '1.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: faraday
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- lib/smooth_operator/internal_data.rb
|
96
96
|
- lib/smooth_operator/open_struct.rb
|
97
97
|
- lib/smooth_operator/operator.rb
|
98
|
+
- lib/smooth_operator/operators/connection_wrapper.rb
|
98
99
|
- lib/smooth_operator/operators/faraday.rb
|
99
100
|
- lib/smooth_operator/operators/typhoeus.rb
|
100
101
|
- lib/smooth_operator/persistence.rb
|