draftsman 0.5.1 → 0.6.0
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/.travis.yml +12 -0
- data/CHANGELOG.md +34 -0
- data/README.md +244 -181
- data/lib/draftsman/config.rb +4 -1
- data/lib/draftsman/draft.rb +117 -80
- data/lib/draftsman/frameworks/rspec.rb +1 -1
- data/lib/draftsman/model.rb +253 -235
- data/lib/draftsman/version.rb +1 -1
- data/lib/draftsman.rb +26 -5
- data/lib/generators/draftsman/templates/config/initializers/draftsman.rb +16 -7
- data/spec/draftsman_spec.rb +7 -9
- data/spec/dummy/app/controllers/application_controller.rb +2 -2
- data/spec/dummy/app/models/overridden_draft.rb +7 -0
- data/spec/dummy/app/models/talkative.rb +21 -43
- data/spec/dummy/db/schema.rb +1 -0
- data/spec/models/child_spec.rb +17 -17
- data/spec/models/draft_spec.rb +893 -305
- data/spec/models/enumable_spec.rb +3 -2
- data/spec/models/overridden_draft_spec.rb +41 -0
- data/spec/models/parent_spec.rb +10 -10
- data/spec/models/skipper_spec.rb +221 -219
- data/spec/models/talkative_spec.rb +107 -108
- data/spec/models/trashable_spec.rb +6 -10
- data/spec/models/vanilla_spec.rb +570 -229
- data/spec/models/whitelister_spec.rb +489 -348
- metadata +7 -10
- data/spec/dummy/db/migrate/20110208155312_set_up_test_tables.rb +0 -95
- data/spec/dummy/db/migrate/20150404203627_add_talkatives_table_to_tests.rb +0 -18
- data/spec/dummy/db/migrate/20150408234937_add_only_children.rb +0 -16
- data/spec/dummy/db/migrate/20160328184419_create_enumables.rb +0 -9
data/spec/models/draft_spec.rb
CHANGED
@@ -1,226 +1,345 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Draftsman::Draft do
|
4
|
-
|
5
|
-
subject { Draftsman::Draft }
|
4
|
+
let(:trashable) { Trashable.new(name: 'Bob') }
|
6
5
|
|
6
|
+
describe '.object_col_is_json?' do
|
7
7
|
it 'does not have a JSON object column' do
|
8
|
-
expect(
|
8
|
+
expect(Draftsman::Draft.object_col_is_json?).to eql false
|
9
9
|
end
|
10
|
+
end
|
10
11
|
|
12
|
+
describe '.object_changes_col_is_json?' do
|
11
13
|
it 'does not have a JSON object_changes column' do
|
12
|
-
expect(
|
14
|
+
expect(Draftsman::Draft.object_changes_col_is_json?).to eql false
|
13
15
|
end
|
16
|
+
end
|
14
17
|
|
18
|
+
describe '.previous_draft_col_is_json?' do
|
15
19
|
it 'does not have a JSON previous_draft column' do
|
16
|
-
expect(
|
20
|
+
expect(Draftsman::Draft.previous_draft_col_is_json?).to eql false
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
|
-
describe '
|
21
|
-
|
22
|
-
|
24
|
+
describe '#event, #create?, #update?, #destroy?, #changeset' do
|
25
|
+
context 'with `create` draft' do
|
26
|
+
before { trashable.save_draft }
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
28
|
+
it 'is a `create` event' do
|
29
|
+
expect(trashable.draft.event).to eql 'create'
|
30
|
+
end
|
27
31
|
|
28
|
-
|
29
|
-
|
32
|
+
it 'identifies as a `create` event' do
|
33
|
+
expect(trashable.draft.create?).to eql true
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'does not identify as an `update` event' do
|
37
|
+
expect(trashable.draft.update?).to eql false
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'does not identify as a `destroy` event' do
|
41
|
+
expect(trashable.draft.destroy?).to eql false
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'has an `id` in the `changeset`' do
|
45
|
+
expect(trashable.draft.changeset).to include :id
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'has a `name` in the `changeset`' do
|
49
|
+
expect(trashable.draft.changeset).to include :name
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'does not have a `title` in the `changeset`' do
|
53
|
+
expect(trashable.draft.changeset).to_not include :title
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'has `created_at` in the `changeset`' do
|
57
|
+
expect(trashable.draft.changeset).to include :created_at
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'has `updated_at` in the `changeset`' do
|
61
|
+
expect(trashable.draft.changeset).to include :updated_at
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'does not have a `previous_draft`' do
|
65
|
+
expect(trashable.draft.previous_draft).to be_nil
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'updated create' do
|
69
|
+
before do
|
70
|
+
trashable.name = 'Sam'
|
71
|
+
trashable.save_draft
|
30
72
|
end
|
31
73
|
|
32
74
|
it 'identifies as a `create` event' do
|
33
|
-
expect(
|
75
|
+
expect(trashable.draft.create?).to eql true
|
34
76
|
end
|
35
77
|
|
36
78
|
it 'does not identify as an `update` event' do
|
37
|
-
expect(
|
79
|
+
expect(trashable.draft.update?).to eql false
|
38
80
|
end
|
39
81
|
|
40
82
|
it 'does not identify as a `destroy` event' do
|
41
|
-
expect(
|
83
|
+
expect(trashable.draft.destroy?).to eql false
|
42
84
|
end
|
43
85
|
|
44
|
-
it '
|
45
|
-
expect(
|
86
|
+
it 'is a `create` event' do
|
87
|
+
expect(trashable.draft.event).to eql 'create'
|
46
88
|
end
|
47
89
|
|
48
90
|
it 'has an `id` in the `changeset`' do
|
49
|
-
expect(
|
91
|
+
expect(trashable.draft.changeset).to include :id
|
50
92
|
end
|
51
93
|
|
52
94
|
it 'has a `name` in the `changeset`' do
|
53
|
-
expect(
|
95
|
+
expect(trashable.draft.changeset).to include :name
|
54
96
|
end
|
55
97
|
|
56
98
|
it 'does not have a `title` in the `changeset`' do
|
57
|
-
expect(
|
99
|
+
expect(trashable.draft.changeset).to_not include :title
|
58
100
|
end
|
59
101
|
|
60
102
|
it 'has `created_at` in the `changeset`' do
|
61
|
-
expect(
|
103
|
+
expect(trashable.draft.changeset).to include :created_at
|
62
104
|
end
|
63
105
|
|
64
106
|
it 'has `updated_at` in the `changeset`' do
|
65
|
-
expect(
|
107
|
+
expect(trashable.draft.changeset).to include :updated_at
|
66
108
|
end
|
67
109
|
|
68
110
|
it 'does not have a `previous_draft`' do
|
69
|
-
expect(
|
111
|
+
expect(trashable.draft.previous_draft).to be_nil
|
70
112
|
end
|
113
|
+
end
|
114
|
+
end
|
71
115
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
expect(subject.create?).to eql true
|
80
|
-
end
|
116
|
+
context 'with `update` draft' do
|
117
|
+
before do
|
118
|
+
trashable.save!
|
119
|
+
trashable.name = 'Sam'
|
120
|
+
trashable.title = 'My Title'
|
121
|
+
trashable.save_draft
|
122
|
+
end
|
81
123
|
|
82
|
-
|
83
|
-
|
84
|
-
|
124
|
+
it 'does not identify as a `create` event' do
|
125
|
+
expect(trashable.draft.create?).to eql false
|
126
|
+
end
|
85
127
|
|
86
|
-
|
87
|
-
|
88
|
-
|
128
|
+
it 'identifies as an `update event' do
|
129
|
+
expect(trashable.draft.update?).to eql true
|
130
|
+
end
|
89
131
|
|
90
|
-
|
91
|
-
|
92
|
-
|
132
|
+
it 'does not identify as a `destroy` event' do
|
133
|
+
expect(trashable.draft.destroy?).to eql false
|
134
|
+
end
|
93
135
|
|
94
|
-
|
95
|
-
|
96
|
-
|
136
|
+
it 'has an `update` event' do
|
137
|
+
expect(trashable.draft.event).to eql 'update'
|
138
|
+
end
|
97
139
|
|
98
|
-
|
99
|
-
|
100
|
-
|
140
|
+
it 'does not have an `id` in the `changeset`' do
|
141
|
+
expect(trashable.draft.changeset).to_not include :id
|
142
|
+
end
|
101
143
|
|
102
|
-
|
103
|
-
|
104
|
-
|
144
|
+
it 'has a `name` in the `changeset`' do
|
145
|
+
expect(trashable.draft.changeset).to include :name
|
146
|
+
end
|
105
147
|
|
106
|
-
|
107
|
-
|
108
|
-
|
148
|
+
it 'has a `title` in the `changeset`' do
|
149
|
+
expect(trashable.draft.changeset).to include :title
|
150
|
+
end
|
109
151
|
|
110
|
-
|
111
|
-
|
112
|
-
|
152
|
+
it 'does not have `created_at` in the `changeset`' do
|
153
|
+
expect(trashable.draft.changeset).to_not include :created_at
|
154
|
+
end
|
113
155
|
|
114
|
-
|
115
|
-
|
116
|
-
|
156
|
+
it 'does not have `updated_at` in the `changeset`' do
|
157
|
+
expect(trashable.draft.changeset).to_not include :updated_at
|
158
|
+
end
|
117
159
|
|
118
|
-
|
119
|
-
|
120
|
-
end
|
121
|
-
end
|
160
|
+
it 'does not have a `previous_draft`' do
|
161
|
+
expect(trashable.draft.previous_draft).to be_nil
|
122
162
|
end
|
123
163
|
|
124
|
-
context '
|
164
|
+
context 'updating the update' do
|
125
165
|
before do
|
126
|
-
trashable.
|
127
|
-
trashable.
|
128
|
-
trashable.
|
129
|
-
trashable.draft_update
|
166
|
+
trashable.title = nil
|
167
|
+
trashable.save_draft
|
168
|
+
trashable.reload
|
130
169
|
end
|
131
170
|
|
132
171
|
it 'does not identify as a `create` event' do
|
133
|
-
expect(
|
172
|
+
expect(trashable.draft.create?).to eql false
|
134
173
|
end
|
135
174
|
|
136
|
-
it 'identifies as an `update event' do
|
137
|
-
expect(
|
175
|
+
it 'identifies as an `update` event' do
|
176
|
+
expect(trashable.draft.update?).to eql true
|
138
177
|
end
|
139
178
|
|
140
179
|
it 'does not identify as a `destroy` event' do
|
141
|
-
expect(
|
180
|
+
expect(trashable.draft.destroy?).to eql false
|
142
181
|
end
|
143
182
|
|
144
183
|
it 'has an `update` event' do
|
145
|
-
expect(
|
146
|
-
end
|
147
|
-
|
148
|
-
it 'has an `object`' do
|
149
|
-
expect(subject.object).to be_present
|
184
|
+
expect(trashable.draft.event).to eql 'update'
|
150
185
|
end
|
151
186
|
|
152
187
|
it 'does not have an `id` in the `changeset`' do
|
153
|
-
expect(
|
188
|
+
expect(trashable.draft.changeset).to_not include :id
|
154
189
|
end
|
155
190
|
|
156
191
|
it 'has a `name` in the `changeset`' do
|
157
|
-
expect(
|
192
|
+
expect(trashable.draft.changeset).to include :name
|
158
193
|
end
|
159
194
|
|
160
|
-
it '
|
161
|
-
expect(
|
195
|
+
it 'does not have a `title` in the `changeset`' do
|
196
|
+
expect(trashable.draft.changeset).to_not include :title
|
162
197
|
end
|
163
198
|
|
164
199
|
it 'does not have `created_at` in the `changeset`' do
|
165
|
-
expect(
|
200
|
+
expect(trashable.draft.changeset).to_not include :created_at
|
166
201
|
end
|
167
202
|
|
168
203
|
it 'does not have `updated_at` in the `changeset`' do
|
169
|
-
expect(
|
204
|
+
expect(trashable.draft.changeset).to_not include :updated_at
|
170
205
|
end
|
171
206
|
|
172
207
|
it 'does not have a `previous_draft`' do
|
173
|
-
expect(
|
208
|
+
expect(trashable.draft.previous_draft).to be_nil
|
174
209
|
end
|
210
|
+
end
|
211
|
+
end
|
175
212
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
213
|
+
context 'with `destroy` draft' do
|
214
|
+
context 'without previous draft' do
|
215
|
+
before do
|
216
|
+
trashable.save!
|
217
|
+
trashable.draft_destruction
|
218
|
+
end
|
181
219
|
|
182
|
-
|
183
|
-
|
184
|
-
|
220
|
+
it 'does not identify as a `create` event' do
|
221
|
+
expect(trashable.draft.create?).to eql false
|
222
|
+
end
|
185
223
|
|
186
|
-
|
187
|
-
|
188
|
-
|
224
|
+
it 'does not identify as an `update` event' do
|
225
|
+
expect(trashable.draft.update?).to eql false
|
226
|
+
end
|
189
227
|
|
190
|
-
|
191
|
-
|
192
|
-
|
228
|
+
it 'identifies as a `destroy` event' do
|
229
|
+
expect(trashable.draft.destroy?).to eql true
|
230
|
+
end
|
193
231
|
|
194
|
-
|
195
|
-
|
196
|
-
|
232
|
+
it 'is not destroyed' do
|
233
|
+
expect(trashable.draft.destroyed?).to eql false
|
234
|
+
end
|
197
235
|
|
198
|
-
|
199
|
-
|
200
|
-
|
236
|
+
it 'is a `destroy` event' do
|
237
|
+
expect(trashable.draft.event).to eql 'destroy'
|
238
|
+
end
|
201
239
|
|
202
|
-
|
203
|
-
|
204
|
-
|
240
|
+
it 'has an empty `changeset`' do
|
241
|
+
expect(trashable.draft.changeset).to eql Hash.new
|
242
|
+
end
|
205
243
|
|
206
|
-
|
207
|
-
|
208
|
-
|
244
|
+
it 'does not have a `previous_draft`' do
|
245
|
+
expect(trashable.draft.previous_draft).to be_nil
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'with previous `create` draft' do
|
250
|
+
before do
|
251
|
+
trashable.save_draft
|
252
|
+
trashable.draft_destruction
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'does not identify as a `create` event' do
|
256
|
+
expect(trashable.draft.create?).to eql false
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'does not identify as an `update` event' do
|
260
|
+
expect(trashable.draft.update?).to eql false
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'identifies as a `destroy` event' do
|
264
|
+
expect(trashable.draft.destroy?).to eql true
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'is not destroyed' do
|
268
|
+
expect(trashable.draft.destroyed?).to eql false
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'is a `destroy` event' do
|
272
|
+
expect(trashable.draft.event).to eql 'destroy'
|
273
|
+
end
|
274
|
+
|
275
|
+
it 'has an `id` in the `changeset`' do
|
276
|
+
expect(trashable.draft.changeset).to include :id
|
277
|
+
end
|
209
278
|
|
210
|
-
|
211
|
-
|
279
|
+
it 'has a `name` in the `changeset`' do
|
280
|
+
expect(trashable.draft.changeset).to include :name
|
281
|
+
end
|
282
|
+
|
283
|
+
it 'does not have a `title` in the `changeset`' do
|
284
|
+
expect(trashable.draft.changeset).to_not include :title
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'has `created_at` in the `changeset`' do
|
288
|
+
expect(trashable.draft.changeset).to include :created_at
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'has `updated_at` in the `changeset`' do
|
292
|
+
expect(trashable.draft.changeset).to include :updated_at
|
293
|
+
end
|
294
|
+
|
295
|
+
it 'has a `previous_draft`' do
|
296
|
+
expect(trashable.draft.previous_draft).to be_present
|
297
|
+
end
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end # #event, #create?, #update?, #destroy?, #changeset
|
301
|
+
|
302
|
+
describe '#object' do
|
303
|
+
context 'with stashed drafted changes' do
|
304
|
+
context 'with `create` draft' do
|
305
|
+
before { trashable.save_draft }
|
306
|
+
|
307
|
+
it 'has an object' do
|
308
|
+
expect(trashable.draft.object).to be_present
|
309
|
+
end
|
310
|
+
|
311
|
+
context 'updated create' do
|
312
|
+
before do
|
313
|
+
trashable.name = 'Sam'
|
314
|
+
trashable.save_draft
|
212
315
|
end
|
213
316
|
|
214
|
-
it '
|
215
|
-
expect(
|
317
|
+
it 'has an `object`' do
|
318
|
+
expect(trashable.draft.object).to be_present
|
216
319
|
end
|
320
|
+
end
|
321
|
+
end
|
217
322
|
|
218
|
-
|
219
|
-
|
323
|
+
context 'with `update` draft' do
|
324
|
+
before do
|
325
|
+
trashable.save!
|
326
|
+
trashable.name = 'Sam'
|
327
|
+
trashable.title = 'My Title'
|
328
|
+
trashable.save_draft
|
329
|
+
end
|
330
|
+
|
331
|
+
it 'has an `object`' do
|
332
|
+
expect(trashable.draft.object).to be_present
|
333
|
+
end
|
334
|
+
|
335
|
+
context 'updating the update' do
|
336
|
+
before do
|
337
|
+
trashable.title = nil
|
338
|
+
trashable.save_draft
|
220
339
|
end
|
221
340
|
|
222
|
-
it '
|
223
|
-
expect(
|
341
|
+
it 'has an `object`' do
|
342
|
+
expect(trashable.draft.object).to be_present
|
224
343
|
end
|
225
344
|
end
|
226
345
|
end
|
@@ -232,135 +351,318 @@ describe Draftsman::Draft do
|
|
232
351
|
trashable.draft_destruction
|
233
352
|
end
|
234
353
|
|
235
|
-
it '
|
236
|
-
expect(
|
354
|
+
it 'has an `object`' do
|
355
|
+
expect(trashable.draft.object).to be_present
|
237
356
|
end
|
357
|
+
end
|
238
358
|
|
239
|
-
|
240
|
-
|
359
|
+
context 'with previous `create` draft' do
|
360
|
+
before do
|
361
|
+
trashable.save_draft
|
362
|
+
trashable.draft_destruction
|
241
363
|
end
|
242
364
|
|
243
|
-
it '
|
244
|
-
expect(
|
365
|
+
it 'has an `object`' do
|
366
|
+
expect(trashable.draft.object).to be_present
|
245
367
|
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end # with stashed drafted changes
|
246
371
|
|
247
|
-
|
248
|
-
|
249
|
-
|
372
|
+
context 'without stashed drafted changes' do
|
373
|
+
before { Draftsman.stash_drafted_changes = false }
|
374
|
+
after { Draftsman.stash_drafted_changes = true }
|
250
375
|
|
251
|
-
|
252
|
-
|
376
|
+
context 'with `create` draft' do
|
377
|
+
before { trashable.save_draft }
|
378
|
+
|
379
|
+
it 'has no object' do
|
380
|
+
expect(trashable.draft.object).to be_nil
|
381
|
+
end
|
382
|
+
|
383
|
+
context 'updated create' do
|
384
|
+
before do
|
385
|
+
trashable.name = 'Sam'
|
386
|
+
trashable.save_draft
|
387
|
+
trashable.reload
|
253
388
|
end
|
254
389
|
|
255
|
-
it 'has
|
256
|
-
expect(
|
390
|
+
it 'has no `object`' do
|
391
|
+
expect(trashable.draft.object).to be_nil
|
257
392
|
end
|
393
|
+
end
|
394
|
+
end
|
258
395
|
|
259
|
-
|
260
|
-
|
396
|
+
context 'with `update` draft' do
|
397
|
+
before do
|
398
|
+
trashable.save!
|
399
|
+
trashable.name = 'Sam'
|
400
|
+
trashable.title = 'My Title'
|
401
|
+
trashable.save_draft
|
402
|
+
trashable.reload
|
403
|
+
end
|
404
|
+
|
405
|
+
it 'has no `object`' do
|
406
|
+
expect(trashable.draft.object).to be_nil
|
407
|
+
end
|
408
|
+
|
409
|
+
context 'updating the update' do
|
410
|
+
before do
|
411
|
+
trashable.title = nil
|
412
|
+
trashable.save_draft
|
261
413
|
end
|
262
414
|
|
263
|
-
it '
|
264
|
-
expect(
|
415
|
+
it 'has no `object`' do
|
416
|
+
expect(trashable.draft.object).to be_nil
|
265
417
|
end
|
266
418
|
end
|
419
|
+
end
|
267
420
|
|
268
|
-
|
421
|
+
context 'with `destroy` draft' do
|
422
|
+
context 'without previous draft' do
|
269
423
|
before do
|
270
|
-
trashable.
|
424
|
+
trashable.save!
|
271
425
|
trashable.draft_destruction
|
272
426
|
end
|
273
427
|
|
274
|
-
it '
|
275
|
-
expect(
|
428
|
+
it 'has no `object`' do
|
429
|
+
expect(trashable.draft.object).to be_nil
|
276
430
|
end
|
431
|
+
end
|
277
432
|
|
278
|
-
|
279
|
-
|
433
|
+
context 'with previous `create` draft' do
|
434
|
+
before do
|
435
|
+
trashable.save_draft
|
436
|
+
trashable.draft_destruction
|
280
437
|
end
|
281
438
|
|
282
|
-
it '
|
283
|
-
expect(
|
439
|
+
it 'has no `object`' do
|
440
|
+
expect(trashable.draft.object).to be_nil
|
284
441
|
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end # without stashed drafted changes
|
445
|
+
end # #object
|
446
|
+
|
447
|
+
describe '#whodunnit' do
|
448
|
+
context 'with default `whodunnit` field name' do
|
449
|
+
it 'records value in `whodunnit`' do
|
450
|
+
::Draftsman.whodunnit = :foobar
|
451
|
+
trashable.save_draft
|
452
|
+
expect(trashable.reload.draft.whodunnit).to eql 'foobar'
|
453
|
+
end
|
454
|
+
end
|
285
455
|
|
286
|
-
|
287
|
-
|
288
|
-
|
456
|
+
context 'with custom `user_id` field' do
|
457
|
+
before { ::Draftsman.whodunnit_field = :user_id }
|
458
|
+
after { ::Draftsman.whodunnit_field = :whodunnit }
|
289
459
|
|
290
|
-
|
291
|
-
|
292
|
-
|
460
|
+
it 'records value in `user_id`' do
|
461
|
+
::Draftsman.whodunnit = 4321
|
462
|
+
trashable.save_draft
|
463
|
+
expect(trashable.reload.draft.user_id).to eql 4321
|
464
|
+
end
|
293
465
|
|
294
|
-
|
295
|
-
|
296
|
-
|
466
|
+
it 'does not record value in `whodunnit`' do
|
467
|
+
::Draftsman.whodunnit_field = :user_id
|
468
|
+
::Draftsman.whodunnit = :foobar
|
469
|
+
trashable.save_draft
|
470
|
+
expect(trashable.reload.draft.whodunnit).to be_nil
|
471
|
+
::Draftsman.whodunnit_field = :whodunnit
|
472
|
+
end
|
473
|
+
end
|
474
|
+
end
|
475
|
+
|
476
|
+
describe '#publish!' do
|
477
|
+
context 'with stashed drafted changes' do
|
478
|
+
context 'with `create` draft' do
|
479
|
+
before { trashable.save_draft }
|
480
|
+
|
481
|
+
it 'does not raise an exception' do
|
482
|
+
expect { trashable.draft.publish! }.to_not raise_exception
|
483
|
+
end
|
484
|
+
|
485
|
+
it 'publishes the item' do
|
486
|
+
trashable.draft.publish!
|
487
|
+
expect(trashable.reload.published?).to eql true
|
488
|
+
end
|
489
|
+
|
490
|
+
it 'is not trashed' do
|
491
|
+
trashable.draft.publish!
|
492
|
+
expect(trashable.reload.trashed?).to eql false
|
493
|
+
end
|
494
|
+
|
495
|
+
it 'is no longer a draft' do
|
496
|
+
trashable.draft.publish!
|
497
|
+
expect(trashable.reload.draft?).to eql false
|
498
|
+
end
|
499
|
+
|
500
|
+
it 'should have a `published_at` timestamp' do
|
501
|
+
trashable.draft.publish!
|
502
|
+
expect(trashable.reload.published_at).to be_present
|
503
|
+
end
|
504
|
+
|
505
|
+
it 'does not have a `draft_id`' do
|
506
|
+
trashable.draft.publish!
|
507
|
+
expect(trashable.reload.draft_id).to be_nil
|
508
|
+
end
|
509
|
+
|
510
|
+
it 'does not have a draft' do
|
511
|
+
trashable.draft.publish!
|
512
|
+
expect(trashable.reload.draft).to be_nil
|
513
|
+
end
|
514
|
+
|
515
|
+
it 'does not have a `trashed_at` timestamp' do
|
516
|
+
trashable.draft.publish!
|
517
|
+
expect(trashable.reload.trashed_at).to be_nil
|
518
|
+
end
|
519
|
+
|
520
|
+
it 'deletes the draft record' do
|
521
|
+
expect { trashable.draft.publish! }.to change(Draftsman::Draft, :count).by(-1)
|
522
|
+
end
|
523
|
+
end # with `create` draft
|
524
|
+
|
525
|
+
context 'with `update` draft' do
|
526
|
+
before do
|
527
|
+
trashable.save!
|
528
|
+
trashable.name = 'Sam'
|
529
|
+
trashable.save_draft
|
530
|
+
end
|
531
|
+
|
532
|
+
it 'does not raise an exception' do
|
533
|
+
expect { trashable.draft.publish! }.to_not raise_exception
|
534
|
+
end
|
535
|
+
|
536
|
+
it 'publishes the item' do
|
537
|
+
trashable.draft.publish!
|
538
|
+
expect(trashable.reload.published?).to eql true
|
539
|
+
end
|
540
|
+
|
541
|
+
it 'is no longer a draft' do
|
542
|
+
trashable.draft.publish!
|
543
|
+
expect(trashable.reload.draft?).to eql false
|
544
|
+
end
|
545
|
+
|
546
|
+
it 'is not trashed' do
|
547
|
+
trashable.draft.publish!
|
548
|
+
expect(trashable.reload.trashed?).to eql false
|
549
|
+
end
|
297
550
|
|
298
|
-
|
299
|
-
|
551
|
+
it 'has an updated `name`' do
|
552
|
+
trashable.draft.publish!
|
553
|
+
expect(trashable.reload.name).to eql 'Sam'
|
554
|
+
end
|
555
|
+
|
556
|
+
it 'has a `published_at` timestamp' do
|
557
|
+
trashable.draft.publish!
|
558
|
+
expect(trashable.reload.published_at).to be_present
|
559
|
+
end
|
560
|
+
|
561
|
+
it 'does not have a `draft_id`' do
|
562
|
+
trashable.draft.publish!
|
563
|
+
expect(trashable.reload.draft_id).to be_nil
|
564
|
+
end
|
565
|
+
|
566
|
+
it 'does not have a `draft`' do
|
567
|
+
trashable.draft.publish!
|
568
|
+
expect(trashable.reload.draft).to be_nil
|
569
|
+
end
|
570
|
+
|
571
|
+
it 'does not have a `trashed_at` timestamp' do
|
572
|
+
trashable.draft.publish!
|
573
|
+
expect(trashable.reload.trashed_at).to be_nil
|
574
|
+
end
|
575
|
+
|
576
|
+
it 'destroys the draft' do
|
577
|
+
expect { trashable.draft.publish! }.to change(Draftsman::Draft, :count).by(-1)
|
578
|
+
end
|
579
|
+
|
580
|
+
it 'does not delete the associated item' do
|
581
|
+
expect { trashable.draft.publish! }.to_not change(Trashable, :count)
|
582
|
+
end
|
583
|
+
end # with `update` draft
|
584
|
+
|
585
|
+
context 'with `destroy` draft' do
|
586
|
+
context 'without previous draft' do
|
587
|
+
before do
|
588
|
+
trashable.save!
|
589
|
+
trashable.draft_destruction
|
300
590
|
end
|
301
591
|
|
302
|
-
it '
|
303
|
-
expect
|
592
|
+
it 'destroys the draft' do
|
593
|
+
expect { trashable.draft.publish! }.to change(Draftsman::Draft, :count).by(-1)
|
304
594
|
end
|
305
595
|
|
306
|
-
it '
|
307
|
-
expect
|
596
|
+
it 'deletes the associated item' do
|
597
|
+
expect { trashable.draft.publish! }.to change(Trashable, :count).by(-1)
|
308
598
|
end
|
599
|
+
end
|
309
600
|
|
310
|
-
|
311
|
-
|
601
|
+
context 'with previous `create` draft' do
|
602
|
+
before do
|
603
|
+
trashable.save_draft
|
604
|
+
trashable.draft_destruction
|
312
605
|
end
|
313
606
|
|
314
|
-
it '
|
315
|
-
expect
|
607
|
+
it 'destroys the draft' do
|
608
|
+
expect { trashable.draft.publish! }.to change(Draftsman::Draft, :count).by(-1)
|
316
609
|
end
|
317
610
|
|
318
|
-
it '
|
319
|
-
expect
|
611
|
+
it 'deletes the associated item' do
|
612
|
+
expect { trashable.draft.publish! }.to change(Trashable, :count).by(-1)
|
320
613
|
end
|
321
614
|
end
|
322
615
|
end
|
323
|
-
end
|
616
|
+
end # with stashed drafted changes
|
617
|
+
|
618
|
+
context 'without stashed drafted changes' do
|
619
|
+
before { Draftsman.stash_drafted_changes = false }
|
620
|
+
after { Draftsman.stash_drafted_changes = true }
|
324
621
|
|
325
|
-
describe 'publish!' do
|
326
622
|
context 'with `create` draft' do
|
327
|
-
before { trashable.
|
328
|
-
subject { trashable.draft.publish!; return trashable.reload }
|
623
|
+
before { trashable.save_draft }
|
329
624
|
|
330
625
|
it 'does not raise an exception' do
|
331
|
-
expect {
|
626
|
+
expect { trashable.draft.publish! }.to_not raise_exception
|
332
627
|
end
|
333
628
|
|
334
629
|
it 'publishes the item' do
|
335
|
-
|
630
|
+
trashable.draft.publish!
|
631
|
+
expect(trashable.reload.published?).to eql true
|
336
632
|
end
|
337
633
|
|
338
634
|
it 'is not trashed' do
|
339
|
-
|
635
|
+
trashable.draft.publish!
|
636
|
+
expect(trashable.reload.trashed?).to eql false
|
340
637
|
end
|
341
638
|
|
342
639
|
it 'is no longer a draft' do
|
343
|
-
|
640
|
+
trashable.draft.publish!
|
641
|
+
expect(trashable.reload.draft?).to eql false
|
344
642
|
end
|
345
643
|
|
346
644
|
it 'should have a `published_at` timestamp' do
|
347
|
-
|
645
|
+
trashable.draft.publish!
|
646
|
+
expect(trashable.reload.published_at).to be_present
|
348
647
|
end
|
349
648
|
|
350
649
|
it 'does not have a `draft_id`' do
|
351
|
-
|
650
|
+
trashable.draft.publish!
|
651
|
+
expect(trashable.reload.draft_id).to be_nil
|
352
652
|
end
|
353
653
|
|
354
654
|
it 'does not have a draft' do
|
355
|
-
|
655
|
+
trashable.draft.publish!
|
656
|
+
expect(trashable.reload.draft).to be_nil
|
356
657
|
end
|
357
658
|
|
358
659
|
it 'does not have a `trashed_at` timestamp' do
|
359
|
-
|
660
|
+
trashable.draft.publish!
|
661
|
+
expect(trashable.reload.trashed_at).to be_nil
|
360
662
|
end
|
361
663
|
|
362
664
|
it 'deletes the draft record' do
|
363
|
-
expect {
|
665
|
+
expect { trashable.draft.publish! }.to change(Draftsman::Draft, :count).by(-1)
|
364
666
|
end
|
365
667
|
end
|
366
668
|
|
@@ -368,53 +670,59 @@ describe Draftsman::Draft do
|
|
368
670
|
before do
|
369
671
|
trashable.save!
|
370
672
|
trashable.name = 'Sam'
|
371
|
-
trashable.
|
673
|
+
trashable.save_draft
|
372
674
|
end
|
373
675
|
|
374
|
-
subject { trashable.draft.publish!; return trashable.reload }
|
375
|
-
|
376
676
|
it 'does not raise an exception' do
|
377
|
-
expect {
|
677
|
+
expect { trashable.draft.publish! }.to_not raise_exception
|
378
678
|
end
|
379
679
|
|
380
680
|
it 'publishes the item' do
|
381
|
-
|
681
|
+
trashable.draft.publish!
|
682
|
+
expect(trashable.reload.published?).to eql true
|
382
683
|
end
|
383
684
|
|
384
685
|
it 'is no longer a draft' do
|
385
|
-
|
686
|
+
trashable.draft.publish!
|
687
|
+
expect(trashable.reload.draft?).to eql false
|
386
688
|
end
|
387
689
|
|
388
690
|
it 'is not trashed' do
|
389
|
-
|
691
|
+
trashable.draft.publish!
|
692
|
+
expect(trashable.reload.trashed?).to eql false
|
390
693
|
end
|
391
694
|
|
392
695
|
it 'has an updated `name`' do
|
393
|
-
|
696
|
+
trashable.draft.publish!
|
697
|
+
expect(trashable.reload.name).to eql 'Sam'
|
394
698
|
end
|
395
699
|
|
396
700
|
it 'has a `published_at` timestamp' do
|
397
|
-
|
701
|
+
trashable.draft.publish!
|
702
|
+
expect(trashable.reload.published_at).to be_present
|
398
703
|
end
|
399
704
|
|
400
705
|
it 'does not have a `draft_id`' do
|
401
|
-
|
706
|
+
trashable.draft.publish!
|
707
|
+
expect(trashable.reload.draft_id).to be_nil
|
402
708
|
end
|
403
709
|
|
404
710
|
it 'does not have a `draft`' do
|
405
|
-
|
711
|
+
trashable.draft.publish!
|
712
|
+
expect(trashable.reload.draft).to be_nil
|
406
713
|
end
|
407
714
|
|
408
715
|
it 'does not have a `trashed_at` timestamp' do
|
409
|
-
|
716
|
+
trashable.draft.publish!
|
717
|
+
expect(trashable.reload.trashed_at).to be_nil
|
410
718
|
end
|
411
719
|
|
412
720
|
it 'destroys the draft' do
|
413
|
-
expect {
|
721
|
+
expect { trashable.draft.publish! }.to change(Draftsman::Draft, :count).by(-1)
|
414
722
|
end
|
415
723
|
|
416
724
|
it 'does not delete the associated item' do
|
417
|
-
expect {
|
725
|
+
expect { trashable.draft.publish! }.to_not change(Trashable, :count)
|
418
726
|
end
|
419
727
|
end
|
420
728
|
|
@@ -425,51 +733,48 @@ describe Draftsman::Draft do
|
|
425
733
|
trashable.draft_destruction
|
426
734
|
end
|
427
735
|
|
428
|
-
subject { trashable.draft.publish! }
|
429
|
-
|
430
736
|
it 'destroys the draft' do
|
431
|
-
expect {
|
737
|
+
expect { trashable.draft.publish! }.to change(Draftsman::Draft, :count).by(-1)
|
432
738
|
end
|
433
739
|
|
434
740
|
it 'deletes the associated item' do
|
435
|
-
expect {
|
741
|
+
expect { trashable.draft.publish! }.to change(Trashable, :count).by(-1)
|
436
742
|
end
|
437
743
|
end
|
438
744
|
|
439
745
|
context 'with previous `create` draft' do
|
440
746
|
before do
|
441
|
-
trashable.
|
747
|
+
trashable.save_draft
|
442
748
|
trashable.draft_destruction
|
443
749
|
end
|
444
750
|
|
445
|
-
subject { trashable.draft.publish! }
|
446
|
-
|
447
751
|
it 'destroys the draft' do
|
448
|
-
expect {
|
752
|
+
expect { trashable.draft.publish! }.to change(Draftsman::Draft, :count).by(-1)
|
449
753
|
end
|
450
754
|
|
451
755
|
it 'deletes the associated item' do
|
452
|
-
expect {
|
756
|
+
expect { trashable.draft.publish! }.to change(Trashable, :count).by(-1)
|
453
757
|
end
|
454
758
|
end
|
455
759
|
end
|
456
|
-
end
|
760
|
+
end # without stashed draft changes
|
761
|
+
end # #publish!
|
457
762
|
|
458
|
-
|
763
|
+
describe '#revert!' do
|
764
|
+
context 'with stashed draft changes' do
|
459
765
|
context 'with `create` draft' do
|
460
|
-
before { trashable.
|
461
|
-
subject { trashable.draft.revert! }
|
766
|
+
before { trashable.save_draft }
|
462
767
|
|
463
768
|
it 'does not raise an exception' do
|
464
|
-
expect {
|
769
|
+
expect { trashable.draft.revert! }.to_not raise_exception
|
465
770
|
end
|
466
771
|
|
467
772
|
it 'destroys the draft' do
|
468
|
-
expect {
|
773
|
+
expect { trashable.draft.revert! }.to change(Draftsman::Draft, :count).by(-1)
|
469
774
|
end
|
470
775
|
|
471
776
|
it 'destroys associated item' do
|
472
|
-
expect {
|
777
|
+
expect { trashable.draft.revert! }.to change(Trashable, :count).by(-1)
|
473
778
|
end
|
474
779
|
end
|
475
780
|
|
@@ -477,39 +782,41 @@ describe Draftsman::Draft do
|
|
477
782
|
before do
|
478
783
|
trashable.save!
|
479
784
|
trashable.name = 'Sam'
|
480
|
-
trashable.
|
785
|
+
trashable.save_draft
|
481
786
|
end
|
482
787
|
|
483
|
-
subject { trashable.draft.revert!; return trashable.reload }
|
484
|
-
|
485
788
|
it 'does not raise an exception' do
|
486
|
-
expect {
|
789
|
+
expect { trashable.draft.revert! }.to_not raise_exception
|
487
790
|
end
|
488
791
|
|
489
792
|
it 'is no longer a draft' do
|
490
|
-
|
793
|
+
trashable.draft.revert!
|
794
|
+
expect(trashable.reload.draft?).to eql false
|
491
795
|
end
|
492
796
|
|
493
797
|
it 'reverts its `name`' do
|
494
|
-
|
798
|
+
trashable.draft.revert!
|
799
|
+
expect(trashable.reload.name).to eql 'Bob'
|
495
800
|
end
|
496
801
|
|
497
802
|
it 'does not have a `draft_id`' do
|
498
|
-
|
803
|
+
trashable.draft.revert!
|
804
|
+
expect(trashable.reload.draft_id).to be_nil
|
499
805
|
end
|
500
806
|
|
501
807
|
it 'does not have a `draft`' do
|
502
|
-
|
808
|
+
trashable.draft.revert!
|
809
|
+
expect(trashable.reload.draft).to be_nil
|
503
810
|
end
|
504
811
|
|
505
812
|
it 'destroys the draft record' do
|
506
|
-
expect {
|
813
|
+
expect { trashable.draft.revert! }.to change(Draftsman::Draft, :count).by(-1)
|
507
814
|
end
|
508
815
|
|
509
816
|
it 'does not destroy the associated item' do
|
510
|
-
expect {
|
817
|
+
expect { trashable.draft.revert! }.to_not change(Trashable, :count)
|
511
818
|
end
|
512
|
-
end
|
819
|
+
end # with `update` draft
|
513
820
|
|
514
821
|
context 'with `destroy` draft' do
|
515
822
|
context 'without previous draft' do
|
@@ -518,115 +825,116 @@ describe Draftsman::Draft do
|
|
518
825
|
trashable.draft_destruction
|
519
826
|
end
|
520
827
|
|
521
|
-
subject { trashable.draft.revert!; return trashable.reload }
|
522
|
-
|
523
828
|
it 'does not raise an exception' do
|
524
|
-
expect {
|
829
|
+
expect { trashable.draft.revert! }.to_not raise_exception
|
525
830
|
end
|
526
831
|
|
527
832
|
it 'is not trashed' do
|
528
|
-
|
833
|
+
trashable.draft.revert!
|
834
|
+
expect(trashable.reload.trashed?).to eql false
|
529
835
|
end
|
530
836
|
|
531
837
|
it 'is no longer a draft' do
|
532
|
-
|
838
|
+
trashable.draft.revert!
|
839
|
+
expect(trashable.reload.draft?).to eql false
|
533
840
|
end
|
534
841
|
|
535
842
|
it 'does not have a `draft_id`' do
|
536
|
-
|
843
|
+
trashable.draft.revert!
|
844
|
+
expect(trashable.reload.draft_id).to be_nil
|
537
845
|
end
|
538
846
|
|
539
847
|
it 'does not have a `draft`' do
|
540
|
-
|
848
|
+
trashable.draft.revert!
|
849
|
+
expect(trashable.reload.draft).to be_nil
|
541
850
|
end
|
542
851
|
|
543
852
|
it 'does not have a `trashed_at` timestamp' do
|
544
|
-
|
853
|
+
trashable.draft.revert!
|
854
|
+
expect(trashable.reload.trashed_at).to be_nil
|
545
855
|
end
|
546
856
|
|
547
857
|
it 'destroys the draft record' do
|
548
|
-
expect {
|
858
|
+
expect { trashable.draft.revert! }.to change(Draftsman::Draft, :count).by(-1)
|
549
859
|
end
|
550
860
|
|
551
861
|
it 'does not destroy the associated item' do
|
552
|
-
expect {
|
862
|
+
expect { trashable.draft.revert! }.to_not change(Trashable, :count)
|
553
863
|
end
|
554
|
-
end
|
864
|
+
end # without previous draft
|
555
865
|
|
556
866
|
context 'with previous `create` draft' do
|
557
867
|
before do
|
558
|
-
trashable.
|
868
|
+
trashable.save_draft
|
559
869
|
trashable.draft_destruction
|
560
870
|
end
|
561
871
|
|
562
|
-
subject { trashable.draft.revert!; return trashable.reload }
|
563
|
-
|
564
872
|
it 'does not raise an exception' do
|
565
|
-
expect {
|
873
|
+
expect { trashable.draft.revert! }.to_not raise_exception
|
566
874
|
end
|
567
875
|
|
568
876
|
it 'is not trashed' do
|
569
|
-
|
877
|
+
trashable.draft.revert!
|
878
|
+
expect(trashable.reload.trashed?).to eql false
|
570
879
|
end
|
571
880
|
|
572
881
|
it 'is a draft' do
|
573
|
-
|
882
|
+
trashable.draft.revert!
|
883
|
+
expect(trashable.reload.draft?).to eql true
|
574
884
|
end
|
575
885
|
|
576
886
|
it 'has a `draft_id`' do
|
577
|
-
|
887
|
+
trashable.draft.revert!
|
888
|
+
expect(trashable.reload.draft_id).to be_present
|
578
889
|
end
|
579
890
|
|
580
891
|
it 'has a `draft`' do
|
581
|
-
|
892
|
+
trashable.draft.revert!
|
893
|
+
expect(trashable.reload.draft).to be_present
|
582
894
|
end
|
583
895
|
|
584
896
|
it 'does not have a `trashed_at` timestamp' do
|
585
|
-
|
897
|
+
trashable.draft.revert!
|
898
|
+
expect(trashable.reload.trashed_at).to be_nil
|
586
899
|
end
|
587
900
|
|
588
901
|
it 'destroys the `destroy` draft record' do
|
589
|
-
expect {
|
902
|
+
expect { trashable.draft.revert! }.to change(Draftsman::Draft.where(event: :destroy), :count).by(-1)
|
590
903
|
end
|
591
904
|
|
592
905
|
it 'reifies the previous `create` draft record' do
|
593
|
-
expect {
|
906
|
+
expect { trashable.draft.revert! }.to change(Draftsman::Draft.where(event: :create), :count).by(1)
|
594
907
|
end
|
595
908
|
|
596
909
|
it 'does not destroy the associated item' do
|
597
|
-
expect {
|
910
|
+
expect { trashable.draft.revert! }.to_not change(Trashable, :count)
|
598
911
|
end
|
599
912
|
|
600
913
|
it "no longer has a `previous_draft`" do
|
601
|
-
|
914
|
+
trashable.draft.revert!
|
915
|
+
expect(trashable.reload.draft.previous_draft).to be_nil
|
602
916
|
end
|
603
|
-
end
|
604
|
-
end
|
605
|
-
end
|
917
|
+
end # with previous `create` draft
|
918
|
+
end # with `destroy` draft
|
919
|
+
end # with stashed draft changes
|
606
920
|
|
607
|
-
|
608
|
-
|
921
|
+
context 'without stashed draft changes' do
|
922
|
+
before { Draftsman.stash_drafted_changes = false }
|
923
|
+
after { Draftsman.stash_drafted_changes = true }
|
609
924
|
|
610
925
|
context 'with `create` draft' do
|
611
|
-
before { trashable.
|
926
|
+
before { trashable.save_draft }
|
612
927
|
|
613
|
-
it
|
614
|
-
expect
|
928
|
+
it 'does not raise an exception' do
|
929
|
+
expect { trashable.draft.revert! }.to_not raise_exception
|
615
930
|
end
|
616
931
|
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
trashable.draft_update
|
621
|
-
end
|
622
|
-
|
623
|
-
it 'has an updated `name`' do
|
624
|
-
expect(subject.name).to eql 'Sam'
|
625
|
-
end
|
932
|
+
it 'destroys the draft' do
|
933
|
+
expect { trashable.draft.revert! }.to change(Draftsman::Draft, :count).by(-1)
|
934
|
+
end
|
626
935
|
|
627
|
-
|
628
|
-
|
629
|
-
end
|
936
|
+
it 'destroys associated item' do
|
937
|
+
expect { trashable.draft.revert! }.to change(Trashable, :count).by(-1)
|
630
938
|
end
|
631
939
|
end
|
632
940
|
|
@@ -634,33 +942,41 @@ describe Draftsman::Draft do
|
|
634
942
|
before do
|
635
943
|
trashable.save!
|
636
944
|
trashable.name = 'Sam'
|
637
|
-
trashable.
|
638
|
-
trashable.draft_update
|
945
|
+
trashable.save_draft
|
639
946
|
end
|
640
947
|
|
641
|
-
it '
|
642
|
-
expect
|
948
|
+
it 'does not raise an exception' do
|
949
|
+
expect { trashable.draft.revert! }.to_not raise_exception
|
643
950
|
end
|
644
951
|
|
645
|
-
it '
|
646
|
-
|
952
|
+
it 'is no longer a draft' do
|
953
|
+
trashable.draft.revert!
|
954
|
+
expect(trashable.reload.draft?).to eql false
|
647
955
|
end
|
648
956
|
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
end
|
957
|
+
it 'reverts its `name`' do
|
958
|
+
trashable.draft.revert!
|
959
|
+
expect(trashable.reload.name).to eql 'Bob'
|
960
|
+
end
|
654
961
|
|
655
|
-
|
656
|
-
|
657
|
-
|
962
|
+
it 'does not have a `draft_id`' do
|
963
|
+
trashable.draft.revert!
|
964
|
+
expect(trashable.reload.draft_id).to be_nil
|
965
|
+
end
|
658
966
|
|
659
|
-
|
660
|
-
|
661
|
-
|
967
|
+
it 'does not have a `draft`' do
|
968
|
+
trashable.draft.revert!
|
969
|
+
expect(trashable.reload.draft).to be_nil
|
662
970
|
end
|
663
|
-
|
971
|
+
|
972
|
+
it 'destroys the draft record' do
|
973
|
+
expect { trashable.draft.revert! }.to change(Draftsman::Draft, :count).by(-1)
|
974
|
+
end
|
975
|
+
|
976
|
+
it 'does not destroy the associated item' do
|
977
|
+
expect { trashable.draft.revert! }.to_not change(Trashable, :count)
|
978
|
+
end
|
979
|
+
end # with `update` draft
|
664
980
|
|
665
981
|
context 'with `destroy` draft' do
|
666
982
|
context 'without previous draft' do
|
@@ -669,49 +985,321 @@ describe Draftsman::Draft do
|
|
669
985
|
trashable.draft_destruction
|
670
986
|
end
|
671
987
|
|
672
|
-
it '
|
673
|
-
expect
|
988
|
+
it 'does not raise an exception' do
|
989
|
+
expect { trashable.draft.revert! }.to_not raise_exception
|
674
990
|
end
|
675
991
|
|
676
|
-
it '
|
677
|
-
|
992
|
+
it 'is not trashed' do
|
993
|
+
trashable.draft.revert!
|
994
|
+
expect(trashable.reload.trashed?).to eql false
|
678
995
|
end
|
679
|
-
|
996
|
+
|
997
|
+
it 'is no longer a draft' do
|
998
|
+
trashable.draft.revert!
|
999
|
+
expect(trashable.reload.draft?).to eql false
|
1000
|
+
end
|
1001
|
+
|
1002
|
+
it 'does not have a `draft_id`' do
|
1003
|
+
trashable.draft.revert!
|
1004
|
+
expect(trashable.reload.draft_id).to be_nil
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
it 'does not have a `draft`' do
|
1008
|
+
trashable.draft.revert!
|
1009
|
+
expect(trashable.reload.draft).to be_nil
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
it 'does not have a `trashed_at` timestamp' do
|
1013
|
+
trashable.draft.revert!
|
1014
|
+
expect(trashable.reload.trashed_at).to be_nil
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
it 'destroys the draft record' do
|
1018
|
+
expect { trashable.draft.revert! }.to change(Draftsman::Draft, :count).by(-1)
|
1019
|
+
end
|
1020
|
+
|
1021
|
+
it 'does not destroy the associated item' do
|
1022
|
+
expect { trashable.draft.revert! }.to_not change(Trashable, :count)
|
1023
|
+
end
|
1024
|
+
end # without previous draft
|
680
1025
|
|
681
1026
|
context 'with previous `create` draft' do
|
682
1027
|
before do
|
683
|
-
trashable.
|
1028
|
+
trashable.save_draft
|
684
1029
|
trashable.draft_destruction
|
685
1030
|
end
|
686
1031
|
|
687
|
-
it '
|
688
|
-
expect
|
1032
|
+
it 'does not raise an exception' do
|
1033
|
+
expect { trashable.draft.revert! }.to_not raise_exception
|
689
1034
|
end
|
690
1035
|
|
691
|
-
it '
|
692
|
-
|
1036
|
+
it 'is not trashed' do
|
1037
|
+
trashable.draft.revert!
|
1038
|
+
expect(trashable.reload.trashed?).to eql false
|
693
1039
|
end
|
694
|
-
end
|
695
1040
|
|
696
|
-
|
697
|
-
|
698
|
-
trashable.
|
699
|
-
trashable.name = 'Sam'
|
700
|
-
trashable.title = 'My Title'
|
701
|
-
trashable.draft_update
|
702
|
-
# Typically, 2 draft operations won't happen in the same request, so reload before draft-destroying.
|
703
|
-
trashable.reload.draft_destruction
|
1041
|
+
it 'is a draft' do
|
1042
|
+
trashable.draft.revert!
|
1043
|
+
expect(trashable.reload.draft?).to eql true
|
704
1044
|
end
|
705
1045
|
|
706
|
-
it '
|
707
|
-
|
1046
|
+
it 'has a `draft_id`' do
|
1047
|
+
trashable.draft.revert!
|
1048
|
+
expect(trashable.reload.draft_id).to be_present
|
708
1049
|
end
|
709
1050
|
|
710
|
-
it '
|
711
|
-
|
1051
|
+
it 'has a `draft`' do
|
1052
|
+
trashable.draft.revert!
|
1053
|
+
expect(trashable.reload.draft).to be_present
|
1054
|
+
end
|
1055
|
+
|
1056
|
+
it 'does not have a `trashed_at` timestamp' do
|
1057
|
+
trashable.draft.revert!
|
1058
|
+
expect(trashable.reload.trashed_at).to be_nil
|
712
1059
|
end
|
1060
|
+
|
1061
|
+
it 'destroys the `destroy` draft record' do
|
1062
|
+
expect { trashable.draft.revert! }.to change(Draftsman::Draft.where(event: :destroy), :count).by(-1)
|
1063
|
+
end
|
1064
|
+
|
1065
|
+
it 'reifies the previous `create` draft record' do
|
1066
|
+
expect { trashable.draft.revert! }.to change(Draftsman::Draft.where(event: :create), :count).by(1)
|
1067
|
+
end
|
1068
|
+
|
1069
|
+
it 'does not destroy the associated item' do
|
1070
|
+
expect { trashable.draft.revert! }.to_not change(Trashable, :count)
|
1071
|
+
end
|
1072
|
+
|
1073
|
+
it "no longer has a `previous_draft`" do
|
1074
|
+
trashable.draft.revert!
|
1075
|
+
expect(trashable.reload.draft.previous_draft).to be_nil
|
1076
|
+
end
|
1077
|
+
end # with previous `create` draft
|
1078
|
+
end # with `destroy` draft
|
1079
|
+
end # without stashed draft changes
|
1080
|
+
end # #revert!
|
1081
|
+
|
1082
|
+
describe '#reify' do
|
1083
|
+
context 'with `create` draft' do
|
1084
|
+
before { trashable.save_draft }
|
1085
|
+
|
1086
|
+
it "has a `title` that matches the item's" do
|
1087
|
+
expect(trashable.draft.reify.title).to eql trashable.title
|
1088
|
+
end
|
1089
|
+
|
1090
|
+
context 'updated create' do
|
1091
|
+
before do
|
1092
|
+
trashable.name = 'Sam'
|
1093
|
+
trashable.save_draft
|
1094
|
+
end
|
1095
|
+
|
1096
|
+
it 'has an updated `name`' do
|
1097
|
+
expect(trashable.draft.reify.name).to eql 'Sam'
|
1098
|
+
end
|
1099
|
+
|
1100
|
+
it 'has no `title`' do
|
1101
|
+
expect(trashable.draft.reify.title).to be_nil
|
713
1102
|
end
|
714
1103
|
end
|
715
1104
|
end
|
716
|
-
|
1105
|
+
|
1106
|
+
context 'with `update` draft' do
|
1107
|
+
before do
|
1108
|
+
trashable.save!
|
1109
|
+
trashable.name = 'Sam'
|
1110
|
+
trashable.title = 'My Title'
|
1111
|
+
trashable.save_draft
|
1112
|
+
end
|
1113
|
+
|
1114
|
+
it 'has the updated `name`' do
|
1115
|
+
expect(trashable.draft.reify.name).to eql 'Sam'
|
1116
|
+
end
|
1117
|
+
|
1118
|
+
it 'has the updated `title`' do
|
1119
|
+
expect(trashable.draft.reify.title).to eql 'My Title'
|
1120
|
+
end
|
1121
|
+
|
1122
|
+
context 'updating the update' do
|
1123
|
+
before do
|
1124
|
+
trashable.title = nil
|
1125
|
+
trashable.save_draft
|
1126
|
+
trashable.reload
|
1127
|
+
end
|
1128
|
+
|
1129
|
+
it 'has the same `name`' do
|
1130
|
+
expect(trashable.draft.reify.name).to eql 'Sam'
|
1131
|
+
end
|
1132
|
+
|
1133
|
+
it 'has the updated `title`' do
|
1134
|
+
expect(trashable.draft.reify.title).to be_nil
|
1135
|
+
end
|
1136
|
+
end
|
1137
|
+
end
|
1138
|
+
|
1139
|
+
context 'with `destroy` draft' do
|
1140
|
+
context 'without previous draft' do
|
1141
|
+
before do
|
1142
|
+
trashable.save!
|
1143
|
+
trashable.draft_destruction
|
1144
|
+
end
|
1145
|
+
|
1146
|
+
it 'records the `name`' do
|
1147
|
+
expect(trashable.draft.reify.name).to eql 'Bob'
|
1148
|
+
end
|
1149
|
+
|
1150
|
+
it 'records the `title`' do
|
1151
|
+
expect(trashable.draft.reify.title).to be_nil
|
1152
|
+
end
|
1153
|
+
end
|
1154
|
+
|
1155
|
+
context 'with previous `create` draft' do
|
1156
|
+
before do
|
1157
|
+
trashable.save_draft
|
1158
|
+
trashable.draft_destruction
|
1159
|
+
end
|
1160
|
+
|
1161
|
+
it 'records the `name`' do
|
1162
|
+
expect(trashable.draft.reify.name).to eql 'Bob'
|
1163
|
+
end
|
1164
|
+
|
1165
|
+
it 'records the `title`' do
|
1166
|
+
expect(trashable.draft.reify.title).to be_nil
|
1167
|
+
end
|
1168
|
+
end
|
1169
|
+
|
1170
|
+
context 'with previous `update` draft' do
|
1171
|
+
before do
|
1172
|
+
trashable.save!
|
1173
|
+
trashable.name = 'Sam'
|
1174
|
+
trashable.title = 'My Title'
|
1175
|
+
trashable.save_draft
|
1176
|
+
# Typically, 2 draft operations won't happen in the same request, so
|
1177
|
+
# reload before draft-destroying.
|
1178
|
+
trashable.reload.draft_destruction
|
1179
|
+
end
|
1180
|
+
|
1181
|
+
it 'records the updated `name`' do
|
1182
|
+
expect(trashable.draft.reify.name).to eql 'Sam'
|
1183
|
+
end
|
1184
|
+
|
1185
|
+
it 'records the updated `title`' do
|
1186
|
+
expect(trashable.draft.reify.title).to eql 'My Title'
|
1187
|
+
end
|
1188
|
+
end
|
1189
|
+
end
|
1190
|
+
end # #reify
|
1191
|
+
|
1192
|
+
describe '#draft_publication_dependencies' do
|
1193
|
+
context 'with stashed draft changes' do
|
1194
|
+
context 'with publication dependency' do
|
1195
|
+
let(:parent) { Parent.new(name: 'Marge') }
|
1196
|
+
let(:child) { Child.new(name: 'Lisa', parent: parent) }
|
1197
|
+
|
1198
|
+
before do
|
1199
|
+
parent.save_draft
|
1200
|
+
child.save_draft
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
it 'returns the parent' do
|
1204
|
+
expect(child.draft.draft_publication_dependencies.to_a).to eql [parent.draft]
|
1205
|
+
end
|
1206
|
+
end
|
1207
|
+
|
1208
|
+
context 'without publication dependency' do
|
1209
|
+
let(:parent) { Parent.new(name: 'Marge') }
|
1210
|
+
let(:child) { Child.new(name: 'Lisa', parent: parent) }
|
1211
|
+
|
1212
|
+
before do
|
1213
|
+
parent.save_draft
|
1214
|
+
child.save_draft
|
1215
|
+
end
|
1216
|
+
|
1217
|
+
it 'returns the parent' do
|
1218
|
+
expect(parent.draft.draft_publication_dependencies.to_a).to eql []
|
1219
|
+
end
|
1220
|
+
end
|
1221
|
+
end
|
1222
|
+
|
1223
|
+
context 'without stashed drafted changes' do
|
1224
|
+
before { Draftsman.stash_drafted_changes = false }
|
1225
|
+
after { Draftsman.stash_drafted_changes = true }
|
1226
|
+
|
1227
|
+
context 'with publication dependency' do
|
1228
|
+
let(:parent) { Parent.new(name: 'Marge') }
|
1229
|
+
let(:child) { Child.new(name: 'Lisa', parent: parent) }
|
1230
|
+
|
1231
|
+
before do
|
1232
|
+
parent.save_draft
|
1233
|
+
child.save_draft
|
1234
|
+
end
|
1235
|
+
|
1236
|
+
it 'returns the parent' do
|
1237
|
+
expect(child.draft.draft_publication_dependencies.to_a).to eql [parent.draft]
|
1238
|
+
end
|
1239
|
+
end
|
1240
|
+
|
1241
|
+
context 'without publication dependency' do
|
1242
|
+
let(:parent) { Parent.new(name: 'Marge') }
|
1243
|
+
let(:child) { Child.new(name: 'Lisa', parent: parent) }
|
1244
|
+
|
1245
|
+
before do
|
1246
|
+
parent.save_draft
|
1247
|
+
child.save_draft
|
1248
|
+
end
|
1249
|
+
|
1250
|
+
it 'returns the parent' do
|
1251
|
+
expect(parent.draft.draft_publication_dependencies.to_a).to eql []
|
1252
|
+
end
|
1253
|
+
end
|
1254
|
+
end
|
1255
|
+
end # #draft_publication_dependencies
|
1256
|
+
|
1257
|
+
describe '#draft_reversion_dependencies' do
|
1258
|
+
context 'with stashed draft changes' do
|
1259
|
+
let(:parent) { Parent.new(name: 'Marge') }
|
1260
|
+
let(:child) { Child.new(name: 'Lisa', parent: parent) }
|
1261
|
+
|
1262
|
+
before do
|
1263
|
+
parent.save_draft
|
1264
|
+
child.save_draft
|
1265
|
+
end
|
1266
|
+
|
1267
|
+
context 'with reversion dependency' do
|
1268
|
+
it 'returns the parent' do
|
1269
|
+
expect(parent.draft.draft_reversion_dependencies).to eql [child.draft]
|
1270
|
+
end
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
context 'without reversion dependency' do
|
1274
|
+
it 'returns the parent' do
|
1275
|
+
expect(child.draft.draft_reversion_dependencies).to eql []
|
1276
|
+
end
|
1277
|
+
end
|
1278
|
+
end
|
1279
|
+
|
1280
|
+
context 'without stashed drafted changes' do
|
1281
|
+
let(:parent) { Parent.new(name: 'Marge') }
|
1282
|
+
let(:child) { Child.new(name: 'Lisa', parent: parent) }
|
1283
|
+
|
1284
|
+
before do
|
1285
|
+
Draftsman.stash_drafted_changes = false
|
1286
|
+
parent.save_draft
|
1287
|
+
child.save_draft
|
1288
|
+
end
|
1289
|
+
|
1290
|
+
after { Draftsman.stash_drafted_changes = true }
|
1291
|
+
|
1292
|
+
context 'with publication dependency' do
|
1293
|
+
it 'returns the parent' do
|
1294
|
+
expect(parent.draft.draft_reversion_dependencies).to eql [child.draft]
|
1295
|
+
end
|
1296
|
+
end
|
1297
|
+
|
1298
|
+
context 'without publication dependency' do
|
1299
|
+
it 'returns the parent' do
|
1300
|
+
expect(child.draft.draft_reversion_dependencies).to eql []
|
1301
|
+
end
|
1302
|
+
end
|
1303
|
+
end
|
1304
|
+
end # #draft_reversion_dependencies
|
717
1305
|
end
|