smooth_operator 1.10.11 → 1.10.13

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjkwOGZiOWM3NGYzODQ5MzY0ZGI4OTEwZWNhNWI5MzgyZmE4Y2E4Zg==
4
+ ZmY5YjcxMjdiMTMzZGM1OTAwNGZhNmY4Mjc4MzRhZGQwNDk0OWY5Mw==
5
5
  data.tar.gz: !binary |-
6
- NzFiOWZiZWY4N2QwZWFmNzU5ODRhYTcyMjk0NGMwNjg0ODgzNDgxOA==
6
+ ZGJlMTk3MTAxMWM5MmM1ZGIxNzliZjYxMTBjNjhmNjE3MjczYWRlMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YTNiMjUwODdkN2NhMDljMjUxNGZkZTlkMzExMzM1ZTg5NzUyN2ExMzZlYTBk
10
- MzE5OGIyZGYyMWZmNWYwOWY4OTU5YjBiNjNjMTE4MzdmMmE1M2Y2MWI3ZTFh
11
- Y2I1YmY2YTUxMTZmMmNlOTRlMGU1N2FlNzVjNWVmMmEzYjdiODQ=
9
+ NzVjN2JlOTI0OTllZDlmYTNlNzkxYjAzODU0NGEyNTQ5ZmY1YTQ1ZjRlYTMy
10
+ Yzg2YTEwYWM3ZTU1OTJhMDk1M2I0ODk2NWU2M2VlMzY2MDUxMDlkMDU2YTU5
11
+ MTZmMjgyNjhkZGY0NzdhOTgwYzExNzFhY2VlMTBkYTA1NmFhNWU=
12
12
  data.tar.gz: !binary |-
