draftsman 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +9 -3
- data/README.md +1 -1
- data/bin/bundler +16 -0
- data/bin/erubis +16 -0
- data/bin/htmldiff +16 -0
- data/bin/ldiff +16 -0
- data/bin/nokogiri +16 -0
- data/bin/rackup +16 -0
- data/bin/rails +16 -0
- data/bin/rake +16 -0
- data/bin/rspec +16 -0
- data/bin/thor +16 -0
- data/bin/tilt +16 -0
- data/draftsman.gemspec +2 -4
- data/lib/draftsman/draft.rb +13 -4
- data/lib/draftsman/frameworks/sinatra.rb +11 -6
- data/lib/draftsman/model.rb +12 -6
- data/lib/draftsman/version.rb +1 -1
- data/spec/controllers/informants_controller_spec.rb +28 -10
- data/spec/controllers/users_controller_spec.rb +16 -7
- data/spec/controllers/whodunnits_controller_spec.rb +16 -7
- data/spec/draftsman_spec.rb +12 -6
- data/spec/models/child_spec.rb +81 -39
- data/spec/models/draft_spec.rb +466 -135
- data/spec/models/parent_spec.rb +57 -28
- data/spec/models/skipper_spec.rb +195 -57
- data/spec/models/trashable_spec.rb +149 -50
- data/spec/models/vanilla_spec.rb +186 -59
- data/spec/models/whitelister_spec.rb +269 -90
- data/spec/spec_helper.rb +1 -6
- metadata +31 -38
- data/Gemfile.lock +0 -97
data/spec/models/draft_spec.rb
CHANGED
@@ -3,28 +3,67 @@ require 'spec_helper'
|
|
3
3
|
describe Draftsman::Draft do
|
4
4
|
describe 'class methods' do
|
5
5
|
subject { Draftsman::Draft }
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
it 'does not have a JSON object column' do
|
8
|
+
expect(subject.object_col_is_json?).to eql false
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'does not have a JSON object_changes column' do
|
12
|
+
expect(subject.object_changes_col_is_json?).to eql false
|
13
|
+
end
|
8
14
|
end
|
9
15
|
|
10
16
|
describe 'instance methods' do
|
11
17
|
let(:trashable) { Trashable.new :name => 'Bob' }
|
12
18
|
subject { trashable.draft }
|
13
19
|
|
14
|
-
describe
|
20
|
+
describe 'event, create?, update?, destroy?, object, changeset' do
|
15
21
|
context 'with `create` draft' do
|
16
22
|
before { trashable.draft_creation }
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
|
24
|
+
it 'is a `create` event' do
|
25
|
+
expect(subject.event).to eql 'create'
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'identifies as a `create` event' do
|
29
|
+
expect(subject.create?).to eql true
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'does not identify as an `update` event' do
|
33
|
+
expect(subject.update?).to eql false
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'does not identify as a `destroy` event' do
|
37
|
+
expect(subject.destroy?).to eql false
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'has an object' do
|
41
|
+
expect(subject.object).to be_present
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'has an `id` in the `changeset`' do
|
45
|
+
expect(subject.changeset).to include :id
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'has a `name` in the `changeset`' do
|
49
|
+
expect(subject.changeset).to include :name
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'does not have a `title` in the `changeset`' do
|
53
|
+
expect(subject.changeset).to_not include :title
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'has `created_at` in the `changeset`' do
|
57
|
+
expect(subject.changeset).to include :created_at
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'has `updated_at` in the `changeset`' do
|
61
|
+
expect(subject.changeset).to include :updated_at
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'does not have a `previous_draft`' do
|
65
|
+
expect(subject.previous_draft).to be_nil
|
66
|
+
end
|
28
67
|
|
29
68
|
context 'updated create' do
|
30
69
|
before do
|
@@ -32,17 +71,49 @@ describe Draftsman::Draft do
|
|
32
71
|
trashable.draft_update
|
33
72
|
end
|
34
73
|
|
35
|
-
it
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
74
|
+
it 'identifies as a `create` event' do
|
75
|
+
expect(subject.create?).to eql true
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'does not identify as an `update` event' do
|
79
|
+
expect(subject.update?).to eql false
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'does not identify as a `destroy` event' do
|
83
|
+
expect(subject.destroy?).to eql false
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'is a `create` event' do
|
87
|
+
expect(subject.event).to eql 'create'
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'has an `object`' do
|
91
|
+
expect(subject.object).to be_present
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'has an `id` in the `changeset`' do
|
95
|
+
expect(subject.changeset).to include :id
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'has a `name` in the `changeset`' do
|
99
|
+
expect(subject.changeset).to include :name
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'does not have a `title` in the `changeset`' do
|
103
|
+
expect(subject.changeset).to_not include :title
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'has `created_at` in the `changeset`' do
|
107
|
+
expect(subject.changeset).to include :created_at
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'has `updated_at` in the `changeset`' do
|
111
|
+
expect(subject.changeset).to include :updated_at
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'does not have a `previous_draft`' do
|
115
|
+
expect(subject.previous_draft).to be_nil
|
116
|
+
end
|
46
117
|
end
|
47
118
|
end
|
48
119
|
|
@@ -54,17 +125,49 @@ describe Draftsman::Draft do
|
|
54
125
|
trashable.draft_update
|
55
126
|
end
|
56
127
|
|
57
|
-
it
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
128
|
+
it 'does not identify as a `create` event' do
|
129
|
+
expect(subject.create?).to eql false
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'identifies as an `update event' do
|
133
|
+
expect(subject.update?).to eql true
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'does not identify as a `destroy` event' do
|
137
|
+
expect(subject.destroy?).to eql false
|
138
|
+
end
|
139
|
+
|
140
|
+
it 'has an `update` event' do
|
141
|
+
expect(subject.event).to eql 'update'
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'has an `object`' do
|
145
|
+
expect(subject.object).to be_present
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'does not have an `id` in the `changeset`' do
|
149
|
+
expect(subject.changeset).to_not include :id
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'has a `name` in the `changeset`' do
|
153
|
+
expect(subject.changeset).to include :name
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'has a `title` in the `changeset`' do
|
157
|
+
expect(subject.changeset).to include :title
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'does not have `created_at` in the `changeset`' do
|
161
|
+
expect(subject.changeset).to_not include :created_at
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'does not have `updated_at` in the `changeset`' do
|
165
|
+
expect(subject.changeset).to_not include :updated_at
|
166
|
+
end
|
167
|
+
|
168
|
+
it 'does not have a `previous_draft`' do
|
169
|
+
expect(subject.previous_draft).to be_nil
|
170
|
+
end
|
68
171
|
|
69
172
|
context 'updating the update' do
|
70
173
|
before do
|
@@ -72,17 +175,49 @@ describe Draftsman::Draft do
|
|
72
175
|
trashable.draft_update
|
73
176
|
end
|
74
177
|
|
75
|
-
it
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
178
|
+
it 'does not identify as a `create` event' do
|
179
|
+
expect(subject.create?).to eql false
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'identifies as an `update` event' do
|
183
|
+
expect(subject.update?).to eql true
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'does not identify as a `destroy` event' do
|
187
|
+
expect(subject.destroy?).to eql false
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'has an `update` event' do
|
191
|
+
expect(subject.event).to eql 'update'
|
192
|
+
end
|
193
|
+
|
194
|
+
it 'has an `object`' do
|
195
|
+
expect(subject.object).to be_present
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'does not have an `id` in the `changeset`' do
|
199
|
+
expect(subject.changeset).to_not include :id
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'has a `name` in the `changeset`' do
|
203
|
+
expect(subject.changeset).to include :name
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'does not have a `title` in the `changeset`' do
|
207
|
+
expect(subject.changeset).to_not include :title
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'does not have `created_at` in the `changeset`' do
|
211
|
+
expect(subject.changeset).to_not include :created_at
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'does not have `updated_at` in the `changeset`' do
|
215
|
+
expect(subject.changeset).to_not include :updated_at
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'does not have a `previous_draft`' do
|
219
|
+
expect(subject.previous_draft).to be_nil
|
220
|
+
end
|
86
221
|
end
|
87
222
|
end
|
88
223
|
|
@@ -93,14 +228,37 @@ describe Draftsman::Draft do
|
|
93
228
|
trashable.draft_destroy
|
94
229
|
end
|
95
230
|
|
96
|
-
it
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
231
|
+
it 'does not identify as a `create` event' do
|
232
|
+
expect(subject.create?).to eql false
|
233
|
+
end
|
234
|
+
|
235
|
+
it 'does not identify as an `update` event' do
|
236
|
+
expect(subject.update?).to eql false
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'identifies as a `destroy` event' do
|
240
|
+
expect(subject.destroy?).to eql true
|
241
|
+
end
|
242
|
+
|
243
|
+
it 'is not destroyed' do
|
244
|
+
expect(subject.destroyed?).to eql false
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'is a `destroy` event' do
|
248
|
+
expect(subject.event).to eql 'destroy'
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'has an `object`' do
|
252
|
+
expect(subject.object).to be_present
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'has an empty `changeset`' do
|
256
|
+
expect(subject.changeset).to eql Hash.new
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'does not have a `previous_draft`' do
|
260
|
+
expect(subject.previous_draft).to be_nil
|
261
|
+
end
|
104
262
|
end
|
105
263
|
|
106
264
|
context 'with previous `create` draft' do
|
@@ -109,36 +267,95 @@ describe Draftsman::Draft do
|
|
109
267
|
trashable.draft_destroy
|
110
268
|
end
|
111
269
|
|
112
|
-
it
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
270
|
+
it 'does not identify as a `create` event' do
|
271
|
+
expect(subject.create?).to eql false
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'does not identify as an `update` event' do
|
275
|
+
expect(subject.update?).to eql false
|
276
|
+
end
|
277
|
+
|
278
|
+
it 'identifies as a `destroy` event' do
|
279
|
+
expect(subject.destroy?).to eql true
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'is not destroyed' do
|
283
|
+
expect(subject.destroyed?).to eql false
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'is a `destroy` event' do
|
287
|
+
expect(subject.event).to eql 'destroy'
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'has an `object`' do
|
291
|
+
expect(subject.object).to be_present
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'has an `id` in the `changeset`' do
|
295
|
+
expect(subject.changeset).to include :id
|
296
|
+
end
|
297
|
+
|
298
|
+
it 'has a `name` in the `changeset`' do
|
299
|
+
expect(subject.changeset).to include :name
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'does not have a `title` in the `changeset`' do
|
303
|
+
expect(subject.changeset).to_not include :title
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'has `created_at` in the `changeset`' do
|
307
|
+
expect(subject.changeset).to include :created_at
|
308
|
+
end
|
309
|
+
|
310
|
+
it 'has `updated_at` in the `changeset`' do
|
311
|
+
expect(subject.changeset).to include :updated_at
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'has a `previous_draft`' do
|
315
|
+
expect(subject.previous_draft).to be_present
|
316
|
+
end
|
124
317
|
end
|
125
318
|
end
|
126
319
|
end
|
127
320
|
|
128
|
-
describe
|
321
|
+
describe 'publish!' do
|
129
322
|
context 'with `create` draft' do
|
130
323
|
before { trashable.draft_creation }
|
131
324
|
subject { trashable.draft.publish!; return trashable.reload }
|
132
|
-
|
133
|
-
it
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
it '
|
325
|
+
|
326
|
+
it 'does not raise an exception' do
|
327
|
+
expect { subject }.to_not raise_exception
|
328
|
+
end
|
329
|
+
|
330
|
+
it 'publishes the item' do
|
331
|
+
expect(subject.published?).to eql true
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'is not trashed' do
|
335
|
+
expect(subject.trashed?).to eql false
|
336
|
+
end
|
337
|
+
|
338
|
+
it 'is no longer a draft' do
|
339
|
+
expect(subject.draft?).to eql false
|
340
|
+
end
|
341
|
+
|
342
|
+
it 'should have a `published_at` timestamp' do
|
343
|
+
expect(subject.published_at).to be_present
|
344
|
+
end
|
345
|
+
|
346
|
+
it 'does not have a `draft_id`' do
|
347
|
+
expect(subject.draft_id).to be_nil
|
348
|
+
end
|
349
|
+
|
350
|
+
it 'does not have a draft' do
|
351
|
+
expect(subject.draft).to be_nil
|
352
|
+
end
|
353
|
+
|
354
|
+
it 'does not have a `trashed_at` timestamp' do
|
355
|
+
expect(subject.trashed_at).to be_nil
|
356
|
+
end
|
357
|
+
|
358
|
+
it 'deletes the draft record' do
|
142
359
|
expect { subject }.to change(Draftsman::Draft, :count).by(-1)
|
143
360
|
end
|
144
361
|
end
|
@@ -151,17 +368,44 @@ describe Draftsman::Draft do
|
|
151
368
|
end
|
152
369
|
|
153
370
|
subject { trashable.draft.publish!; return trashable.reload }
|
154
|
-
|
155
|
-
it
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
371
|
+
|
372
|
+
it 'does not raise an exception' do
|
373
|
+
expect { subject }.to_not raise_exception
|
374
|
+
end
|
375
|
+
|
376
|
+
it 'publishes the item' do
|
377
|
+
expect(subject.published?).to eql true
|
378
|
+
end
|
379
|
+
|
380
|
+
it 'is no longer a draft' do
|
381
|
+
expect(subject.draft?).to eql false
|
382
|
+
end
|
383
|
+
|
384
|
+
it 'is not trashed' do
|
385
|
+
expect(subject.trashed?).to eql false
|
386
|
+
end
|
387
|
+
|
388
|
+
it 'has an updated `name`' do
|
389
|
+
expect(subject.name).to eql 'Sam'
|
390
|
+
end
|
391
|
+
|
392
|
+
it 'has a `published_at` timestamp' do
|
393
|
+
expect(subject.published_at).to be_present
|
394
|
+
end
|
395
|
+
|
396
|
+
it 'does not have a `draft_id`' do
|
397
|
+
expect(subject.draft_id).to be_nil
|
398
|
+
end
|
399
|
+
|
400
|
+
it 'does not have a `draft`' do
|
401
|
+
expect(subject.draft).to be_nil
|
402
|
+
end
|
403
|
+
|
404
|
+
it 'does not have a `trashed_at` timestamp' do
|
405
|
+
expect(subject.trashed_at).to be_nil
|
406
|
+
end
|
407
|
+
|
408
|
+
it 'destroys the draft' do
|
165
409
|
expect { subject }.to change(Draftsman::Draft, :count).by(-1)
|
166
410
|
end
|
167
411
|
|
@@ -207,17 +451,20 @@ describe Draftsman::Draft do
|
|
207
451
|
end
|
208
452
|
end
|
209
453
|
|
210
|
-
describe
|
454
|
+
describe 'revert!' do
|
211
455
|
context 'with `create` draft' do
|
212
456
|
before { trashable.draft_creation }
|
213
457
|
subject { trashable.draft.revert! }
|
214
|
-
it { expect { subject }.to_not raise_exception }
|
215
458
|
|
216
|
-
it '
|
459
|
+
it 'does not raise an exception' do
|
460
|
+
expect { subject }.to_not raise_exception
|
461
|
+
end
|
462
|
+
|
463
|
+
it 'destroys the draft' do
|
217
464
|
expect { subject }.to change(Draftsman::Draft, :count).by(-1)
|
218
465
|
end
|
219
466
|
|
220
|
-
it '
|
467
|
+
it 'destroys associated item' do
|
221
468
|
expect { subject }.to change(Trashable, :count).by(-1)
|
222
469
|
end
|
223
470
|
end
|
@@ -230,17 +477,32 @@ describe Draftsman::Draft do
|
|
230
477
|
end
|
231
478
|
|
232
479
|
subject { trashable.draft.revert!; return trashable.reload }
|
233
|
-
it { expect { subject }.to_not raise_exception }
|
234
|
-
it { should_not be_draft }
|
235
|
-
its(:name) { should eql 'Bob' }
|
236
|
-
its(:draft_id) { should be_nil }
|
237
|
-
its(:draft) { should be_nil }
|
238
480
|
|
239
|
-
it '
|
481
|
+
it 'does not raise an exception' do
|
482
|
+
expect { subject }.to_not raise_exception
|
483
|
+
end
|
484
|
+
|
485
|
+
it 'is no longer a draft' do
|
486
|
+
expect(subject.draft?).to eql false
|
487
|
+
end
|
488
|
+
|
489
|
+
it 'reverts its `name`' do
|
490
|
+
expect(subject.name).to eql 'Bob'
|
491
|
+
end
|
492
|
+
|
493
|
+
it 'does not have a `draft_id`' do
|
494
|
+
expect(subject.draft_id).to be_nil
|
495
|
+
end
|
496
|
+
|
497
|
+
it 'does not have a `draft`' do
|
498
|
+
expect(subject.draft).to be_nil
|
499
|
+
end
|
500
|
+
|
501
|
+
it 'destroys the draft record' do
|
240
502
|
expect { subject }.to change(Draftsman::Draft, :count).by(-1)
|
241
503
|
end
|
242
504
|
|
243
|
-
it 'does not
|
505
|
+
it 'does not destroy the associated item' do
|
244
506
|
expect { subject }.to_not change(Trashable, :count)
|
245
507
|
end
|
246
508
|
end
|
@@ -253,18 +515,36 @@ describe Draftsman::Draft do
|
|
253
515
|
end
|
254
516
|
|
255
517
|
subject { trashable.draft.revert!; return trashable.reload }
|
256
|
-
|
257
|
-
it
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
518
|
+
|
519
|
+
it 'does not raise an exception' do
|
520
|
+
expect { subject }.to_not raise_exception
|
521
|
+
end
|
522
|
+
|
523
|
+
it 'is not trashed' do
|
524
|
+
expect(subject.trashed?).to eql false
|
525
|
+
end
|
526
|
+
|
527
|
+
it 'is no longer a draft' do
|
528
|
+
expect(subject.draft?).to eql false
|
529
|
+
end
|
530
|
+
|
531
|
+
it 'does not have a `draft_id`' do
|
532
|
+
expect(subject.draft_id).to be_nil
|
533
|
+
end
|
534
|
+
|
535
|
+
it 'does not have a `draft`' do
|
536
|
+
expect(subject.draft).to be_nil
|
537
|
+
end
|
538
|
+
|
539
|
+
it 'does not have a `trashed_at` timestamp' do
|
540
|
+
expect(subject.trashed_at).to be_nil
|
541
|
+
end
|
542
|
+
|
543
|
+
it 'destroys the draft record' do
|
264
544
|
expect { subject }.to change(Draftsman::Draft, :count).by(-1)
|
265
545
|
end
|
266
546
|
|
267
|
-
it 'does not
|
547
|
+
it 'does not destroy the associated item' do
|
268
548
|
expect { subject }.to_not change(Trashable, :count)
|
269
549
|
end
|
270
550
|
end
|
@@ -276,38 +556,59 @@ describe Draftsman::Draft do
|
|
276
556
|
end
|
277
557
|
|
278
558
|
subject { trashable.draft.revert!; return trashable.reload }
|
279
|
-
|
280
|
-
it
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
559
|
+
|
560
|
+
it 'does not raise an exception' do
|
561
|
+
expect { subject }.to_not raise_exception
|
562
|
+
end
|
563
|
+
|
564
|
+
it 'is not trashed' do
|
565
|
+
expect(subject.trashed?).to eql false
|
566
|
+
end
|
567
|
+
|
568
|
+
it 'is a draft' do
|
569
|
+
expect(subject.draft?).to eql true
|
570
|
+
end
|
571
|
+
|
572
|
+
it 'has a `draft_id`' do
|
573
|
+
expect(subject.draft_id).to be_present
|
574
|
+
end
|
575
|
+
|
576
|
+
it 'has a `draft`' do
|
577
|
+
expect(subject.draft).to be_present
|
578
|
+
end
|
579
|
+
|
580
|
+
it 'does not have a `trashed_at` timestamp' do
|
581
|
+
expect(subject.trashed_at).to be_nil
|
582
|
+
end
|
583
|
+
|
584
|
+
it 'destroys the `destroy` draft record' do
|
287
585
|
expect { subject }.to change(Draftsman::Draft.where(:event => 'destroy'), :count).by(-1)
|
288
586
|
end
|
289
587
|
|
290
|
-
it 'reifies the previous `create` draft' do
|
588
|
+
it 'reifies the previous `create` draft record' do
|
291
589
|
expect { subject }.to change(Draftsman::Draft.where(:event => 'create'), :count).by(1)
|
292
590
|
end
|
293
591
|
|
294
|
-
it 'does not
|
592
|
+
it 'does not destroy the associated item' do
|
295
593
|
expect { subject }.to_not change(Trashable, :count)
|
296
594
|
end
|
297
595
|
|
298
|
-
|
299
|
-
subject.draft.previous_draft.
|
596
|
+
it "no longer has a `previous_draft`" do
|
597
|
+
expect(subject.draft.previous_draft).to be_nil
|
300
598
|
end
|
301
599
|
end
|
302
600
|
end
|
303
601
|
end
|
304
602
|
|
305
|
-
describe
|
603
|
+
describe 'reify' do
|
306
604
|
subject { trashable.draft.reify }
|
307
605
|
|
308
606
|
context 'with `create` draft' do
|
309
607
|
before { trashable.draft_creation }
|
310
|
-
|
608
|
+
|
609
|
+
it "has a `title` that matches the item's" do
|
610
|
+
expect(subject.title).to eql trashable.title
|
611
|
+
end
|
311
612
|
|
312
613
|
context 'updated create' do
|
313
614
|
before do
|
@@ -315,8 +616,13 @@ describe Draftsman::Draft do
|
|
315
616
|
trashable.draft_update
|
316
617
|
end
|
317
618
|
|
318
|
-
|
319
|
-
|
619
|
+
it 'has an updated `name`' do
|
620
|
+
expect(subject.name).to eql 'Sam'
|
621
|
+
end
|
622
|
+
|
623
|
+
it 'has no `title`' do
|
624
|
+
expect(subject.title).to be_nil
|
625
|
+
end
|
320
626
|
end
|
321
627
|
end
|
322
628
|
|
@@ -328,8 +634,13 @@ describe Draftsman::Draft do
|
|
328
634
|
trashable.draft_update
|
329
635
|
end
|
330
636
|
|
331
|
-
|
332
|
-
|
637
|
+
it 'has the updated `name`' do
|
638
|
+
expect(subject.name).to eql 'Sam'
|
639
|
+
end
|
640
|
+
|
641
|
+
it 'has the updated `title`' do
|
642
|
+
expect(subject.title).to eql 'My Title'
|
643
|
+
end
|
333
644
|
|
334
645
|
context 'updating the update' do
|
335
646
|
before do
|
@@ -337,8 +648,13 @@ describe Draftsman::Draft do
|
|
337
648
|
trashable.draft_update
|
338
649
|
end
|
339
650
|
|
340
|
-
|
341
|
-
|
651
|
+
it 'has the same `name`' do
|
652
|
+
expect(subject.name).to eql 'Sam'
|
653
|
+
end
|
654
|
+
|
655
|
+
it 'has the updated `title`' do
|
656
|
+
expect(subject.title).to be_nil
|
657
|
+
end
|
342
658
|
end
|
343
659
|
end
|
344
660
|
|
@@ -349,8 +665,13 @@ describe Draftsman::Draft do
|
|
349
665
|
trashable.draft_destroy
|
350
666
|
end
|
351
667
|
|
352
|
-
|
353
|
-
|
668
|
+
it 'records the `name`' do
|
669
|
+
expect(subject.name).to eql 'Bob'
|
670
|
+
end
|
671
|
+
|
672
|
+
it 'records the `title`' do
|
673
|
+
expect(subject.title).to be_nil
|
674
|
+
end
|
354
675
|
end
|
355
676
|
|
356
677
|
context 'with previous `create` draft' do
|
@@ -359,8 +680,13 @@ describe Draftsman::Draft do
|
|
359
680
|
trashable.draft_destroy
|
360
681
|
end
|
361
682
|
|
362
|
-
|
363
|
-
|
683
|
+
it 'records the `name`' do
|
684
|
+
expect(subject.name).to eql 'Bob'
|
685
|
+
end
|
686
|
+
|
687
|
+
it 'records the `title`' do
|
688
|
+
expect(subject.title).to be_nil
|
689
|
+
end
|
364
690
|
end
|
365
691
|
|
366
692
|
context 'with previous `update` draft' do
|
@@ -373,8 +699,13 @@ describe Draftsman::Draft do
|
|
373
699
|
trashable.reload.draft_destroy
|
374
700
|
end
|
375
701
|
|
376
|
-
|
377
|
-
|
702
|
+
it 'records the updated `name`' do
|
703
|
+
expect(subject.name).to eql 'Sam'
|
704
|
+
end
|
705
|
+
|
706
|
+
it 'records the updated `title`' do
|
707
|
+
expect(subject.title).to eql 'My Title'
|
708
|
+
end
|
378
709
|
end
|
379
710
|
end
|
380
711
|
end
|