mongoid-versioning 1.2.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -0
- data/.travis.yml +4 -1
- data/README.md +3 -3
- data/lib/mongoid/core_ext/errors/versioning_not_on_root.rb +1 -3
- data/lib/mongoid/core_ext/relations/cascading.rb +4 -5
- data/lib/mongoid/core_ext/relations/metadata.rb +16 -16
- data/lib/mongoid/core_ext/threaded/lifecycle.rb +4 -3
- data/lib/mongoid/core_ext/versioning.rb +19 -20
- data/lib/mongoid/versioning.rb +14 -14
- data/lib/mongoid/versioning/version.rb +1 -1
- data/mongoid-versioning.gemspec +4 -4
- data/spec/app/models/address.rb +9 -8
- data/spec/app/models/paranoid_post.rb +2 -2
- data/spec/app/models/tag.rb +1 -1
- data/spec/app/models/wiki_page.rb +2 -2
- data/spec/mongoid/errors/versioning_not_on_root_spec.rb +8 -10
- data/spec/mongoid/relations/macros_spec.rb +6 -6
- data/spec/mongoid/relations/metadata_spec.rb +8 -12
- data/spec/mongoid/versioning_spec.rb +129 -171
- data/spec/spec_helper.rb +19 -22
- metadata +8 -5
- data/CHANGELOG.md +0 -9
@@ -1,16 +1,16 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mongoid::Relations::Macros do
|
4
|
-
describe
|
5
|
-
context
|
6
|
-
it
|
7
|
-
expect
|
4
|
+
describe '.embedded_in' do
|
5
|
+
context 'when the document is versioned' do
|
6
|
+
it 'raises an error' do
|
7
|
+
expect do
|
8
8
|
Class.new do
|
9
9
|
include Mongoid::Document
|
10
10
|
include Mongoid::Versioning
|
11
11
|
embedded_in :parent_class
|
12
12
|
end
|
13
|
-
|
13
|
+
end.to raise_error(Mongoid::Errors::VersioningNotOnRoot)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -1,10 +1,8 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mongoid::Relations::Metadata do
|
4
|
-
describe
|
5
|
-
|
6
|
-
context "when versioned is true" do
|
7
|
-
|
4
|
+
describe '#versioned?' do
|
5
|
+
context 'when versioned is true' do
|
8
6
|
let(:metadata) do
|
9
7
|
described_class.new(
|
10
8
|
name: :versions,
|
@@ -13,13 +11,12 @@ describe Mongoid::Relations::Metadata do
|
|
13
11
|
)
|
14
12
|
end
|
15
13
|
|
16
|
-
it
|
14
|
+
it 'returns true' do
|
17
15
|
expect(metadata).to be_versioned
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
21
|
-
context
|
22
|
-
|
19
|
+
context 'when versioned is false' do
|
23
20
|
let(:metadata) do
|
24
21
|
described_class.new(
|
25
22
|
name: :versions,
|
@@ -28,13 +25,12 @@ describe Mongoid::Relations::Metadata do
|
|
28
25
|
)
|
29
26
|
end
|
30
27
|
|
31
|
-
it
|
28
|
+
it 'returns false' do
|
32
29
|
expect(metadata).not_to be_versioned
|
33
30
|
end
|
34
31
|
end
|
35
32
|
|
36
|
-
context
|
37
|
-
|
33
|
+
context 'when versioned is nil' do
|
38
34
|
let(:metadata) do
|
39
35
|
described_class.new(
|
40
36
|
name: :versions,
|
@@ -42,7 +38,7 @@ describe Mongoid::Relations::Metadata do
|
|
42
38
|
)
|
43
39
|
end
|
44
40
|
|
45
|
-
it
|
41
|
+
it 'returns false' do
|
46
42
|
expect(metadata).not_to be_versioned
|
47
43
|
end
|
48
44
|
end
|
@@ -1,11 +1,8 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative '../spec_helper'
|
2
2
|
|
3
3
|
describe Mongoid::Versioning do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
context "when provided an integer" do
|
8
|
-
|
4
|
+
describe '.max_versions' do
|
5
|
+
context 'when provided an integer' do
|
9
6
|
before do
|
10
7
|
WikiPage.max_versions(10)
|
11
8
|
end
|
@@ -14,105 +11,95 @@ describe Mongoid::Versioning do
|
|
14
11
|
WikiPage.max_versions(5)
|
15
12
|
end
|
16
13
|
|
17
|
-
it
|
14
|
+
it 'sets the class version max' do
|
18
15
|
expect(WikiPage.version_max).to eq(10)
|
19
16
|
end
|
20
17
|
end
|
21
18
|
|
22
|
-
context
|
23
|
-
|
19
|
+
context 'when provided a string' do
|
24
20
|
before do
|
25
|
-
WikiPage.max_versions(
|
21
|
+
WikiPage.max_versions('10')
|
26
22
|
end
|
27
23
|
|
28
24
|
after do
|
29
25
|
WikiPage.max_versions(5)
|
30
26
|
end
|
31
27
|
|
32
|
-
it
|
28
|
+
it 'sets the class version max' do
|
33
29
|
expect(WikiPage.version_max).to eq(10)
|
34
30
|
end
|
35
31
|
end
|
36
32
|
end
|
37
33
|
|
38
|
-
describe
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
context "when the document is new" do
|
43
|
-
|
44
|
-
it "returns 1" do
|
34
|
+
describe '#version' do
|
35
|
+
context 'when there is no default scope' do
|
36
|
+
context 'when the document is new' do
|
37
|
+
it 'returns 1' do
|
45
38
|
expect(WikiPage.new.version).to eq(1)
|
46
39
|
end
|
47
40
|
end
|
48
41
|
|
49
|
-
context
|
50
|
-
|
42
|
+
context 'when the document is persisted once' do
|
51
43
|
let(:page) do
|
52
|
-
WikiPage.create(title:
|
44
|
+
WikiPage.create(title: '1')
|
53
45
|
end
|
54
46
|
|
55
|
-
it
|
47
|
+
it 'returns 1' do
|
56
48
|
expect(page.version).to eq(1)
|
57
49
|
end
|
58
50
|
end
|
59
51
|
|
60
|
-
context
|
61
|
-
|
52
|
+
context 'when the document is persisted more than once' do
|
62
53
|
let(:page) do
|
63
|
-
WikiPage.create(title:
|
54
|
+
WikiPage.create(title: '1')
|
64
55
|
end
|
65
56
|
|
66
57
|
before do
|
67
|
-
3.times { |n| page.update_attribute(:title,
|
58
|
+
3.times { |n| page.update_attribute(:title, n.to_s) }
|
68
59
|
end
|
69
60
|
|
70
|
-
it
|
61
|
+
it 'returns the number of versions' do
|
71
62
|
expect(page.version).to eq(4)
|
72
63
|
end
|
73
64
|
end
|
74
65
|
|
75
|
-
context
|
76
|
-
|
66
|
+
context 'when maximum versions is defined' do
|
77
67
|
let(:page) do
|
78
|
-
WikiPage.create(title:
|
68
|
+
WikiPage.create(title: '1')
|
79
69
|
end
|
80
70
|
|
81
|
-
context
|
82
|
-
|
71
|
+
context 'when saving over the max versions limit' do
|
83
72
|
before do
|
84
|
-
10.times { |n| page.update_attribute(:title,
|
73
|
+
10.times { |n| page.update_attribute(:title, n.to_s) }
|
85
74
|
end
|
86
75
|
|
87
|
-
it
|
76
|
+
it 'returns the number of versions' do
|
88
77
|
expect(page.version).to eq(11)
|
89
78
|
end
|
90
79
|
end
|
91
80
|
end
|
92
81
|
|
93
|
-
context
|
94
|
-
|
82
|
+
context 'when performing versionless saves' do
|
95
83
|
let(:page) do
|
96
|
-
WikiPage.create(title:
|
84
|
+
WikiPage.create(title: '1')
|
97
85
|
end
|
98
86
|
|
99
87
|
before do
|
100
88
|
10.times do |n|
|
101
|
-
page.versionless { |doc| doc.update_attribute(:title,
|
89
|
+
page.versionless { |doc| doc.update_attribute(:title, n.to_s) }
|
102
90
|
end
|
103
91
|
end
|
104
92
|
|
105
|
-
it
|
93
|
+
it 'does not increment the version number' do
|
106
94
|
expect(page.version).to eq(1)
|
107
95
|
end
|
108
96
|
end
|
109
97
|
end
|
110
98
|
|
111
|
-
context
|
112
|
-
|
99
|
+
context 'when there is a default scope' do
|
113
100
|
before :all do
|
114
101
|
class WikiPage
|
115
|
-
default_scope -> { where(author:
|
102
|
+
default_scope -> { where(author: 'Jim') }
|
116
103
|
end
|
117
104
|
end
|
118
105
|
|
@@ -120,116 +107,107 @@ describe Mongoid::Versioning do
|
|
120
107
|
WikiPage.default_scoping = nil
|
121
108
|
end
|
122
109
|
|
123
|
-
context
|
124
|
-
|
125
|
-
it "returns 1" do
|
110
|
+
context 'when the document is new' do
|
111
|
+
it 'returns 1' do
|
126
112
|
expect(WikiPage.new.version).to eq(1)
|
127
113
|
end
|
128
114
|
end
|
129
115
|
|
130
|
-
context
|
131
|
-
|
116
|
+
context 'when the document is persisted once' do
|
132
117
|
let(:page) do
|
133
|
-
WikiPage.create(title:
|
118
|
+
WikiPage.create(title: '1')
|
134
119
|
end
|
135
120
|
|
136
|
-
it
|
121
|
+
it 'returns 1' do
|
137
122
|
expect(page.version).to eq(1)
|
138
123
|
end
|
139
124
|
end
|
140
125
|
|
141
|
-
context
|
142
|
-
|
126
|
+
context 'when the document is persisted more than once' do
|
143
127
|
let(:page) do
|
144
|
-
WikiPage.create(title:
|
128
|
+
WikiPage.create(title: '1')
|
145
129
|
end
|
146
130
|
|
147
131
|
before do
|
148
|
-
3.times { |n| page.update_attribute(:title,
|
132
|
+
3.times { |n| page.update_attribute(:title, n.to_s) }
|
149
133
|
end
|
150
134
|
|
151
|
-
it
|
135
|
+
it 'returns the number of versions' do
|
152
136
|
expect(page.version).to eq(4)
|
153
137
|
end
|
154
138
|
end
|
155
139
|
|
156
|
-
context
|
157
|
-
|
140
|
+
context 'when maximum versions is defined' do
|
158
141
|
let(:page) do
|
159
|
-
WikiPage.create(title:
|
142
|
+
WikiPage.create(title: '1')
|
160
143
|
end
|
161
144
|
|
162
|
-
context
|
163
|
-
|
145
|
+
context 'when saving over the max versions limit' do
|
164
146
|
before do
|
165
|
-
10.times { |n| page.update_attribute(:title,
|
147
|
+
10.times { |n| page.update_attribute(:title, n.to_s) }
|
166
148
|
end
|
167
149
|
|
168
|
-
it
|
150
|
+
it 'returns the number of versions' do
|
169
151
|
expect(page.version).to eq(11)
|
170
152
|
end
|
171
153
|
end
|
172
154
|
end
|
173
155
|
|
174
|
-
context
|
175
|
-
|
156
|
+
context 'when performing versionless saves' do
|
176
157
|
let(:page) do
|
177
|
-
WikiPage.create(title:
|
158
|
+
WikiPage.create(title: '1')
|
178
159
|
end
|
179
160
|
|
180
161
|
before do
|
181
162
|
10.times do |n|
|
182
|
-
page.versionless { |doc| doc.update_attribute(:title,
|
163
|
+
page.versionless { |doc| doc.update_attribute(:title, n.to_s) }
|
183
164
|
end
|
184
165
|
end
|
185
166
|
|
186
|
-
it
|
167
|
+
it 'does not increment the version number' do
|
187
168
|
expect(page.version).to eq(1)
|
188
169
|
end
|
189
170
|
end
|
190
171
|
end
|
191
172
|
|
192
|
-
context
|
193
|
-
|
194
|
-
let(:title) { "my new wiki" }
|
173
|
+
context 'when not using the default database' do
|
174
|
+
let(:title) { 'my new wiki' }
|
195
175
|
|
196
176
|
let!(:page) do
|
197
|
-
WikiPage.with(database: database_id_alt).create!(description:
|
177
|
+
WikiPage.with(database: database_id_alt).create!(description: '1', title: title)
|
198
178
|
end
|
199
179
|
|
200
|
-
context
|
201
|
-
|
202
|
-
it "returns 1" do
|
180
|
+
context 'when the document is persisted once' do
|
181
|
+
it 'returns 1' do
|
203
182
|
expect(page.version).to eq(1)
|
204
183
|
end
|
205
184
|
|
206
|
-
it
|
207
|
-
expect
|
185
|
+
it 'does not persist to default database' do
|
186
|
+
expect do
|
208
187
|
WikiPage.find_by(title: title)
|
209
|
-
|
188
|
+
end.to raise_error(Mongoid::Errors::DocumentNotFound)
|
210
189
|
end
|
211
190
|
|
212
|
-
it
|
191
|
+
it 'persists to specified database' do
|
213
192
|
expect(WikiPage.with(database: database_id_alt).find_by(title: title)).not_to be_nil
|
214
193
|
end
|
215
194
|
end
|
216
195
|
|
217
|
-
context
|
218
|
-
|
196
|
+
context 'when the document is persisted more than once' do
|
219
197
|
before do
|
220
|
-
3.times { |n| page.with(database: database_id_alt).update_attribute(:description,
|
198
|
+
3.times { |n| page.with(database: database_id_alt).update_attribute(:description, n.to_s) }
|
221
199
|
end
|
222
200
|
|
223
|
-
it
|
201
|
+
it 'returns the number of versions' do
|
224
202
|
expect(page.version).to eq(4)
|
225
203
|
end
|
226
204
|
|
227
|
-
it
|
228
|
-
expect(WikiPage.with(database: database_id_alt).find_by(:
|
205
|
+
it 'persists to specified database' do
|
206
|
+
expect(WikiPage.with(database: database_id_alt).find_by(title: title)).not_to be_nil
|
229
207
|
end
|
230
208
|
|
231
|
-
it
|
232
|
-
expect(WikiPage.with(database: database_id_alt).find_by(:
|
209
|
+
it 'persists the versions to specified database' do
|
210
|
+
expect(WikiPage.with(database: database_id_alt).find_by(title: title).version).to eq(4)
|
233
211
|
end
|
234
212
|
end
|
235
213
|
|
@@ -239,107 +217,98 @@ describe Mongoid::Versioning do
|
|
239
217
|
end
|
240
218
|
end
|
241
219
|
|
242
|
-
describe
|
243
|
-
|
220
|
+
describe '#versionless' do
|
244
221
|
let(:page) do
|
245
222
|
WikiPage.new(created_at: Time.now.utc)
|
246
223
|
end
|
247
224
|
|
248
|
-
context
|
249
|
-
|
250
|
-
it "sets versionless to true" do
|
225
|
+
context 'when executing the block' do
|
226
|
+
it 'sets versionless to true' do
|
251
227
|
page.versionless do |doc|
|
252
228
|
expect(doc.send(:versionless?)).to be_truthy
|
253
229
|
end
|
254
230
|
end
|
255
231
|
end
|
256
232
|
|
257
|
-
context
|
258
|
-
|
259
|
-
it "sets versionless to false" do
|
233
|
+
context 'when the block finishes' do
|
234
|
+
it 'sets versionless to false' do
|
260
235
|
page.versionless
|
261
236
|
expect(page.send(:versionless?)).to be_falsy
|
262
237
|
end
|
263
238
|
end
|
264
239
|
end
|
265
240
|
|
266
|
-
describe
|
267
|
-
|
241
|
+
describe '#versions' do
|
268
242
|
let(:page) do
|
269
|
-
WikiPage.create(title:
|
270
|
-
wiki.author =
|
243
|
+
WikiPage.create(title: '1', description: 'test') do |wiki|
|
244
|
+
wiki.author = 'woodchuck'
|
271
245
|
end
|
272
246
|
end
|
273
247
|
|
274
|
-
context
|
275
|
-
|
276
|
-
context "when the document has changed" do
|
277
|
-
|
248
|
+
context 'when saving the document ' do
|
249
|
+
context 'when the document has changed' do
|
278
250
|
before do
|
279
|
-
page.update_attribute(:title,
|
251
|
+
page.update_attribute(:title, '2')
|
280
252
|
end
|
281
253
|
|
282
254
|
let(:version) do
|
283
255
|
page.versions.first
|
284
256
|
end
|
285
257
|
|
286
|
-
it
|
287
|
-
expect(version.title).to eq(
|
258
|
+
it 'creates a new version' do
|
259
|
+
expect(version.title).to eq('1')
|
288
260
|
end
|
289
261
|
|
290
|
-
it
|
291
|
-
expect(version.description).to eq(
|
262
|
+
it 'properly versions the localized fields' do
|
263
|
+
expect(version.description).to eq('test')
|
292
264
|
end
|
293
265
|
|
294
|
-
it
|
266
|
+
it 'only creates 1 new version' do
|
295
267
|
expect(page.versions.count).to eq(1)
|
296
268
|
end
|
297
269
|
|
298
|
-
it
|
270
|
+
it 'does not version the _id' do
|
299
271
|
expect(version._id).to be_nil
|
300
272
|
end
|
301
273
|
|
302
|
-
it
|
274
|
+
it 'does version the updated_at timestamp' do
|
303
275
|
expect(version.updated_at).not_to be_nil
|
304
276
|
end
|
305
277
|
|
306
|
-
context
|
307
|
-
|
278
|
+
context 'when only updated_at was changed' do
|
308
279
|
before do
|
309
280
|
page.update_attributes(updated_at: Time.now)
|
310
281
|
end
|
311
282
|
|
312
|
-
it
|
283
|
+
it 'does not generate another version' do
|
313
284
|
expect(page.versions.count).to eq(1)
|
314
285
|
end
|
315
286
|
end
|
316
287
|
|
317
|
-
it
|
288
|
+
it 'does not embed versions within versions' do
|
318
289
|
expect(version.versions).to be_empty
|
319
290
|
end
|
320
291
|
|
321
|
-
it
|
322
|
-
expect(version.author).to eq(
|
292
|
+
it 'versions protected fields' do
|
293
|
+
expect(version.author).to eq('woodchuck')
|
323
294
|
end
|
324
295
|
|
325
|
-
context
|
326
|
-
|
296
|
+
context 'when saving multiple times' do
|
327
297
|
before do
|
328
|
-
page.update_attribute(:title,
|
298
|
+
page.update_attribute(:title, '3')
|
329
299
|
end
|
330
300
|
|
331
|
-
it
|
301
|
+
it 'does not embed versions within versions' do
|
332
302
|
expect(version.versions).to be_empty
|
333
303
|
end
|
334
304
|
|
335
|
-
it
|
305
|
+
it 'does not embed versions multiple levels deep' do
|
336
306
|
expect(page.versions.last.versions).to be_empty
|
337
307
|
end
|
338
308
|
end
|
339
309
|
end
|
340
310
|
|
341
|
-
context
|
342
|
-
|
311
|
+
context 'when the document has not changed' do
|
343
312
|
before do
|
344
313
|
page.save
|
345
314
|
end
|
@@ -348,65 +317,58 @@ describe Mongoid::Versioning do
|
|
348
317
|
page.versions.first
|
349
318
|
end
|
350
319
|
|
351
|
-
it
|
320
|
+
it 'does not create a new version' do
|
352
321
|
expect(version).to be_nil
|
353
322
|
end
|
354
323
|
end
|
355
324
|
|
356
|
-
context
|
357
|
-
|
358
|
-
context "when the document is paranoid" do
|
359
|
-
|
325
|
+
context 'when saving over the number of maximum versions' do
|
326
|
+
context 'when the document is paranoid' do
|
360
327
|
let!(:post) do
|
361
|
-
ParanoidPost.create(title:
|
328
|
+
ParanoidPost.create(title: 'test')
|
362
329
|
end
|
363
330
|
|
364
331
|
before do
|
365
332
|
3.times do |n|
|
366
|
-
post.update_attribute(:title,
|
333
|
+
post.update_attribute(:title, n.to_s)
|
367
334
|
end
|
368
335
|
end
|
369
336
|
|
370
|
-
it
|
337
|
+
it 'only versions the maximum amount' do
|
371
338
|
expect(post.versions.target.size).to eq(2)
|
372
339
|
end
|
373
340
|
|
374
|
-
it
|
341
|
+
it 'persists the changes' do
|
375
342
|
expect(post.reload.versions.target.size).to eq(2)
|
376
343
|
end
|
377
344
|
end
|
378
345
|
|
379
|
-
context
|
380
|
-
|
346
|
+
context 'when saving in succession' do
|
381
347
|
before do
|
382
348
|
10.times do |n|
|
383
|
-
page.update_attribute(:title,
|
349
|
+
page.update_attribute(:title, n.to_s)
|
384
350
|
end
|
385
351
|
end
|
386
352
|
|
387
|
-
|
388
|
-
page.versions
|
389
|
-
end
|
390
|
-
|
391
|
-
it "only versions the maximum amount" do
|
392
|
-
expect(versions.count).to eq(5)
|
353
|
+
it 'only versions the maximum amount' do
|
354
|
+
expect(page.reload.versions.count).to eq(5)
|
393
355
|
end
|
394
356
|
|
395
|
-
it
|
396
|
-
expect(versions.last.title).to eq(
|
357
|
+
it 'shifts the versions in order' do
|
358
|
+
expect(page.reload.versions.last.title).to eq('8')
|
397
359
|
end
|
398
360
|
|
399
|
-
it
|
400
|
-
expect(page.reload.versions.last.title).to eq(
|
361
|
+
it 'persists the version shifts' do
|
362
|
+
expect(page.reload.versions.last.title).to eq('8')
|
363
|
+
expect(page.reload.versions.first.title).to eq('4')
|
401
364
|
end
|
402
365
|
end
|
403
366
|
|
404
|
-
context
|
405
|
-
|
367
|
+
context 'when saving in batches' do
|
406
368
|
before do
|
407
369
|
2.times do
|
408
370
|
5.times do |n|
|
409
|
-
WikiPage.find(page.id).update_attributes(title:
|
371
|
+
WikiPage.find(page.id).update_attributes(title: n.to_s)
|
410
372
|
end
|
411
373
|
end
|
412
374
|
end
|
@@ -419,40 +381,37 @@ describe Mongoid::Versioning do
|
|
419
381
|
from_db.versions
|
420
382
|
end
|
421
383
|
|
422
|
-
it
|
384
|
+
it 'only versions the maximum amount' do
|
423
385
|
expect(versions.count).to eq(5)
|
424
386
|
end
|
425
387
|
end
|
426
388
|
end
|
427
389
|
|
428
|
-
context
|
429
|
-
|
390
|
+
context 'when persisting versionless' do
|
430
391
|
before do
|
431
|
-
page.versionless { |doc| doc.update_attribute(:title,
|
392
|
+
page.versionless { |doc| doc.update_attribute(:title, '2') }
|
432
393
|
end
|
433
394
|
|
434
|
-
it
|
395
|
+
it 'does not version the document' do
|
435
396
|
expect(page.versions.count).to eq(0)
|
436
397
|
end
|
437
398
|
end
|
438
399
|
|
439
|
-
context
|
440
|
-
|
400
|
+
context 'when deleting versions' do
|
441
401
|
let(:comment) do
|
442
402
|
Comment.new(title: "Don't delete me!")
|
443
403
|
end
|
444
404
|
|
445
405
|
let!(:orphaned) do
|
446
|
-
Comment.create(title:
|
406
|
+
Comment.create(title: 'Annie')
|
447
407
|
end
|
448
408
|
|
449
409
|
before do
|
450
410
|
page.comments << comment
|
451
|
-
page.update_attribute(:title,
|
411
|
+
page.update_attribute(:title, '5')
|
452
412
|
end
|
453
413
|
|
454
|
-
context
|
455
|
-
|
414
|
+
context 'when the version had a dependent relation' do
|
456
415
|
before do
|
457
416
|
page.versions.delete_all
|
458
417
|
end
|
@@ -461,34 +420,33 @@ describe Mongoid::Versioning do
|
|
461
420
|
Comment.find(comment.id)
|
462
421
|
end
|
463
422
|
|
464
|
-
it
|
423
|
+
it 'does not perform dependent cascading' do
|
465
424
|
expect(from_db).to eq(comment)
|
466
425
|
end
|
467
426
|
|
468
|
-
it
|
427
|
+
it 'does not delete related orphans' do
|
469
428
|
expect(Comment.find(orphaned.id)).to eq(orphaned)
|
470
429
|
end
|
471
430
|
|
472
|
-
it
|
431
|
+
it 'deletes the version' do
|
473
432
|
expect(page.versions).to be_empty
|
474
433
|
end
|
475
434
|
|
476
|
-
it
|
435
|
+
it 'persists the deletion' do
|
477
436
|
expect(page.reload.versions).to be_empty
|
478
437
|
end
|
479
438
|
|
480
|
-
it
|
481
|
-
expect(page.reload.comments).to eq([
|
439
|
+
it 'retains the root relation' do
|
440
|
+
expect(page.reload.comments).to eq([comment])
|
482
441
|
end
|
483
442
|
end
|
484
443
|
end
|
485
444
|
end
|
486
445
|
end
|
487
446
|
|
488
|
-
context
|
489
|
-
|
447
|
+
context 'when appending a self referencing document with versions' do
|
490
448
|
let(:page) do
|
491
|
-
WikiPage.create(title:
|
449
|
+
WikiPage.create(title: '1')
|
492
450
|
end
|
493
451
|
|
494
452
|
let(:child) do
|
@@ -499,12 +457,12 @@ describe Mongoid::Versioning do
|
|
499
457
|
page.child_pages << child
|
500
458
|
end
|
501
459
|
|
502
|
-
it
|
503
|
-
expect(page.child_pages).to eq([
|
460
|
+
it 'allows the document to be added' do
|
461
|
+
expect(page.child_pages).to eq([child])
|
504
462
|
end
|
505
463
|
|
506
|
-
it
|
507
|
-
expect(page.reload.child_pages).to eq([
|
464
|
+
it 'persists the changes' do
|
465
|
+
expect(page.reload.child_pages).to eq([child])
|
508
466
|
end
|
509
467
|
end
|
510
468
|
end
|