cardiac 0.2.0.pre8 → 0.2.0.pre9
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 +4 -4
- data/lib/cardiac/model/declarations.rb +4 -2
- data/lib/cardiac/railtie.rb +10 -0
- data/lib/cardiac/resource/builder.rb +4 -0
- data/lib/cardiac/util.rb +3 -2
- data/lib/cardiac/version.rb +1 -1
- data/spec/rails-3.2/Gemfile.lock +11 -11
- data/spec/rails-3.2/app_root/app/models/dummy.rb +7 -0
- data/spec/rails-3.2/app_root/log/test.log +11165 -0
- data/spec/rails-4.2/Gemfile +9 -0
- data/spec/rails-4.2/Gemfile.lock +157 -0
- data/spec/{rails-4.0 → rails-4.2}/Rakefile +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/app/assets/javascripts/application.js +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/app/assets/stylesheets/application.css +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/app/controllers/application_controller.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/app/helpers/application_helper.rb +0 -0
- data/spec/rails-4.2/app_root/app/models/dummy.rb +7 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/app/views/layouts/application.html.erb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/application.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/boot.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/database.yml +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/environment.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/environments/development.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/environments/production.rb +1 -1
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/environments/test.rb +1 -1
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/initializers/inflections.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/initializers/mime_types.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/initializers/secret_token.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/initializers/session_store.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/initializers/wrap_parameters.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/locales/en.yml +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/config/routes.rb +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/db/test.sqlite3 +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/log/development.log +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/log/test.log +11097 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/public/404.html +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/public/422.html +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/public/500.html +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/public/favicon.ico +0 -0
- data/spec/{rails-4.0 → rails-4.2}/app_root/script/rails +0 -0
- data/spec/{rails-4.0 → rails-4.2}/spec/spec_helper.rb +0 -0
- data/spec/shared/cardiac/model/base_spec.rb +3 -360
- data/spec/shared/cardiac/model/declarations_spec.rb +74 -0
- data/spec/shared/cardiac/model/persistence_spec.rb +179 -0
- data/spec/shared/cardiac/model/querying_spec.rb +144 -0
- metadata +76 -66
- data/spec/rails-4.0/Gemfile +0 -9
- data/spec/rails-4.0/Gemfile.lock +0 -132
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -4,41 +4,10 @@ describe Cardiac::Model::Base do
|
|
4
4
|
|
5
5
|
include_context 'Client responses'
|
6
6
|
|
7
|
-
let!
|
8
|
-
|
9
|
-
self.base_resource = 'http://localhost/dummy'
|
10
|
-
|
11
|
-
attribute :id, type: Integer
|
12
|
-
attribute :name, type: String
|
13
|
-
|
14
|
-
def self.name; 'Dummy' end
|
15
|
-
|
16
|
-
self
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
7
|
+
let!(:klass) { Dummy }
|
8
|
+
|
20
9
|
subject { klass }
|
21
|
-
|
22
|
-
describe '#base_resource' do
|
23
|
-
subject { super().base_resource }
|
24
|
-
it { is_expected.to be_a(::Cardiac::Resource) }
|
25
|
-
end
|
26
|
-
|
27
|
-
describe '#base_resource' do
|
28
|
-
subject { super().base_resource }
|
29
|
-
describe '#to_url' do
|
30
|
-
subject { super().to_url }
|
31
|
-
it { is_expected.to eq('http://localhost/dummy') }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it { is_expected.to respond_to(:find_instances) }
|
36
|
-
it { is_expected.to respond_to(:create_instance) }
|
37
|
-
it { is_expected.to respond_to(:identify) }
|
38
|
-
it { is_expected.not_to respond_to(:find_instance) }
|
39
|
-
it { is_expected.not_to respond_to(:update_instance) }
|
40
|
-
it { is_expected.not_to respond_to(:delete_instance) }
|
41
|
-
|
10
|
+
|
42
11
|
shared_examples 'new records' do
|
43
12
|
it { is_expected.not_to be_persisted }
|
44
13
|
it { is_expected.to be_new_record }
|
@@ -64,145 +33,6 @@ describe Cardiac::Model::Base do
|
|
64
33
|
end
|
65
34
|
end
|
66
35
|
|
67
|
-
shared_examples 'administering records' do
|
68
|
-
describe '#id' do
|
69
|
-
subject { super().id }
|
70
|
-
it { is_expected.to eq(1) }
|
71
|
-
end
|
72
|
-
|
73
|
-
describe '#to_key' do
|
74
|
-
subject { super().to_key }
|
75
|
-
it { is_expected.to eq([1]) }
|
76
|
-
end
|
77
|
-
|
78
|
-
describe '#name' do
|
79
|
-
subject { super().name }
|
80
|
-
it { is_expected.to eq('Jane Doe') }
|
81
|
-
end
|
82
|
-
|
83
|
-
describe '#remote_attributes' do
|
84
|
-
subject { super().remote_attributes }
|
85
|
-
it { is_expected.to eq('id' => 1, 'name' => 'John Doe') }
|
86
|
-
end
|
87
|
-
|
88
|
-
describe '#changed' do
|
89
|
-
subject { super().changed }
|
90
|
-
it { is_expected.to be_empty }
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
shared_examples 'read-only models prohibit modification' do
|
95
|
-
before(:each) { klass.readonly = true }
|
96
|
-
after(:each) { klass.readonly = false }
|
97
|
-
it('raises an error') { expect{ subject }.to raise_error }
|
98
|
-
end
|
99
|
-
|
100
|
-
shared_examples 'finding all instances' do
|
101
|
-
|
102
|
-
# Require that the class itself receives the operation call.
|
103
|
-
before(:each) { expect(klass).to receive(:find_instances).and_call_original }
|
104
|
-
|
105
|
-
describe 'when an Array is returned' do
|
106
|
-
let(:mock_index_success) { mock_response_klass.new("[ #{mock_success.body} ]", mock_success.code, mock_success.headers) }
|
107
|
-
|
108
|
-
# Mock the REST execution, using the :mock_success stubbed out response...
|
109
|
-
include_context 'Client execution', :get, :index_success
|
110
|
-
|
111
|
-
describe '#first' do
|
112
|
-
subject { super().first }
|
113
|
-
it { is_expected.to be_persisted }
|
114
|
-
end
|
115
|
-
|
116
|
-
describe '#first' do
|
117
|
-
subject { super().first }
|
118
|
-
it { is_expected.not_to be_new_record }
|
119
|
-
end
|
120
|
-
|
121
|
-
describe '#first' do
|
122
|
-
subject { super().first }
|
123
|
-
describe '#id' do
|
124
|
-
subject { super().id }
|
125
|
-
it { is_expected.to eq(1) }
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
describe '#first' do
|
130
|
-
subject { super().first }
|
131
|
-
describe '#to_key' do
|
132
|
-
subject { super().to_key }
|
133
|
-
it { is_expected.to eq([1]) }
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
describe '#first' do
|
138
|
-
subject { super().first }
|
139
|
-
describe '#to_param' do
|
140
|
-
subject { super().to_param }
|
141
|
-
it { is_expected.to eq('1') }
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
describe '#first' do
|
146
|
-
subject { super().first }
|
147
|
-
describe '#name' do
|
148
|
-
subject { super().name }
|
149
|
-
it { is_expected.to eq('John Doe') }
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
describe '#first' do
|
154
|
-
subject { super().first }
|
155
|
-
describe '#remote_attributes' do
|
156
|
-
subject { super().remote_attributes }
|
157
|
-
it { is_expected.to be_empty }
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
describe '#first' do
|
162
|
-
subject { super().first }
|
163
|
-
describe '#changed' do
|
164
|
-
subject { super().changed }
|
165
|
-
it { is_expected.to be_empty }
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
describe 'when an Array is not returned' do
|
171
|
-
|
172
|
-
# Mock the REST execution, using the :mock_success stubbed out response...
|
173
|
-
include_context 'Client execution', :get, :success
|
174
|
-
|
175
|
-
it 'should raise an exception' do
|
176
|
-
expect { subject.first }.to raise_error
|
177
|
-
end
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
describe '#identify' do
|
182
|
-
subject { klass.identify(1) }
|
183
|
-
|
184
|
-
it { is_expected.not_to respond_to(:find_instances) }
|
185
|
-
it { is_expected.not_to respond_to(:create_instance) }
|
186
|
-
it { is_expected.not_to respond_to(:identify) }
|
187
|
-
it { is_expected.to respond_to(:find_instance) }
|
188
|
-
it { is_expected.to respond_to(:update_instance) }
|
189
|
-
it { is_expected.to respond_to(:delete_instance) }
|
190
|
-
end
|
191
|
-
|
192
|
-
describe '#with_resource()' do
|
193
|
-
subject { klass.with_resource{|x| x.get } }
|
194
|
-
|
195
|
-
# Mock the REST execution, using the :mock_success stubbed out response...
|
196
|
-
include_context 'Client execution', :get, :success
|
197
|
-
|
198
|
-
it { is_expected.to be_a(Hash) }
|
199
|
-
|
200
|
-
describe "['segment']" do
|
201
|
-
subject { super()['segment'] }
|
202
|
-
it { is_expected.to eq({'id'=>1, 'name'=>'John Doe'}) }
|
203
|
-
end
|
204
|
-
end
|
205
|
-
|
206
36
|
describe '#new' do
|
207
37
|
subject { klass.new }
|
208
38
|
|
@@ -257,191 +87,4 @@ describe Cardiac::Model::Base do
|
|
257
87
|
end
|
258
88
|
end
|
259
89
|
|
260
|
-
describe '#create' do
|
261
|
-
subject { klass.create }
|
262
|
-
|
263
|
-
context do
|
264
|
-
# Mock the REST execution, using the :mock_success stubbed out response...
|
265
|
-
include_context 'Client execution', :post, :success
|
266
|
-
|
267
|
-
it { is_expected.to be_persisted }
|
268
|
-
it { is_expected.not_to be_destroyed }
|
269
|
-
it { is_expected.not_to be_new_record }
|
270
|
-
|
271
|
-
describe '#id' do
|
272
|
-
subject { super().id }
|
273
|
-
it { is_expected.to eq(1) }
|
274
|
-
end
|
275
|
-
|
276
|
-
describe '#to_key' do
|
277
|
-
subject { super().to_key }
|
278
|
-
it { is_expected.to eq([1]) }
|
279
|
-
end
|
280
|
-
|
281
|
-
describe '#to_param' do
|
282
|
-
subject { super().to_param }
|
283
|
-
it { is_expected.to eq('1') }
|
284
|
-
end
|
285
|
-
|
286
|
-
describe '#name' do
|
287
|
-
subject { super().name }
|
288
|
-
it { is_expected.to be_nil }
|
289
|
-
end # remote attributes ignored by default on creation.
|
290
|
-
|
291
|
-
describe '#remote_attributes' do
|
292
|
-
subject { super().remote_attributes }
|
293
|
-
it { is_expected.not_to be_empty }
|
294
|
-
end
|
295
|
-
|
296
|
-
describe '#changed' do
|
297
|
-
subject { super().changed }
|
298
|
-
it { is_expected.to be_empty }
|
299
|
-
end
|
300
|
-
|
301
|
-
it 'should store the remote attributes' do
|
302
|
-
expect(subject.remote_attributes['id']).to eq(1)
|
303
|
-
expect(subject.remote_attributes[:name]).to eq('John Doe')
|
304
|
-
end
|
305
|
-
end
|
306
|
-
|
307
|
-
it_behaves_like 'read-only models prohibit modification'
|
308
|
-
end
|
309
|
-
|
310
|
-
describe '#find(id)' do
|
311
|
-
subject { klass.find(1) }
|
312
|
-
|
313
|
-
# Mock the REST execution, using the :mock_success stubbed out response...
|
314
|
-
include_context 'Client execution', :get, :success
|
315
|
-
|
316
|
-
it { is_expected.to be_persisted }
|
317
|
-
it { is_expected.not_to be_new_record }
|
318
|
-
|
319
|
-
describe '#id' do
|
320
|
-
subject { super().id }
|
321
|
-
it { is_expected.to eq(1) }
|
322
|
-
end
|
323
|
-
|
324
|
-
describe '#to_key' do
|
325
|
-
subject { super().to_key }
|
326
|
-
it { is_expected.to eq([1]) }
|
327
|
-
end
|
328
|
-
|
329
|
-
describe '#to_param' do
|
330
|
-
subject { super().to_param }
|
331
|
-
it { is_expected.to eq('1') }
|
332
|
-
end
|
333
|
-
|
334
|
-
describe '#name' do
|
335
|
-
subject { super().name }
|
336
|
-
it { is_expected.to eq('John Doe') }
|
337
|
-
end
|
338
|
-
|
339
|
-
describe '#remote_attributes' do
|
340
|
-
subject { super().remote_attributes }
|
341
|
-
it { is_expected.to be_empty }
|
342
|
-
end
|
343
|
-
|
344
|
-
describe '#changed' do
|
345
|
-
subject { super().changed }
|
346
|
-
it { is_expected.to be_empty }
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
describe '#find(:all)' do
|
351
|
-
include_examples 'finding all instances' do
|
352
|
-
subject { klass.find(:all) }
|
353
|
-
end
|
354
|
-
end
|
355
|
-
|
356
|
-
describe '#all' do
|
357
|
-
include_examples 'finding all instances' do
|
358
|
-
subject { klass.all }
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
describe '#reload' do
|
363
|
-
subject { klass.send(:instantiate, id: 1, name: 'Johnny Doe').tap{|r| r.name = 'Jane Doe' }.reload }
|
364
|
-
|
365
|
-
# Mock the REST execution, using the :mock_success stubbed out response...
|
366
|
-
include_context 'Client execution', :get, :success
|
367
|
-
|
368
|
-
it { is_expected.to be_persisted }
|
369
|
-
it { is_expected.not_to be_destroyed }
|
370
|
-
it { is_expected.not_to be_new_record }
|
371
|
-
|
372
|
-
describe '#id' do
|
373
|
-
subject { super().id }
|
374
|
-
it { is_expected.to eq(1) }
|
375
|
-
end
|
376
|
-
|
377
|
-
describe '#to_key' do
|
378
|
-
subject { super().to_key }
|
379
|
-
it { is_expected.to eq([1]) }
|
380
|
-
end
|
381
|
-
|
382
|
-
describe '#to_param' do
|
383
|
-
subject { super().to_param }
|
384
|
-
it { is_expected.to eq('1') }
|
385
|
-
end
|
386
|
-
|
387
|
-
describe '#name' do
|
388
|
-
subject { super().name }
|
389
|
-
it { is_expected.to eq('John Doe') }
|
390
|
-
end
|
391
|
-
|
392
|
-
describe '#remote_attributes' do
|
393
|
-
subject { super().remote_attributes }
|
394
|
-
it { is_expected.to be_empty }
|
395
|
-
end
|
396
|
-
|
397
|
-
describe '#changed' do
|
398
|
-
subject { super().changed }
|
399
|
-
it { is_expected.to be_empty }
|
400
|
-
end
|
401
|
-
end
|
402
|
-
|
403
|
-
describe '#update' do
|
404
|
-
subject { klass.send(:instantiate, id: 1, name: 'John Doe').tap{|r| r.update(name: 'Jane Doe') } }
|
405
|
-
|
406
|
-
context do
|
407
|
-
# Mock the REST execution, using the :mock_success stubbed out response...
|
408
|
-
include_context 'Client execution', :put, :success
|
409
|
-
include_context 'administering records'
|
410
|
-
|
411
|
-
it { is_expected.to be_persisted }
|
412
|
-
it { is_expected.not_to be_destroyed }
|
413
|
-
it { is_expected.not_to be_new_record }
|
414
|
-
it { is_expected.not_to be_name_changed }
|
415
|
-
|
416
|
-
describe '#to_param' do
|
417
|
-
subject { super().to_param }
|
418
|
-
it { is_expected.to eq('1') }
|
419
|
-
end
|
420
|
-
end
|
421
|
-
|
422
|
-
it_behaves_like 'read-only models prohibit modification'
|
423
|
-
end
|
424
|
-
|
425
|
-
describe '#delete' do
|
426
|
-
subject { klass.send(:instantiate, id: 1, name: 'Jane Doe').tap(&:destroy) }
|
427
|
-
|
428
|
-
context do
|
429
|
-
# Mock the REST execution, using the :mock_success stubbed out response...
|
430
|
-
include_context 'Client execution', :delete, :success
|
431
|
-
include_context 'administering records'
|
432
|
-
|
433
|
-
it { is_expected.to be_destroyed }
|
434
|
-
it { is_expected.not_to be_new_record }
|
435
|
-
it { is_expected.not_to be_name_changed }
|
436
|
-
it { is_expected.not_to be_name_changed }
|
437
|
-
|
438
|
-
describe '#to_param' do
|
439
|
-
subject { super().to_param }
|
440
|
-
it { is_expected.to be_nil }
|
441
|
-
end
|
442
|
-
end
|
443
|
-
|
444
|
-
it_behaves_like 'read-only models prohibit modification'
|
445
|
-
end
|
446
|
-
|
447
90
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cardiac::Model::Base do
|
4
|
+
|
5
|
+
include_context 'Client responses'
|
6
|
+
|
7
|
+
let!(:klass) { Dummy }
|
8
|
+
|
9
|
+
subject { klass }
|
10
|
+
|
11
|
+
describe '#base_resource' do
|
12
|
+
subject { super().base_resource }
|
13
|
+
|
14
|
+
it { is_expected.to be_a(::Cardiac::Resource) }
|
15
|
+
|
16
|
+
describe '#to_url' do
|
17
|
+
subject { super().to_url }
|
18
|
+
it { is_expected.to eq('http://localhost/dummy') }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it { is_expected.to respond_to(:find_instances) }
|
23
|
+
it { is_expected.to respond_to(:create_instance) }
|
24
|
+
it { is_expected.to respond_to(:identify) }
|
25
|
+
it { is_expected.not_to respond_to(:find_instance) }
|
26
|
+
it { is_expected.not_to respond_to(:update_instance) }
|
27
|
+
it { is_expected.not_to respond_to(:delete_instance) }
|
28
|
+
|
29
|
+
describe '#identify' do
|
30
|
+
let(:id_or_model) { 1 }
|
31
|
+
|
32
|
+
subject { klass.identify(id_or_model) }
|
33
|
+
|
34
|
+
it { is_expected.not_to respond_to(:find_instances) }
|
35
|
+
it { is_expected.not_to respond_to(:create_instance) }
|
36
|
+
it { is_expected.not_to respond_to(:identify) }
|
37
|
+
it { is_expected.to respond_to(:find_instance) }
|
38
|
+
it { is_expected.to respond_to(:update_instance) }
|
39
|
+
it { is_expected.to respond_to(:delete_instance) }
|
40
|
+
|
41
|
+
it 'CGI escapes strings' do
|
42
|
+
bad_path = 'bad/string&?'
|
43
|
+
good_path = CGI.escape(bad_path)
|
44
|
+
|
45
|
+
expect(CGI).to receive(:escape).once.and_call_original
|
46
|
+
|
47
|
+
expect(klass.identify(bad_path).to_url).to eq('http://localhost/dummy/'+good_path)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'CGI escapes arrays' do
|
51
|
+
bad_path = ['bad&','string&?']
|
52
|
+
good_path = [CGI.escape('bad&'), CGI.escape('string&?')]
|
53
|
+
|
54
|
+
expect(CGI).to receive(:escape).twice.and_call_original
|
55
|
+
|
56
|
+
expect(klass.identify(bad_path).to_url).to eq('http://localhost/dummy/'+good_path.to_param)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#with_resource()' do
|
61
|
+
subject { klass.with_resource{|x| x.get } }
|
62
|
+
|
63
|
+
# Mock the REST execution, using the :mock_success stubbed out response...
|
64
|
+
include_context 'Client execution', :get, :success
|
65
|
+
|
66
|
+
it { is_expected.to be_a(Hash) }
|
67
|
+
|
68
|
+
describe "['segment']" do
|
69
|
+
subject { super()['segment'] }
|
70
|
+
it { is_expected.to eq({'id'=>1, 'name'=>'John Doe'}) }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Cardiac::Model::Base do
|
4
|
+
|
5
|
+
include_context 'Client responses'
|
6
|
+
|
7
|
+
let!(:klass) { Dummy }
|
8
|
+
|
9
|
+
subject { klass }
|
10
|
+
|
11
|
+
shared_examples 'administering records' do
|
12
|
+
describe '#id' do
|
13
|
+
subject { super().id }
|
14
|
+
it { is_expected.to eq(1) }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#to_key' do
|
18
|
+
subject { super().to_key }
|
19
|
+
it { is_expected.to eq([1]) }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#name' do
|
23
|
+
subject { super().name }
|
24
|
+
it { is_expected.to eq('Jane Doe') }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#remote_attributes' do
|
28
|
+
subject { super().remote_attributes }
|
29
|
+
it { is_expected.to eq('id' => 1, 'name' => 'John Doe') }
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#changed' do
|
33
|
+
subject { super().changed }
|
34
|
+
it { is_expected.to be_empty }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
shared_examples 'read-only models prohibit modification' do
|
39
|
+
before(:each) { klass.readonly = true }
|
40
|
+
after(:each) { klass.readonly = false }
|
41
|
+
it('raises an error') { expect{ subject }.to raise_error }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#create' do
|
45
|
+
subject { klass.create }
|
46
|
+
|
47
|
+
context do
|
48
|
+
# Mock the REST execution, using the :mock_success stubbed out response...
|
49
|
+
include_context 'Client execution', :post, :success
|
50
|
+
|
51
|
+
it { is_expected.to be_persisted }
|
52
|
+
it { is_expected.not_to be_destroyed }
|
53
|
+
it { is_expected.not_to be_new_record }
|
54
|
+
|
55
|
+
describe '#id' do
|
56
|
+
subject { super().id }
|
57
|
+
it { is_expected.to eq(1) }
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#to_key' do
|
61
|
+
subject { super().to_key }
|
62
|
+
it { is_expected.to eq([1]) }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#to_param' do
|
66
|
+
subject { super().to_param }
|
67
|
+
it { is_expected.to eq('1') }
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#name' do
|
71
|
+
subject { super().name }
|
72
|
+
it { is_expected.to be_nil }
|
73
|
+
end # remote attributes ignored by default on creation.
|
74
|
+
|
75
|
+
describe '#remote_attributes' do
|
76
|
+
subject { super().remote_attributes }
|
77
|
+
it { is_expected.not_to be_empty }
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#changed' do
|
81
|
+
subject { super().changed }
|
82
|
+
it { is_expected.to be_empty }
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should store the remote attributes' do
|
86
|
+
expect(subject.remote_attributes['id']).to eq(1)
|
87
|
+
expect(subject.remote_attributes[:name]).to eq('John Doe')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
it_behaves_like 'read-only models prohibit modification'
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#reload' do
|
95
|
+
subject { klass.send(:instantiate, id: 1, name: 'Johnny Doe').tap{|r| r.name = 'Jane Doe' }.reload }
|
96
|
+
|
97
|
+
# Mock the REST execution, using the :mock_success stubbed out response...
|
98
|
+
include_context 'Client execution', :get, :success
|
99
|
+
|
100
|
+
it { is_expected.to be_persisted }
|
101
|
+
it { is_expected.not_to be_destroyed }
|
102
|
+
it { is_expected.not_to be_new_record }
|
103
|
+
|
104
|
+
describe '#id' do
|
105
|
+
subject { super().id }
|
106
|
+
it { is_expected.to eq(1) }
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#to_key' do
|
110
|
+
subject { super().to_key }
|
111
|
+
it { is_expected.to eq([1]) }
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#to_param' do
|
115
|
+
subject { super().to_param }
|
116
|
+
it { is_expected.to eq('1') }
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#name' do
|
120
|
+
subject { super().name }
|
121
|
+
it { is_expected.to eq('John Doe') }
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#remote_attributes' do
|
125
|
+
subject { super().remote_attributes }
|
126
|
+
it { is_expected.to be_empty }
|
127
|
+
end
|
128
|
+
|
129
|
+
describe '#changed' do
|
130
|
+
subject { super().changed }
|
131
|
+
it { is_expected.to be_empty }
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe '#update' do
|
136
|
+
subject { klass.send(:instantiate, id: 1, name: 'John Doe').tap{|r| r.update(name: 'Jane Doe') } }
|
137
|
+
|
138
|
+
context do
|
139
|
+
# Mock the REST execution, using the :mock_success stubbed out response...
|
140
|
+
include_context 'Client execution', :put, :success
|
141
|
+
include_context 'administering records'
|
142
|
+
|
143
|
+
it { is_expected.to be_persisted }
|
144
|
+
it { is_expected.not_to be_destroyed }
|
145
|
+
it { is_expected.not_to be_new_record }
|
146
|
+
it { is_expected.not_to be_name_changed }
|
147
|
+
|
148
|
+
describe '#to_param' do
|
149
|
+
subject { super().to_param }
|
150
|
+
it { is_expected.to eq('1') }
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
it_behaves_like 'read-only models prohibit modification'
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '#delete' do
|
158
|
+
subject { klass.send(:instantiate, id: 1, name: 'Jane Doe').tap(&:destroy) }
|
159
|
+
|
160
|
+
context do
|
161
|
+
# Mock the REST execution, using the :mock_success stubbed out response...
|
162
|
+
include_context 'Client execution', :delete, :success
|
163
|
+
include_context 'administering records'
|
164
|
+
|
165
|
+
it { is_expected.to be_destroyed }
|
166
|
+
it { is_expected.not_to be_new_record }
|
167
|
+
it { is_expected.not_to be_name_changed }
|
168
|
+
it { is_expected.not_to be_name_changed }
|
169
|
+
|
170
|
+
describe '#to_param' do
|
171
|
+
subject { super().to_param }
|
172
|
+
it { is_expected.to be_nil }
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
it_behaves_like 'read-only models prohibit modification'
|
177
|
+
end
|
178
|
+
|
179
|
+
end
|