ddy_remote_resource 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a83306ed9f8641a5842e6b886a0fad7ac91898f9
4
- data.tar.gz: c47d38be2244a886ba8afaae18aa54f8953436be
3
+ metadata.gz: 105d5039c31e2184308d4644f7abfb77d7d4d1b8
4
+ data.tar.gz: 6bafc95fb2ddcfe869e10c4ea1a56159454c10f7
5
5
  SHA512:
6
- metadata.gz: d6f5cc8d3bbd70527df5337af6ec8e9ba4ac8257a34d683772654fc79e170a0a43629fa5985c3ba7cf7db9907fe53fbb86bb431dc5257783bc08a2949ab4e530
7
- data.tar.gz: d29ffc3ad4f221bf3bc756aa0a1935de98fdb8f06da14bad8e745304e04214e2a3076827abce3b59be56bfefef967da9b22edcfe194494f92b49aa1e193246eb
6
+ metadata.gz: 3014a4aed78428e91fd8b8e0ad79731838537a021d28077f04b3892bbf535887cb903355a412924643dbe4a5f32adddda78a5eb24084bb453930c3070267b16d
7
+ data.tar.gz: f359aceea77a8470012c43269827787329124d14e1702cf28224c5bd8a3c7dbb3bb572de4fbf06e75abdc4574455899886152403bcb5d63b62fc0bb512aea497
@@ -20,7 +20,7 @@ module RemoteResource
20
20
  include RemoteResource::Querying::PersistenceMethods
21
21
 
22
22
  attr_accessor :last_request, :last_response, :meta
23
- attr_accessor :destroyed
23
+ attr_writer :destroyed, :persisted, :success
24
24
 
25
25
  class_attribute :root_element, instance_accessor: false
26
26
 
@@ -74,19 +74,23 @@ module RemoteResource
74
74
  end
75
75
 
76
76
  def persisted?
77
- if destroyed
77
+ if destroyed?
78
78
  false
79
79
  else
80
- id.present?
80
+ !!@persisted || id.present?
81
81
  end
82
82
  end
83
83
 
84
84
  def new_record?
85
- !persisted?
85
+ !persisted? && !destroyed?
86
+ end
87
+
88
+ def destroyed?
89
+ !!@destroyed
86
90
  end
87
91
 
88
92
  def success?
89
- last_response.success? && !errors?
93
+ !!@success || (last_response.present? && last_response.success? && !errors?)
90
94
  end
91
95
 
92
96
  def errors?
@@ -55,11 +55,9 @@ module RemoteResource
55
55
  message << " with response_code=#{response_code}" if response_code.present?
56
56
  message << " with http_action=#{http_action}"
57
57
  message << " with request_url=#{request_url}"
58
- # message << " with request_query=#{request_query}" if request_query.present? # TODO: Test usability of error message whether to include this
59
- # message << " with request_body=#{request_body}" if request_body.present? # TODO: Test usability of error message whether to include this
60
- # message << " with response_body=#{response_body}" if response_body.present? # TODO: Test usability of error message whether to include this
61
58
  message
62
59
  end
60
+
63
61
  end
64
62
 
65
63
  HTTPRedirectionError = Class.new(HTTPError) # HTTP 3xx
@@ -1,3 +1,3 @@
1
1
  module RemoteResource
2
- VERSION = '1.0.2'.freeze
2
+ VERSION = '1.0.3'.freeze
3
3
  end
@@ -137,50 +137,67 @@ RSpec.describe RemoteResource::Base do
137
137
  end
138
138
  end
139
139
 
140
- describe '#persisted?' do
140
+ describe '#persisted?, #new_record? and #destroyed?' do
141
141
  context 'when id is present' do
142
- it 'returns true' do
142
+ it 'returns the correct lifecycle predicates' do
143
143
  dummy.id = 10
144
- expect(dummy.persisted?).to eql true
144
+
145
+ aggregate_failures do
146
+ expect(dummy.persisted?).to eql true
147
+ expect(dummy.new_record?).to eql false
148
+ expect(dummy.destroyed?).to eql false
149
+ end
145
150
  end
146
151
  end
147
152
 
148
- context 'when id is present and destroyed is present' do
149
- it 'returns false' do
153
+ context 'when id is present and @destroyed flag is present' do
154
+ it 'returns the correct lifecycle predicates' do
150
155
  dummy.id = 10
151
156
  dummy.destroyed = true
152
- expect(dummy.persisted?).to eql false
157
+
158
+ aggregate_failures do
159
+ expect(dummy.persisted?).to eql false
160
+ expect(dummy.new_record?).to eql false
161
+ expect(dummy.destroyed?).to eql true
162
+ end
153
163
  end
154
164
  end
155
165
 
156
166
  context 'when id is NOT present' do
157
- it 'returns false' do
167
+ it 'returns the correct lifecycle predicates' do
158
168
  dummy.id = nil
159
- expect(dummy.persisted?).to eql false
169
+
170
+ aggregate_failures do
171
+ expect(dummy.persisted?).to eql false
172
+ expect(dummy.new_record?).to eql true
173
+ expect(dummy.destroyed?).to eql false
174
+ end
160
175
  end
161
176
  end
162
177
 
163
- context 'when id is NOT present and destroyed is present' do
164
- it 'returns false' do
178
+ context 'when id is NOT present and @persisted flag is present' do
179
+ it 'returns the correct lifecycle predicates' do
165
180
  dummy.id = nil
166
- dummy.destroyed = true
167
- expect(dummy.persisted?).to eql false
168
- end
169
- end
170
- end
181
+ dummy.persisted = true
171
182
 
172
- describe '#new_record?' do
173
- context 'when #persisted?' do
174
- it 'returns false' do
175
- dummy.id = 10
176
- expect(dummy.new_record?).to eql false
183
+ aggregate_failures do
184
+ expect(dummy.persisted?).to eql true
185
+ expect(dummy.new_record?).to eql false
186
+ expect(dummy.destroyed?).to eql false
187
+ end
177
188
  end
178
189
  end
179
190
 
180
- context 'when NOT #persisted?' do
181
- it 'returns true' do
191
+ context 'when id is NOT present and @destroyed flag is present' do
192
+ it 'returns the correct lifecycle predicates' do
182
193
  dummy.id = nil
183
- expect(dummy.new_record?).to eql true
194
+ dummy.destroyed = true
195
+
196
+ aggregate_failures do
197
+ expect(dummy.persisted?).to eql false
198
+ expect(dummy.new_record?).to eql false
199
+ expect(dummy.destroyed?).to eql true
200
+ end
184
201
  end
185
202
  end
186
203
  end
@@ -210,6 +227,32 @@ RSpec.describe RemoteResource::Base do
210
227
  expect(dummy.success?).to eql false
211
228
  end
212
229
  end
230
+
231
+ context 'when last response is NOT successful and #success flag is present' do
232
+ it 'returns true' do
233
+ dummy.last_response = instance_double(RemoteResource::Response, success?: false)
234
+ dummy.success = true
235
+
236
+ expect(dummy.success?).to eql true
237
+ end
238
+ end
239
+
240
+ context 'when last response is NOT present' do
241
+ it 'returns false' do
242
+ dummy.last_response = nil
243
+
244
+ expect(dummy.success?).to eql false
245
+ end
246
+ end
247
+
248
+ context 'when last response is NOT present and #success flag is present' do
249
+ it 'returns true' do
250
+ dummy.last_response = nil
251
+ dummy.success = true
252
+
253
+ expect(dummy.success?).to eql true
254
+ end
255
+ end
213
256
  end
214
257
 
215
258
  describe '#errors?' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe RemoteResource::VERSION do
4
- it { is_expected.to eql '1.0.2' }
4
+ it { is_expected.to eql '1.0.3' }
5
5
  end
6
6
 
7
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ddy_remote_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan van der Pas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-18 00:00:00.000000000 Z
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler