mongoid_relations_dirty_tracking 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/{LICENSE.txt → LICENSE} +22 -22
- data/README.md +80 -51
- data/lib/mongoid/relations_dirty_tracking.rb +124 -108
- data/lib/mongoid/relations_dirty_tracking/version.rb +7 -5
- data/lib/mongoid_relations_dirty_tracking.rb +3 -2
- data/spec/gemfiles/Gemfile.master +3 -0
- data/spec/gemfiles/Gemfile.rails51 +6 -0
- data/spec/gemfiles/Gemfile.rails52 +6 -0
- data/spec/gemfiles/Gemfile.rails60 +6 -0
- data/spec/lib/mongoid/relations_dirty_tracking_spec.rb +398 -382
- data/spec/spec_helper.rb +70 -65
- metadata +63 -39
- data/.gitignore +0 -17
- data/Gemfile +0 -4
- data/Rakefile +0 -6
- data/lib/mongoid/relations_dirty_tracking/versioning.rb +0 -54
- data/mongoid_relations_dirty_tracking.gemspec +0 -26
@@ -1,382 +1,398 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
its(:
|
9
|
-
its(:
|
10
|
-
its(:
|
11
|
-
|
12
|
-
|
13
|
-
context
|
14
|
-
context
|
15
|
-
before :each do
|
16
|
-
@embedded_doc = TestEmbeddedDocument.new
|
17
|
-
subject.one_document = @embedded_doc
|
18
|
-
end
|
19
|
-
|
20
|
-
its(:changed?) {
|
21
|
-
its(:children_changed?) {
|
22
|
-
its(:relations_changed?) {
|
23
|
-
its(:changed_with_relations?) {
|
24
|
-
its(:changes_with_relations) {
|
25
|
-
|
26
|
-
describe
|
27
|
-
it
|
28
|
-
expect(subject.relation_changes['one_document']).to eq([nil, @embedded_doc.attributes])
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
subject.
|
38
|
-
subject.
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
its(:
|
43
|
-
its(:
|
44
|
-
its(:
|
45
|
-
its(:
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
subject.one_document =
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
its(:
|
65
|
-
its(:
|
66
|
-
its(:
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
its(:
|
97
|
-
its(:
|
98
|
-
its(:
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
@embedded_doc
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
its(:
|
119
|
-
its(:
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
its(:
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
its(:
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
its(:
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
its(:
|
204
|
-
its(:
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
its(:
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
its(:
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
context
|
345
|
-
it
|
346
|
-
expect(
|
347
|
-
expect(
|
348
|
-
end
|
349
|
-
end
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
klass
|
370
|
-
expect(klass.relations_dirty_tracking_options[:except]).to include('
|
371
|
-
end
|
372
|
-
end
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Mongoid::RelationsDirtyTracking do
|
6
|
+
subject { TestDocument.create }
|
7
|
+
|
8
|
+
its(:changed?) { is_expected.to eq false }
|
9
|
+
its(:children_changed?) { is_expected.to eq false }
|
10
|
+
its(:relations_changed?) { is_expected.to eq false }
|
11
|
+
its(:changed_with_relations?) { is_expected.to eq false }
|
12
|
+
|
13
|
+
context 'embeds_one relationship' do
|
14
|
+
context 'when adding document' do
|
15
|
+
before :each do
|
16
|
+
@embedded_doc = TestEmbeddedDocument.new
|
17
|
+
subject.one_document = @embedded_doc
|
18
|
+
end
|
19
|
+
|
20
|
+
its(:changed?) { is_expected.to eq false }
|
21
|
+
its(:children_changed?) { is_expected.to eq false }
|
22
|
+
its(:relations_changed?) { is_expected.to eq true }
|
23
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
24
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
25
|
+
|
26
|
+
describe '#relation_changes' do
|
27
|
+
it 'returns array with differences' do
|
28
|
+
expect(subject.relation_changes['one_document']).to eq([nil, @embedded_doc.attributes])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'when removing document' do
|
34
|
+
before :each do
|
35
|
+
@embedded_doc = TestEmbeddedDocument.new
|
36
|
+
subject.one_document = @embedded_doc
|
37
|
+
subject.save!
|
38
|
+
subject.one_document = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
its(:changed?) { is_expected.to eq false }
|
42
|
+
its(:children_changed?) { is_expected.to eq false }
|
43
|
+
its(:relations_changed?) { is_expected.to eq true }
|
44
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
45
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
46
|
+
|
47
|
+
describe '#relation_changes' do
|
48
|
+
it 'returns array with differences' do
|
49
|
+
expect(subject.relation_changes['one_document']).to eq([@embedded_doc.attributes, nil])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'when changing value on embedded document' do
|
55
|
+
before :each do
|
56
|
+
@embedded_doc = TestEmbeddedDocument.new
|
57
|
+
subject.one_document = @embedded_doc
|
58
|
+
subject.save!
|
59
|
+
subject.one_document.title = 'foobar'
|
60
|
+
end
|
61
|
+
|
62
|
+
its(:changed?) { is_expected.to eq true }
|
63
|
+
its(:children_changed?) { is_expected.to eq true }
|
64
|
+
its(:relations_changed?) { is_expected.to eq true }
|
65
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
66
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
67
|
+
|
68
|
+
describe '#relation_changes' do
|
69
|
+
it 'returns array with differences' do
|
70
|
+
old_attributes = @embedded_doc.attributes.clone.delete_if { |key, _val| key == 'title' }
|
71
|
+
expect(subject.relation_changes['one_document']).to eq([old_attributes, @embedded_doc.attributes])
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when just updated_at is changed on embedded document' do
|
77
|
+
before :each do
|
78
|
+
embedded_doc = Class.new(TestEmbeddedDocument) { include Mongoid::Timestamps }.new
|
79
|
+
subject.one_document = @embedded_doc
|
80
|
+
subject.save!
|
81
|
+
embedded_doc.updated_at = Time.now
|
82
|
+
end
|
83
|
+
its(:changed?) { is_expected.to eq false }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'embeds_many relationship' do
|
88
|
+
context 'when adding document' do
|
89
|
+
before :each do
|
90
|
+
@embedded_doc = TestEmbeddedDocument.new
|
91
|
+
subject.many_documents << @embedded_doc
|
92
|
+
end
|
93
|
+
|
94
|
+
its(:changed?) { is_expected.to eq false }
|
95
|
+
its(:children_changed?) { is_expected.to eq false }
|
96
|
+
its(:relations_changed?) { is_expected.to eq true }
|
97
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
98
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
99
|
+
|
100
|
+
describe '#relation_changes' do
|
101
|
+
it 'returns array with differences' do
|
102
|
+
expect(subject.relation_changes['many_documents']).to eq([[], [@embedded_doc.attributes]])
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context 'when removing document' do
|
108
|
+
before :each do
|
109
|
+
@embedded_doc = TestEmbeddedDocument.new
|
110
|
+
subject.many_documents = [@embedded_doc]
|
111
|
+
subject.save!
|
112
|
+
subject.many_documents.delete @embedded_doc
|
113
|
+
end
|
114
|
+
|
115
|
+
its(:changed?) { is_expected.to eq false }
|
116
|
+
its(:children_changed?) { is_expected.to eq false }
|
117
|
+
its(:relations_changed?) { is_expected.to eq true }
|
118
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
119
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
120
|
+
|
121
|
+
describe '#relation_changes' do
|
122
|
+
it 'returns array with differences' do
|
123
|
+
expect(subject.relation_changes['many_documents']).to eq([[@embedded_doc.attributes], []])
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'has_one relationship' do
|
130
|
+
context 'when adding document' do
|
131
|
+
before :each do
|
132
|
+
@related_doc = TestRelatedDocument.new
|
133
|
+
subject.one_related = @related_doc
|
134
|
+
end
|
135
|
+
|
136
|
+
its(:changed?) { is_expected.to eq false }
|
137
|
+
its(:children_changed?) { is_expected.to eq false }
|
138
|
+
its(:relations_changed?) { is_expected.to eq true }
|
139
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
140
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
141
|
+
|
142
|
+
describe '#relation_changes' do
|
143
|
+
it 'returns array with differences' do
|
144
|
+
expect(subject.relation_changes['one_related']).to eq([nil, { '_id' => @related_doc._id }])
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
context 'when removing document' do
|
150
|
+
before :each do
|
151
|
+
@related_doc = TestRelatedDocument.new
|
152
|
+
subject.one_related = @related_doc
|
153
|
+
subject.save!
|
154
|
+
subject.one_related = nil
|
155
|
+
end
|
156
|
+
|
157
|
+
its(:changed?) { is_expected.to eq false }
|
158
|
+
its(:children_changed?) { is_expected.to eq false }
|
159
|
+
its(:relations_changed?) { is_expected.to eq true }
|
160
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
161
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
162
|
+
|
163
|
+
describe '#relation_changes' do
|
164
|
+
it 'returns array with differences' do
|
165
|
+
expect(subject.relation_changes['one_related']).to eq([{ '_id' => @related_doc._id }, nil])
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context 'when changing document' do
|
171
|
+
before :each do
|
172
|
+
@related_doc = TestRelatedDocument.new
|
173
|
+
subject.one_related = @related_doc
|
174
|
+
subject.save!
|
175
|
+
subject.one_related = @another_related_doc = TestRelatedDocument.new
|
176
|
+
end
|
177
|
+
|
178
|
+
its(:changed?) { is_expected.to eq false }
|
179
|
+
its(:children_changed?) { is_expected.to eq false }
|
180
|
+
its(:relations_changed?) { is_expected.to eq true }
|
181
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
182
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
183
|
+
|
184
|
+
describe '#relation_changes' do
|
185
|
+
it 'returns array with differences' do
|
186
|
+
expect(subject.relation_changes['one_related']).to eq([{ '_id' => @related_doc._id },
|
187
|
+
{ '_id' => @another_related_doc._id }])
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context 'when changing value on referenced document' do
|
193
|
+
before :each do
|
194
|
+
@related_doc = TestRelatedDocument.new
|
195
|
+
subject.one_related = @related_doc
|
196
|
+
subject.save!
|
197
|
+
subject.one_related.title = 'New title'
|
198
|
+
end
|
199
|
+
|
200
|
+
its(:changed?) { is_expected.to eq false }
|
201
|
+
its(:children_changed?) { is_expected.to eq false }
|
202
|
+
its(:relations_changed?) { is_expected.to eq false }
|
203
|
+
its(:changed_with_relations?) { is_expected.to eq false }
|
204
|
+
its(:relation_changes) { is_expected.to be_empty }
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context 'has_many relationship' do
|
209
|
+
context 'when adding document' do
|
210
|
+
before :each do
|
211
|
+
@related_doc = TestRelatedDocument.new
|
212
|
+
subject.many_related << @related_doc
|
213
|
+
end
|
214
|
+
|
215
|
+
its(:changed?) { is_expected.to eq false }
|
216
|
+
its(:children_changed?) { is_expected.to eq false }
|
217
|
+
its(:relations_changed?) { is_expected.to eq true }
|
218
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
219
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
220
|
+
|
221
|
+
describe '#relation_changes' do
|
222
|
+
it 'returns array with differences' do
|
223
|
+
expect(subject.relation_changes['many_related']).to eq([[], [{ '_id' => @related_doc._id }]])
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context 'when removing document' do
|
229
|
+
before :each do
|
230
|
+
@related_doc = TestRelatedDocument.new
|
231
|
+
subject.many_related << @related_doc
|
232
|
+
subject.save!
|
233
|
+
subject.many_related.delete(@related_doc)
|
234
|
+
end
|
235
|
+
|
236
|
+
its(:changed?) { is_expected.to eq false }
|
237
|
+
its(:children_changed?) { is_expected.to eq false }
|
238
|
+
its(:relations_changed?) { is_expected.to eq true }
|
239
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
240
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
241
|
+
|
242
|
+
describe '#relation_changes' do
|
243
|
+
it 'returns array with differences' do
|
244
|
+
expect(subject.relation_changes['many_related']).to eq([[{ '_id' => @related_doc._id }], []])
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context 'has_and_belongs_to_many relationship' do
|
251
|
+
context 'when adding document' do
|
252
|
+
before :each do
|
253
|
+
@related_doc = TestRelatedDocument.new
|
254
|
+
subject.many_to_many_related << @related_doc
|
255
|
+
end
|
256
|
+
|
257
|
+
its(:changed?) { is_expected.to eq false }
|
258
|
+
its(:children_changed?) { is_expected.to eq false }
|
259
|
+
its(:relations_changed?) { is_expected.to eq true }
|
260
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
261
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
262
|
+
|
263
|
+
describe '#relation_changes' do
|
264
|
+
it 'returns array with differences' do
|
265
|
+
expect(subject.relation_changes['many_to_many_related']).to eq([[], [{ '_id' => @related_doc._id }]])
|
266
|
+
end
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
context 'when removing document' do
|
271
|
+
before :each do
|
272
|
+
@related_doc = TestRelatedDocument.new
|
273
|
+
subject.many_to_many_related << @related_doc
|
274
|
+
subject.save!
|
275
|
+
subject.many_to_many_related.delete(@related_doc)
|
276
|
+
end
|
277
|
+
|
278
|
+
its(:changed?) { is_expected.to eq false }
|
279
|
+
its(:children_changed?) { is_expected.to eq false }
|
280
|
+
its(:relations_changed?) { is_expected.to eq true }
|
281
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
282
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
283
|
+
|
284
|
+
describe '#relation_changes' do
|
285
|
+
it 'returns array with differences' do
|
286
|
+
expect(subject.relation_changes['many_to_many_related']).to eq([[{ '_id' => @related_doc._id }], []])
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
context 'belongs_to relationship' do
|
293
|
+
subject { TestRelatedDocument.create }
|
294
|
+
|
295
|
+
context 'when adding document' do
|
296
|
+
before :each do
|
297
|
+
@doc = TestDocument.create
|
298
|
+
subject.test_document = @doc
|
299
|
+
end
|
300
|
+
|
301
|
+
its(:changed?) { is_expected.to eq true }
|
302
|
+
its(:children_changed?) { is_expected.to eq false }
|
303
|
+
its(:relations_changed?) { is_expected.to eq true }
|
304
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
305
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
306
|
+
|
307
|
+
describe '#relation_changes' do
|
308
|
+
it 'returns array with differences' do
|
309
|
+
expect(subject.relation_changes['test_document']).to eq([nil, { 'test_document_id' => @doc._id }])
|
310
|
+
end
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
context 'when removing document' do
|
315
|
+
before :each do
|
316
|
+
@doc = TestDocument.create
|
317
|
+
subject.test_document = @doc
|
318
|
+
subject.save!
|
319
|
+
subject.test_document = nil
|
320
|
+
end
|
321
|
+
|
322
|
+
its(:changed?) { is_expected.to eq true }
|
323
|
+
its(:children_changed?) { is_expected.to eq false }
|
324
|
+
its(:relations_changed?) { is_expected.to eq true }
|
325
|
+
its(:changed_with_relations?) { is_expected.to eq true }
|
326
|
+
its(:changes_with_relations) { is_expected.to include(subject.relation_changes) }
|
327
|
+
|
328
|
+
describe '#relation_changes' do
|
329
|
+
it 'returns array with differences' do
|
330
|
+
expect(subject.relation_changes['test_document']).to eq([{ 'test_document_id' => @doc._id }, nil])
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
describe '.track_relation?' do
|
337
|
+
context 'with only options' do
|
338
|
+
it 'do tracks only specified relations' do
|
339
|
+
expect(TestDocumentWithOnlyOption.track_relation?(:many_documents)).to eq true
|
340
|
+
expect(TestDocumentWithOnlyOption.track_relation?(:one_related)).to eq false
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
context 'with except options' do
|
345
|
+
it 'do no track excluded relations' do
|
346
|
+
expect(TestDocumentWithExceptOption.track_relation?('many_documents')).to eq false
|
347
|
+
expect(TestDocumentWithExceptOption.track_relation?('one_related')).to eq true
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
describe 'by default the versions relation is not tracked' do
|
353
|
+
context "when not called 'relations_dirty_tracking'" do
|
354
|
+
it "'versions' is excluded from tracing" do
|
355
|
+
expect(Class.new(TestDocument).relations_dirty_tracking_options[:except]).to include('versions')
|
356
|
+
end
|
357
|
+
end
|
358
|
+
|
359
|
+
context "when called 'relations_dirty_tracking' with only" do
|
360
|
+
it "'versions' is excluded from tracing" do
|
361
|
+
klass = Class.new(TestDocument) { relations_dirty_tracking(only: 'foobar') }
|
362
|
+
expect(klass.relations_dirty_tracking_options[:except]).to include('versions')
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
context "when called 'relations_dirty_tracking' with except" do
|
367
|
+
it "'versions' is excluded from tracing" do
|
368
|
+
klass = Class.new(TestDocument) { relations_dirty_tracking(except: 'foobar') }
|
369
|
+
expect(klass.relations_dirty_tracking_options[:except]).to include('versions')
|
370
|
+
expect(klass.relations_dirty_tracking_options[:except]).to include('foobar')
|
371
|
+
end
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
describe 'global disablement' do
|
376
|
+
context 'when adding document' do
|
377
|
+
before :each do
|
378
|
+
@embedded_doc = TestEmbeddedDocument.new
|
379
|
+
|
380
|
+
described_class.disable do
|
381
|
+
subject.many_documents << @embedded_doc
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
its(:changed?) { is_expected.to eq false }
|
386
|
+
its(:children_changed?) { is_expected.to eq false }
|
387
|
+
its(:relations_changed?) { is_expected.to eq false }
|
388
|
+
its(:changed_with_relations?) { is_expected.to eq false }
|
389
|
+
its(:changes_with_relations) { is_expected.to_not include(subject.relation_changes) }
|
390
|
+
|
391
|
+
describe '#relation_changes' do
|
392
|
+
it 'returns array with differences' do
|
393
|
+
expect(subject.relation_changes['many_documents']).to eq(nil)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|