13
- MmExYzVkNDQ0YmEyZGJjZGMxYzljOWMwMjJmMjBiMGI3MDE1ZDU5ZjVlOTI0
14
- ZDQ4ODA5NWIwZjcxYTY4M2Y0OGI2MzU2OTk5OWUxYzI4NzQ4MDI1YTY4ODNm
15
- N2IzMmMzMTU2ODgwNmRiOGYwMjNkNTI3MDlmNDZiY2VkYWM0ZDA=
13
+ MDUyMGNiMDllZDI5NjExNWEzMzMyYzY4YTQ1MGUzYjU3M2I2M2UwNzM2OTNm
14
+ YTYwMDAwOWEwMjM2YjViY2JhMDFkNzE4MGU4ODc5OWViMTFiZjFhMmVkZmY3
15
+ MWZkZjhhYmIzNzQ5N2Q2MjFkNGE5ZTE1NDk5YTM5ODYyOTA4MzE=
data/README.md CHANGED
@@ -120,7 +120,7 @@ post.save("#{post.id}/save_and_add_to_list", { admin: true, post: { author: 'Age
120
120
  ### 2.4) Saving using HTTP Patch verb
121
121
  ```ruby
122
122
  class Page < MyBlogResource
123
- self.save_http_verb = :patch
123
+ self.update_http_verb = :patch
124
124
  end
125
125
 
126
126
  page = Page.find(2)
@@ -142,23 +142,30 @@ remote_call = Page.find(:all) # Will make a GET call to 'http://myblog.com/api/v
142
142
  pages = remote_call.objects # 'pages = remote_call.data' also works
143
143
 
144
144
  # If the server response is positive (http code between 200 and 299):
145
- remote_call.success? # true
146
- remote_call.failure? # false
145
+ remote_call.ok? # true
146
+ remote_call.not_processed? # false
147
147
  remote_call.error? # false
148
148
  remote_call.status # true
149
149
  pages = remote_call.data # array of Page instances
150
150
  remote_call.http_status # server_response code
151
151
 
152
- # If the server response is negative (http code between 400 and 499):
153
- remote_call.success? # false
154
- remote_call.failure? # true
152
+ # If the server response is unprocessed entity (http code 422):
153
+ remote_call.ok? # false
154
+ remote_call.not_processed? # true
155
155
  remote_call.error? # false
156
156
  remote_call.status # false
157
157
  remote_call.http_status # server_response code
158
158
 
159
- # If the server response is an error (http code between 500 and 599), or the connection broke:
160
- remote_call.success? # false
161
- remote_call.failure? # false
159
+ # If the server response is client error (http code between 400..499, except 422):
160
+ remote_call.ok? # false
161
+ remote_call.not_processed? # false
162
+ remote_call.error? # true
163
+ remote_call.status # nil
164
+ remote_call.http_status # server_response code
165
+
166
+ # If the server response is server error (http code between 500 and 599), or the connection broke:
167
+ remote_call.ok? # false
168
+ remote_call.not_processed? # false
162
169
  remote_call.error? # true
163
170
  remote_call.status # nil
164
171
  remote_call.http_status # server_response code or 0 if connection broke
@@ -14,7 +14,7 @@ module SmoothOperator
14
14
  returning_object = {}
15
15
 
16
16
  get(relative_path, data, options).tap do |remote_call|
17
- remote_call.object = build_object(remote_call.parsed_response, options) if remote_call.success?
17
+ remote_call.object = build_object(remote_call.parsed_response, options) if remote_call.ok?
18
18
 
19
19
  returning_object = remote_call
20
20
  end
@@ -8,35 +8,27 @@ module SmoothOperator
8
8
 
9
9
  module ClassMethods
10
10
 
11
- def methods_http_verbs
12
- @methods_http_verbs ||= { create: :post, save: :put, destroy: :delete }
11
+ def methods_vs_http_verbs
12
+ @methods_vs_http_verbs ||= { reload: :get, create: :post, update: :put, destroy: :delete }
13
13
  end
14
14
 
15
- [:create, :save, :destroy].each do |method|
16
- define_method("#{method}_http_verb=") { |http_verb| methods_http_verbs[method] = http_verb }
15
+ [:reload, :create, :update, :destroy].each do |method|
16
+ define_method("#{method}_http_verb=") { |http_verb| methods_vs_http_verbs[method] = http_verb }
17
17
  end
18
18
 
19
19
  def create(attributes = nil, relative_path = nil, data = {}, options = {})
20
- # if attributes.is_a?(Array)
21
- # attributes.map { |array_entry| create(array_entry, relative_path, data, options) }
22
- # else
23
- new(attributes).tap { |object| object.save(relative_path, data, options) }
24
- # end
20
+ new(attributes).tap { |object| object.save(relative_path, data, options) }
25
21
  end
26
22
 
27
23
  end
28
24
 
29
25
 
30
- attr_accessor :extra_params
31
-
32
26
  def reload(relative_path = nil, data = {}, options = {})
33
- raise 'UnknownPath' if !respond_to?(:id) || Helpers.blank?(id)
34
-
35
- relative_path, options = resource_path(relative_path, options)
27
+ raise 'UnknownPath' if Helpers.blank?(relative_path) && (!respond_to?(:id) || Helpers.blank?(id))
36
28
 
37
29
  success = {}
38
30
 
39
- make_remote_call(:get, relative_path, data, options) do |remote_call|
31
+ make_the_call(*persistent_method_args(:reload, relative_path, data, options)) do |remote_call|
40
32
  success = remote_call.status
41
33
  end
42
34
 
@@ -70,11 +62,9 @@ module SmoothOperator
70
62
  def destroy(relative_path = nil, data = {}, options = {})
71
63
  return false unless persisted?
72
64
 
73
- relative_path, options = resource_path(relative_path, options)
74
-
75
65
  success = {}
76
66
 
77
- success = make_remote_call(self.class.methods_http_verbs[:destroy], relative_path, data, options) do |remote_call|
67
+ make_the_call(*persistent_method_args(:destroy, relative_path, data, options)) do |remote_call|
78
68
  success = remote_call.status
79
69
 
80
70
  @destroyed = true if success
@@ -87,13 +77,15 @@ module SmoothOperator
87
77
  protected ######################### PROTECTED ##################
88
78
 
89
79
  def create_or_update(relative_path, data, options)
80
+ data = data_with_object_attributes(data, options)
81
+
90
82
  new_record? ? create(relative_path, data, options) : update(relative_path, data, options)
91
83
  end
92
84
 
93
85
  def create(relative_path, data, options)
94
86
  success = {}
95
87
 
96
- make_remote_call(self.class.methods_http_verbs[:create], relative_path, data, options) do |remote_call|
88
+ make_the_call(http_verb_for(:create, options), relative_path, data, options) do |remote_call|
97
89
  success = remote_call.status
98
90
 
99
91
  @new_record = false if success
@@ -103,60 +95,59 @@ module SmoothOperator
103
95
  end
104
96
 
105
97
  def update(relative_path, data, options)
106
- relative_path, options = resource_path(relative_path, options)
107
-
108
98
  success = {}
109
99
 
110
- make_remote_call(self.class.methods_http_verbs[:save], relative_path, data, options) do |remote_call|
100
+ make_the_call(*persistent_method_args(:update, relative_path, data, options)) do |remote_call|
111
101
  success = remote_call.status
112
102
  end
113
103
 
114
104
  success
115
105
  end
116
106
 
107
+ def make_the_call(http_verb, relative_path, data, options)
108
+ self.class.make_the_call(http_verb, relative_path, data, options) do |remote_call|
109
+ @last_remote_call = remote_call
110
+
111
+ returning_data = @last_remote_call.parsed_response
112
+
113
+ if !@last_remote_call.error? && returning_data.is_a?(Hash)
114
+ assign_attributes returning_data, from_server: true
115
+ end
116
+
117
+ yield(remote_call)
118
+ end
119
+ end
120
+
117
121
 
118
122
  private ##################### PRIVATE ####################
119
123
 
120
- def resource_path(relative_path, options)
124
+ def persistent_method_args(method, relative_path, data, options)
125
+ options ||= {}
126
+
121
127
  if Helpers.blank?(relative_path)
122
128
  if parent_object.nil? || options[:ignore_parent] == true
123
129
  relative_path = id.to_s
124
130
  else
125
- options ||= {}
126
131
  options[:table_name] = ''
127
132
  relative_path = "#{parent_object.table_name}/#{parent_object.id}/#{table_name}/#{id}"
128
133
  end
129
134
  end
130
135
 
131
- [relative_path, options]
136
+ [http_verb_for(method, options), relative_path, data, options]
132
137
  end
133
138
 
134
- def make_remote_call(http_verb, relative_path, data, options)
135
- data ||= {}
136
- data.merge!(extra_params || {})
137
-
138
- data, options = build_remote_call_args(http_verb, data, options)
139
-
140
- self.class.make_the_call(http_verb, relative_path, data, options) do |remote_call|
141
- @last_remote_call = remote_call
142
-
143
- returning_data = @last_remote_call.parsed_response
144
-
145
- if !@last_remote_call.error? && returning_data.is_a?(Hash)
146
- assign_attributes returning_data, from_server: true
147
- end
148
-
149
- yield(remote_call)
150
- end
139
+ def http_verb_for(method, options)
140
+ options[:http_verb] || self.class.methods_vs_http_verbs[method]
151
141
  end
152
142
 
153
- def build_remote_call_args(http_verb, data, options)
154
- return [data, options] if http_verb == :delete
143
+ def data_with_object_attributes(data, options)
144
+ data = Helpers.stringify_keys(data)
155
145
 
156
146
  hash = serializable_hash(options[:serializable_options]).dup
147
+
157
148
  hash.delete('id')
158
149
 
159
- [{ model_name => hash }.merge(data), options]
150
+ { model_name => hash }.merge(data)
160
151
  end
161
152
 
162
153
  end
@@ -15,36 +15,31 @@ module SmoothOperator
15
15
  end
16
16
 
17
17
 
18
- def success?
18
+ def ok?
19
19
  http_status.between?(200, 299) || http_status == 304
20
20
  end
21
21
 
22
- alias :ok? :success?
23
-
24
- def not_success?
25
- !success?
22
+ def not_processed?
23
+ http_status == 422
26
24
  end
27
25
 
28
- alias :not_ok? :not_success?
26
+ def error?
27
+ !ok? && !not_processed?
28
+ end
29
29
 
30
- def failure?
30
+ def client_error?
31
31
  http_status.between?(400, 499)
32
32
  end
33
33
 
34
- alias :failed? :failure?
35
-
36
- def error?
34
+ def server_error?
37
35
  http_status.between?(500, 599) || http_status == 0
38
36
  end
39
37
 
38
+
40
39
  def not_found?
41
40
  http_status == 404
42
41
  end
43
42
 
44
- def not_processed?
45
- http_status == 422
46
- end
47
-
48
43
  def timeout?
49
44
  false
50
45
  end
@@ -53,6 +48,7 @@ module SmoothOperator
53
48
  false
54
49
  end
55
50
 
51
+
56
52
  def parsed_response
57
53
  return nil if body.nil?
58
54
 
@@ -66,11 +62,7 @@ module SmoothOperator
66
62
  end
67
63
 
68
64
  def status
69
- return nil if error?
70
-
71
- return true if success?
72
-
73
- not_processed? ? false : nil
65
+ error? ? nil : ok?
74
66
  end
75
67
 
76
68
  def objects
@@ -1,3 +1,3 @@
1
1
  module SmoothOperator
2
- VERSION = "1.10.11"
2
+ VERSION = "1.10.13"
3
3
  end
@@ -19,8 +19,21 @@ describe SmoothOperator::FinderMethods do
19
19
  subject { UserWithAddressAndPosts::Son }
20
20
 
21
21
  describe ".all" do
22
- xit "should can .find(:all) with the same arguments that it as received" do
23
-
22
+ context "when NO arguments are passed" do
23
+ it "it should can .find(:all, {}, {})" do
24
+ expect(subject).to receive(:find).with(:all, {}, {})
25
+ subject.all
26
+ end
27
+ end
28
+
29
+ context "when arguments are passed" do
30
+ it "it should can .find(:all) with the same arguments that .alll has received" do
31
+ arguments = [{ id: 2 }, { http_verb: 'head' }]
32
+
33
+ expect(subject).to receive(:find).with(:all, *arguments)
34
+
35
+ subject.all(*arguments)
36
+ end
24
37
  end
25
38
  end
26
39
 
@@ -24,7 +24,7 @@ shared_examples_for "persistent remote call" do
24
24
 
25
25
  it "it should return true" do
26
26
  execute_method
27
- expect(subject.last_remote_call.success?).to be true
27
+ expect(subject.last_remote_call.ok?).to be true
28
28
  expect(subject.last_remote_call.status).to be true
29
29
  end
30
30
 
@@ -36,12 +36,12 @@ shared_examples_for "persistent remote call" do
36
36
  it_behaves_like "successful persistent remote call"
37
37
  end
38
38
 
39
- context "when the response is negative" do
39
+ context "when the response is unprocessed_entity" do
40
40
  let(:method_arguments) { ['', { status: 422 }] }
41
41
 
42
42
  it "it should return false" do
43
43
  execute_method
44
- expect(subject.last_remote_call.failure?).to be true
44
+ expect(subject.last_remote_call.not_processed?).to be true
45
45
  expect(subject.last_remote_call.status).to be false
46
46
  end
47
47
 
@@ -53,11 +53,28 @@ shared_examples_for "persistent remote call" do
53
53
  it_behaves_like "successful persistent remote call"
54
54
  end
55
55
 
56
+ context "when the response is client side error" do
57
+ let(:method_arguments) { ['', { status: 404 }] }
58
+
59
+ it "it should return nil" do
60
+ execute_method
61
+ expect(subject.last_remote_call.client_error?).to be true
62
+ expect(subject.last_remote_call.error?).to be true
63
+ expect(subject.last_remote_call.status).to be nil
64
+ end
65
+
66
+ it "it should assert the subject's persistence" do
67
+ execute_method
68
+ expect(subject.persisted?).to be(persistence_state[500])
69
+ end
70
+ end
71
+
56
72
  context "when the there is a connection error ou http 500" do
57
73
  let(:method_arguments) { ['', { status: 500 }] }
58
74
 
59
75
  it "it should return nil" do
60
76
  execute_method
77
+ expect(subject.last_remote_call.server_error?).to be true
61
78
  expect(subject.last_remote_call.error?).to be true
62
79
  expect(subject.last_remote_call.status).to be_nil
63
80
  end
@@ -87,11 +104,28 @@ shared_examples_for "save method" do
87
104
  end
88
105
  end
89
106
 
107
+ shared_examples_for "a method that calls the #make_the_call method" do
108
+ let(:method_arguments) { ['custom_path', { "user" => { "first_name" => "nhoJ" }, "extra_params" => 'extra_params' }, { option1: 'option1', option2: 'option2', http_verb: :get, serializable_options: { only: [:first_name] } }] }
109
+
110
+ it "it should pass all arguments to #make_the_call" do
111
+ expect(subject).to receive(:make_the_call).with(:get, *method_arguments)
112
+
113
+ execute_method
114
+ end
115
+
116
+ it "it should pass all arguments to .make_the_call" do
117
+ expect(subject.class).to receive(:make_the_call).with(:get, *method_arguments)
118
+
119
+ execute_method
120
+ end
121
+ end
122
+
90
123
 
91
124
  describe SmoothOperator::Persistence, helpers: :persistence do
92
125
 
93
126
  describe "#reload", current: true do
94
127
  subject { new_user }
128
+ let(:method_to_execute) { :reload }
95
129
 
96
130
  context "before calling #reload" do
97
131
  it "#has_data_from_server and #from_server should return false" do
@@ -149,6 +183,8 @@ describe SmoothOperator::Persistence, helpers: :persistence do
149
183
  end
150
184
 
151
185
  end
186
+
187
+ it_behaves_like "a method that calls the #make_the_call method"
152
188
  end
153
189
 
154
190
  describe ".create" do
@@ -281,14 +317,16 @@ describe SmoothOperator::Persistence, helpers: :persistence do
281
317
  subject { new_user }
282
318
  let(:persistence_state) { { 200 => true, 422 => false, 500 => false } }
283
319
 
284
- it_behaves_like "persistent remote call"
285
-
286
320
  it "it should make a post http call" do
287
321
  execute_method
288
322
  expect(subject.last_remote_call.parsed_response['http_verb']).to eq('post')
289
323
  end
290
324
 
291
325
  it_behaves_like "save method"
326
+
327
+ it_behaves_like "persistent remote call"
328
+
329
+ it_behaves_like "a method that calls the #make_the_call method"
292
330
  end
293
331
 
294
332
  context "when an instance IS persisted" do
@@ -296,31 +334,34 @@ describe SmoothOperator::Persistence, helpers: :persistence do
296
334
  subject { existing_user }
297
335
  let(:persistence_state) { { 200 => true, 422 => true, 500 => true } }
298
336
 
299
- it_behaves_like "persistent remote call"
300
-
301
337
  it "it should make a put http call" do
302
338
  execute_method
303
339
  expect(subject.last_remote_call.parsed_response['http_verb']).to eq('put')
304
340
  end
305
341
 
306
342
  it_behaves_like "save method"
343
+
344
+ it_behaves_like "persistent remote call"
345
+
346
+ it_behaves_like "a method that calls the #make_the_call method"
307
347
  end
308
348
 
309
349
  context "and it uses 'patch' http verb to save" do
310
350
  subject { existing_user_with_patch }
311
351
  let(:persistence_state) { { 200 => true, 422 => true, 500 => true } }
312
352
 
313
- it_behaves_like "persistent remote call"
314
-
315
353
  it "it should make a patch http call" do
316
354
  execute_method
317
355
  expect(subject.last_remote_call.parsed_response['http_verb']).to eq('patch')
318
356
  end
319
357
 
320
358
  it_behaves_like "save method"
359
+
360
+ it_behaves_like "persistent remote call"
361
+
362
+ it_behaves_like "a method that calls the #make_the_call method"
321
363
  end
322
364
  end
323
-
324
365
  end
325
366
 
326
367
  describe "#save!" do
@@ -362,12 +403,14 @@ describe SmoothOperator::Persistence, helpers: :persistence do
362
403
  subject { existing_user }
363
404
  let(:persistence_state) { { 200 => false, 422 => true, 500 => true } }
364
405
 
365
- it_behaves_like "persistent remote call"
366
-
367
406
  it "it should make a delete http call" do
368
407
  execute_method
369
408
  expect(subject.last_remote_call.parsed_response['http_verb']).to eq('delete')
370
409
  end
410
+
411
+ it_behaves_like "persistent remote call"
412
+
413
+ it_behaves_like "a method that calls the #make_the_call method"
371
414
  end
372
415
 
373
416
  end
@@ -1,17 +1,25 @@
1
1
  require "spec_helper"
2
2
 
3
- describe SmoothOperator::RemoteCall, current: true do
3
+ describe SmoothOperator::RemoteCall do
4
4
  subject { UserWithAddressAndPosts::Son.new(attributes_for(:user_with_address_and_posts)) }
5
5
 
6
6
  context "when the server response has a http code in the 200 range" do
7
7
  before { subject.save(nil, { status: 200 }) }
8
8
 
9
- it "#success? should return true" do
10
- expect(subject.last_remote_call.success?).to be true
9
+ it "#ok? should return true" do
10
+ expect(subject.last_remote_call.ok?).to be true
11
11
  end
12
12
 
13
- it "#failure? should return false" do
14
- expect(subject.last_remote_call.failure?).to be false
13
+ it "#not_processed? should return false" do
14
+ expect(subject.last_remote_call.not_processed?).to be false
15
+ end
16
+
17
+ it "#client_error? should return false" do
18
+ expect(subject.last_remote_call.client_error?).to be false
19
+ end
20
+
21
+ it "#server_error? should return false" do
22
+ expect(subject.last_remote_call.server_error?).to be false
15
23
  end
16
24
 
17
25
  it "#error? should return false" do
@@ -22,10 +30,6 @@ describe SmoothOperator::RemoteCall, current: true do
22
30
  expect(subject.last_remote_call.not_found?).to be false
23
31
  end
24
32
 
25
- it "#not_processed? should return false" do
26
- expect(subject.last_remote_call.not_processed?).to be false
27
- end
28
-
29
33
  it "#timeout? should return false" do
30
34
  expect(subject.last_remote_call.timeout?).to be false
31
35
  end
@@ -39,27 +43,31 @@ describe SmoothOperator::RemoteCall, current: true do
39
43
  end
40
44
  end
41
45
 
42
- context "when the server response has a http code in the 400 range" do
46
+ context "when the server response has a http code in the 400 range (not 422, 404)" do
43
47
  before { subject.save(nil, { status: 400 }) }
44
48
 
45
- it "#success? should return false" do
46
- expect(subject.last_remote_call.success?).to be false
49
+ it "#ok? should return false" do
50
+ expect(subject.last_remote_call.ok?).to be false
47
51
  end
48
52
 
49
- it "#failure? should return true" do
50
- expect(subject.last_remote_call.failure?).to be true
53
+ it "#not_processed? should return false" do
54
+ expect(subject.last_remote_call.not_processed?).to be false
51
55
  end
52
56
 
53
- it "#error? should return false" do
54
- expect(subject.last_remote_call.error?).to be false
57
+ it "#client_error? should return true" do
58
+ expect(subject.last_remote_call.client_error?).to be true
55
59
  end
56
60
 
57
- it "#not_found? should return false" do
58
- expect(subject.last_remote_call.not_found?).to be false
61
+ it "#server_error? should return false" do
62
+ expect(subject.last_remote_call.server_error?).to be false
59
63
  end
60
64
 
61
- it "#not_processed? should return false" do
62
- expect(subject.last_remote_call.not_processed?).to be false
65
+ it "#error? should return true" do
66
+ expect(subject.last_remote_call.error?).to be true
67
+ end
68
+
69
+ it "#not_found? should return false" do
70
+ expect(subject.last_remote_call.not_found?).to be false
63
71
  end
64
72
 
65
73
  it "#timeout? should return false" do
@@ -78,24 +86,28 @@ describe SmoothOperator::RemoteCall, current: true do
78
86
  context "when the server response has a http is 404" do
79
87
  before { subject.save(nil, { status: 404 }) }
80
88
 
81
- it "#success? should return false" do
82
- expect(subject.last_remote_call.success?).to be false
89
+ it "#ok? should return false" do
90
+ expect(subject.last_remote_call.ok?).to be false
83
91
  end
84
92
 
85
- it "#failure? should return true" do
86
- expect(subject.last_remote_call.failure?).to be true
93
+ it "#not_processed? should return false" do
94
+ expect(subject.last_remote_call.not_processed?).to be false
87
95
  end
88
96
 
89
- it "#error? should return false" do
90
- expect(subject.last_remote_call.error?).to be false
97
+ it "#client_error? should return true" do
98
+ expect(subject.last_remote_call.client_error?).to be true
91
99
  end
92
100
 
93
- it "#not_found? should return true" do
94
- expect(subject.last_remote_call.not_found?).to be true
101
+ it "#server_error? should return false" do
102
+ expect(subject.last_remote_call.server_error?).to be false
95
103
  end
96
104
 
97
- it "#not_processed? should return false" do
98
- expect(subject.last_remote_call.not_processed?).to be false
105
+ it "#error? should return true" do
106
+ expect(subject.last_remote_call.error?).to be true
107
+ end
108
+
109
+ it "#not_found? should return true" do
110
+ expect(subject.last_remote_call.not_found?).to be true
99
111
  end
100
112
 
101
113
  it "#timeout? should return false" do
@@ -114,12 +126,20 @@ describe SmoothOperator::RemoteCall, current: true do
114
126
  context "when the server response has a http is 422" do
115
127
  before { subject.save(nil, { status: 422 }) }
116
128
 
117
- it "#success? should return false" do
118
- expect(subject.last_remote_call.success?).to be false
129
+ it "#ok? should return false" do
130
+ expect(subject.last_remote_call.ok?).to be false
131
+ end
132
+
133
+ it "#not_processed? should return true" do
134
+ expect(subject.last_remote_call.not_processed?).to be true
135
+ end
136
+
137
+ it "#client_error? should return true" do
138
+ expect(subject.last_remote_call.client_error?).to be true
119
139
  end
120
140
 
121
- it "#failure? should return true" do
122
- expect(subject.last_remote_call.failure?).to be true
141
+ it "#server_error? should return false" do
142
+ expect(subject.last_remote_call.server_error?).to be false
123
143
  end
124
144
 
125
145
  it "#error? should return false" do
@@ -130,10 +150,6 @@ describe SmoothOperator::RemoteCall, current: true do
130
150
  expect(subject.last_remote_call.not_found?).to be false
131
151
  end
132
152
 
133
- it "#not_processed? should return true" do
134
- expect(subject.last_remote_call.not_processed?).to be true
135
- end
136
-
137
153
  it "#timeout? should return false" do
138
154
  expect(subject.last_remote_call.timeout?).to be false
139
155
  end
@@ -150,12 +166,20 @@ describe SmoothOperator::RemoteCall, current: true do
150
166
  context "when the server response has a http code in the 500 range" do
151
167
  before { subject.save(nil, { status: 500 }) }
152
168
 
153
- it "#success? should return false" do
154
- expect(subject.last_remote_call.success?).to be false
169
+ it "#ok? should return false" do
170
+ expect(subject.last_remote_call.ok?).to be false
171
+ end
172
+
173
+ it "#not_processed? should return false" do
174
+ expect(subject.last_remote_call.not_processed?).to be false
175
+ end
176
+
177
+ it "#client_error? should return false" do
178
+ expect(subject.last_remote_call.client_error?).to be false
155
179
  end
156
180
 
157
- it "#failure? should return false" do
158
- expect(subject.last_remote_call.failure?).to be false
181
+ it "#server_error? should return true" do
182
+ expect(subject.last_remote_call.server_error?).to be true
159
183
  end
160
184
 
161
185
  it "#error? should return true" do
@@ -166,10 +190,6 @@ describe SmoothOperator::RemoteCall, current: true do
166
190
  expect(subject.last_remote_call.not_found?).to be false
167
191
  end
168
192
 
169
- it "#not_processed? should return false" do
170
- expect(subject.last_remote_call.not_processed?).to be false
171
- end
172
-
173
193
  it "#timeout? should return false" do
174
194
  expect(subject.last_remote_call.timeout?).to be false
175
195
  end
@@ -188,12 +208,20 @@ describe SmoothOperator::RemoteCall, current: true do
188
208
 
189
209
  before { subject.save }
190
210
 
191
- it "#success? should return false" do
192
- expect(subject.last_remote_call.success?).to be false
211
+ it "#ok? should return false" do
212
+ expect(subject.last_remote_call.ok?).to be false
193
213
  end
194
214
 
195
- it "#failure? should return false" do
196
- expect(subject.last_remote_call.failure?).to be false
215
+ it "#not_processed? should return false" do
216
+ expect(subject.last_remote_call.not_processed?).to be false
217
+ end
218
+
219
+ it "#client_error? should return false" do
220
+ expect(subject.last_remote_call.client_error?).to be false
221
+ end
222
+
223
+ it "#server_error? should return true" do
224
+ expect(subject.last_remote_call.server_error?).to be true
197
225
  end
198
226
 
199
227
  it "#error? should return true" do
@@ -204,10 +232,6 @@ describe SmoothOperator::RemoteCall, current: true do
204
232
  expect(subject.last_remote_call.not_found?).to be false
205
233
  end
206
234
 
207
- it "#not_processed? should return false" do
208
- expect(subject.last_remote_call.not_processed?).to be false
209
- end
210
-
211
235
  it "#timeout? should return false" do
212
236
  expect(subject.last_remote_call.timeout?).to be false
213
237
  end
@@ -226,12 +250,20 @@ describe SmoothOperator::RemoteCall, current: true do
226
250
 
227
251
  before { subject.save('timeout') }
228
252
 
229
- it "#success? should return false" do
230
- expect(subject.last_remote_call.success?).to be false
253
+ it "#ok? should return false" do
254
+ expect(subject.last_remote_call.ok?).to be false
231
255
  end
232
256
 
233
- it "#failure? should return false" do
234
- expect(subject.last_remote_call.failure?).to be false
257
+ it "#not_processed? should return false" do
258
+ expect(subject.last_remote_call.not_processed?).to be false
259
+ end
260
+
261
+ it "#client_error? should return false" do
262
+ expect(subject.last_remote_call.client_error?).to be false
263
+ end
264
+
265
+ it "#server_error? should return true" do
266
+ expect(subject.last_remote_call.server_error?).to be true
235
267
  end
236
268
 
237
269
  it "#error? should return true" do
@@ -242,10 +274,6 @@ describe SmoothOperator::RemoteCall, current: true do
242
274
  expect(subject.last_remote_call.not_found?).to be false
243
275
  end
244
276
 
245
- it "#not_processed? should return false" do
246
- expect(subject.last_remote_call.not_processed?).to be false
247
- end
248
-
249
277
  it "#timeout? should return true" do
250
278
  expect(subject.last_remote_call.timeout?).to be true
251
279
  end
@@ -27,7 +27,7 @@ module UserWithAddressAndPosts
27
27
 
28
28
  self.table_name = 'users'
29
29
 
30
- self.save_http_verb = :patch
30
+ self.update_http_verb = :patch
31
31
 
32
32
  end
33
33
 
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.10.11
4
+ version: 1.10.13
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-05-09 00:00:00.000000000 Z
11
+ date: 2014-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler