mongoid-history 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +22 -18
- data/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/CONTRIBUTING.md +4 -4
- data/Gemfile +8 -6
- data/README.md +2 -12
- data/UPGRADING.md +20 -1
- data/lib/mongoid/history.rb +8 -4
- data/lib/mongoid/history/attributes/base.rb +2 -2
- data/lib/mongoid/history/attributes/create.rb +2 -2
- data/lib/mongoid/history/attributes/update.rb +2 -2
- data/lib/mongoid/history/options.rb +11 -20
- data/lib/mongoid/history/trackable.rb +71 -56
- data/lib/mongoid/history/tracker.rb +8 -5
- data/lib/mongoid/history/version.rb +1 -1
- data/spec/integration/embedded_in_polymorphic_spec.rb +26 -49
- data/spec/integration/integration_spec.rb +132 -120
- data/spec/integration/multi_relation_spec.rb +14 -20
- data/spec/integration/multiple_trackers_spec.rb +35 -38
- data/spec/integration/nested_embedded_documents_spec.rb +31 -51
- data/spec/integration/nested_embedded_polymorphic_documents_spec.rb +64 -76
- data/spec/integration/subclasses_spec.rb +17 -5
- data/spec/integration/track_history_order_spec.rb +59 -27
- data/spec/integration/validation_failure_spec.rb +21 -8
- data/spec/spec_helper.rb +6 -1
- data/spec/unit/attributes/base_spec.rb +17 -26
- data/spec/unit/attributes/create_spec.rb +152 -125
- data/spec/unit/attributes/destroy_spec.rb +68 -58
- data/spec/unit/attributes/update_spec.rb +71 -50
- data/spec/unit/callback_options_spec.rb +36 -30
- data/spec/unit/embedded_methods_spec.rb +42 -24
- data/spec/unit/history_spec.rb +12 -10
- data/spec/unit/my_instance_methods_spec.rb +191 -121
- data/spec/unit/options_spec.rb +49 -26
- data/spec/unit/singleton_methods_spec.rb +156 -88
- data/spec/unit/trackable_spec.rb +254 -156
- data/spec/unit/tracker_spec.rb +81 -54
- metadata +2 -2
@@ -1,20 +1,25 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Mongoid::History::Attributes::Destroy do
|
4
|
-
|
5
|
-
|
4
|
+
before :each do
|
5
|
+
class ModelOne
|
6
6
|
include Mongoid::Document
|
7
7
|
include Mongoid::History::Trackable
|
8
|
+
|
8
9
|
store_in collection: :model_ones
|
10
|
+
|
9
11
|
field :foo
|
10
12
|
field :b, as: :bar
|
11
|
-
|
12
|
-
|
13
|
-
end
|
13
|
+
|
14
|
+
track_history on: :foo, modifier_field_optional: true
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
+
after :each do
|
19
|
+
Object.send(:remove_const, :ModelOne)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:obj_one) { ModelOne.new }
|
18
23
|
let(:base) { described_class.new(obj_one) }
|
19
24
|
subject { base }
|
20
25
|
|
@@ -22,50 +27,57 @@ describe Mongoid::History::Attributes::Destroy do
|
|
22
27
|
subject { base.attributes }
|
23
28
|
|
24
29
|
describe '#fields' do
|
25
|
-
before
|
26
|
-
model_one.instance_variable_set(:@history_trackable_options, nil)
|
27
|
-
model_one.track_history on: :foo
|
30
|
+
before :each do
|
28
31
|
obj_one.save!
|
29
32
|
end
|
30
|
-
|
33
|
+
|
34
|
+
let(:obj_one) { ModelOne.new(foo: 'Foo', bar: 'Bar') }
|
31
35
|
it { is_expected.to eq('_id' => [obj_one._id, nil], 'foo' => ['Foo', nil], 'version' => [1, nil]) }
|
32
36
|
end
|
33
37
|
|
34
38
|
describe '#insert_embeds_one_changes' do
|
35
|
-
before
|
36
|
-
# Need class name constant. So, defining class like this
|
39
|
+
before :each do
|
37
40
|
class ModelTwo
|
38
41
|
include Mongoid::Document
|
39
42
|
include Mongoid::History::Trackable
|
43
|
+
|
40
44
|
store_in collection: :model_twos
|
45
|
+
|
41
46
|
embeds_one :emb_two
|
42
|
-
|
47
|
+
|
48
|
+
track_history on: :fields, modifier_field_optional: true
|
43
49
|
end
|
44
50
|
|
45
51
|
class EmbTwo
|
46
52
|
include Mongoid::Document
|
53
|
+
|
47
54
|
field :em_foo
|
48
55
|
field :em_bar
|
56
|
+
|
49
57
|
embedded_in :model_two
|
50
58
|
end
|
51
59
|
end
|
52
60
|
|
53
|
-
|
61
|
+
after :each do
|
62
|
+
Object.send(:remove_const, :ModelTwo)
|
63
|
+
Object.send(:remove_const, :EmbTwo)
|
64
|
+
end
|
65
|
+
|
54
66
|
let(:obj_two) { ModelTwo.new(emb_two: emb_obj_two) }
|
55
67
|
let(:emb_obj_two) { EmbTwo.new(em_foo: 'Em-Foo', em_bar: 'Em-Bar') }
|
56
68
|
let(:base) { described_class.new(obj_two) }
|
57
69
|
|
58
70
|
context 'when relation tracked' do
|
59
|
-
before
|
60
|
-
ModelTwo.track_history on: :emb_two
|
71
|
+
before :each do
|
72
|
+
ModelTwo.track_history on: :emb_two, modifier_field_optional: true
|
61
73
|
obj_two.save!
|
62
74
|
end
|
63
75
|
it { expect(subject['emb_two']).to eq [{ '_id' => emb_obj_two._id, 'em_foo' => 'Em-Foo', 'em_bar' => 'Em-Bar' }, nil] }
|
64
76
|
end
|
65
77
|
|
66
78
|
context 'when relation not tracked' do
|
67
|
-
before
|
68
|
-
ModelTwo.track_history on: :fields
|
79
|
+
before :each do
|
80
|
+
ModelTwo.track_history on: :fields, modifier_field_optional: true
|
69
81
|
allow(ModelTwo).to receive(:dynamic_enabled?) { false }
|
70
82
|
obj_two.save!
|
71
83
|
end
|
@@ -73,133 +85,136 @@ describe Mongoid::History::Attributes::Destroy do
|
|
73
85
|
end
|
74
86
|
|
75
87
|
context 'when relation with alias' do
|
76
|
-
before
|
77
|
-
# Need class name constant. So, defining class like this
|
88
|
+
before :each do
|
78
89
|
class ModelThree
|
79
90
|
include Mongoid::Document
|
80
91
|
include Mongoid::History::Trackable
|
92
|
+
|
81
93
|
store_in collection: :model_threes
|
82
94
|
embeds_one :emb_three, store_as: :emtr
|
95
|
+
|
96
|
+
track_history on: :emb_three, modifier_field_optional: true
|
83
97
|
end
|
84
98
|
|
85
99
|
class EmbThree
|
86
100
|
include Mongoid::Document
|
101
|
+
|
87
102
|
field :em_foo
|
88
103
|
embedded_in :model_three
|
89
104
|
end
|
90
105
|
end
|
91
106
|
|
92
|
-
|
93
|
-
|
94
|
-
|
107
|
+
after :each do
|
108
|
+
Object.send(:remove_const, :ModelThree)
|
109
|
+
Object.send(:remove_const, :EmbThree)
|
110
|
+
end
|
111
|
+
|
112
|
+
before :each do
|
95
113
|
obj_three.save!
|
96
114
|
end
|
97
115
|
|
98
116
|
let(:obj_three) { ModelThree.new(emb_three: emb_obj_three) }
|
99
117
|
let(:emb_obj_three) { EmbThree.new(em_foo: 'Em-Foo') }
|
100
118
|
let(:base) { described_class.new(obj_three) }
|
101
|
-
it { expect(subject['emb_three']).to eq [{ '_id' => emb_obj_three._id, 'em_foo' => 'Em-Foo' }, nil] }
|
102
119
|
|
103
|
-
|
104
|
-
Object.send(:remove_const, :ModelThree)
|
105
|
-
Object.send(:remove_const, :EmbThree)
|
106
|
-
end
|
120
|
+
it { expect(subject['emb_three']).to eq [{ '_id' => emb_obj_three._id, 'em_foo' => 'Em-Foo' }, nil] }
|
107
121
|
end
|
108
122
|
|
109
123
|
context 'relation with permitted attributes' do
|
110
|
-
before
|
111
|
-
ModelTwo.track_history on: [{ emb_two: :em_foo }]
|
124
|
+
before :each do
|
125
|
+
ModelTwo.track_history on: [{ emb_two: :em_foo }], modifier_field_optional: true
|
112
126
|
obj_two.save!
|
113
127
|
end
|
128
|
+
|
114
129
|
it { expect(subject['emb_two']).to eq [{ '_id' => emb_obj_two._id, 'em_foo' => 'Em-Foo' }, nil] }
|
115
130
|
end
|
116
131
|
|
117
132
|
context 'when relation object not built' do
|
118
|
-
before
|
119
|
-
ModelTwo.track_history on: :emb_two
|
133
|
+
before :each do
|
134
|
+
ModelTwo.track_history on: :emb_two, modifier_field_optional: true
|
120
135
|
obj_two.save!
|
121
136
|
end
|
137
|
+
|
122
138
|
let(:obj_two) { ModelTwo.new }
|
123
139
|
it { expect(subject['emb_two']).to be_nil }
|
124
140
|
end
|
125
|
-
|
126
|
-
after(:all) do
|
127
|
-
Object.send(:remove_const, :ModelTwo)
|
128
|
-
Object.send(:remove_const, :EmbTwo)
|
129
|
-
end
|
130
141
|
end
|
131
142
|
|
132
143
|
describe '#insert_embeds_many_changes' do
|
133
144
|
context 'Case 1:' do
|
134
|
-
before
|
145
|
+
before :each do
|
135
146
|
class ModelTwo
|
136
147
|
include Mongoid::Document
|
137
148
|
include Mongoid::History::Trackable
|
149
|
+
|
138
150
|
embeds_many :em_twos
|
139
151
|
track_history on: :fields
|
140
152
|
end
|
141
153
|
|
142
154
|
class EmTwo
|
143
155
|
include Mongoid::Document
|
156
|
+
|
144
157
|
field :em_foo
|
145
158
|
field :em_bar
|
159
|
+
|
146
160
|
embedded_in :model_two
|
147
161
|
end
|
148
162
|
end
|
149
163
|
|
164
|
+
after :each do
|
165
|
+
Object.send(:remove_const, :ModelTwo)
|
166
|
+
Object.send(:remove_const, :EmTwo)
|
167
|
+
end
|
168
|
+
|
150
169
|
let(:obj_two) { ModelTwo.new(em_twos: [em_obj_two]) }
|
151
170
|
let(:em_obj_two) { EmTwo.new(em_foo: 'Em-Foo', em_bar: 'Em-Bar') }
|
152
171
|
let(:base) { described_class.new(obj_two) }
|
153
172
|
|
154
173
|
context 'when relation tracked' do
|
155
|
-
before
|
156
|
-
ModelTwo.clear_trackable_memoization
|
174
|
+
before :each do
|
157
175
|
ModelTwo.track_history on: :em_twos
|
158
176
|
end
|
159
177
|
it { expect(subject['em_twos']).to eq [[{ '_id' => em_obj_two._id, 'em_foo' => 'Em-Foo', 'em_bar' => 'Em-Bar' }], nil] }
|
160
178
|
end
|
161
179
|
|
162
180
|
context 'when relation not tracked' do
|
163
|
-
before
|
164
|
-
ModelTwo.clear_trackable_memoization
|
181
|
+
before :each do
|
165
182
|
ModelTwo.track_history on: :fields
|
166
183
|
end
|
167
184
|
it { expect(subject['em_twos']).to be_nil }
|
168
185
|
end
|
169
186
|
|
170
187
|
context 'when relation with permitted attributes for tracking' do
|
171
|
-
before
|
172
|
-
ModelTwo.clear_trackable_memoization
|
188
|
+
before :each do
|
173
189
|
ModelTwo.track_history on: { em_twos: :em_foo }
|
174
190
|
end
|
175
191
|
it { expect(subject['em_twos']).to eq [[{ '_id' => em_obj_two._id, 'em_foo' => 'Em-Foo' }], nil] }
|
176
192
|
end
|
177
|
-
|
178
|
-
after(:all) do
|
179
|
-
Object.send(:remove_const, :ModelTwo)
|
180
|
-
Object.send(:remove_const, :EmTwo)
|
181
|
-
end
|
182
193
|
end
|
183
194
|
|
184
195
|
context 'when relation with alias' do
|
185
|
-
before
|
196
|
+
before :each do
|
186
197
|
class ModelTwo
|
187
198
|
include Mongoid::Document
|
188
199
|
include Mongoid::History::Trackable
|
200
|
+
|
189
201
|
embeds_many :em_twos, store_as: :emws
|
190
202
|
track_history on: :fields
|
203
|
+
|
204
|
+
track_history on: :em_twos
|
191
205
|
end
|
192
206
|
|
193
207
|
class EmTwo
|
194
208
|
include Mongoid::Document
|
209
|
+
|
195
210
|
field :em_foo
|
196
211
|
embedded_in :model_two
|
197
212
|
end
|
198
213
|
end
|
199
214
|
|
200
|
-
|
201
|
-
ModelTwo
|
202
|
-
|
215
|
+
after :each do
|
216
|
+
Object.send(:remove_const, :ModelTwo)
|
217
|
+
Object.send(:remove_const, :EmTwo)
|
203
218
|
end
|
204
219
|
|
205
220
|
let(:obj_two) { ModelTwo.new(em_twos: [em_obj_two]) }
|
@@ -207,11 +222,6 @@ describe Mongoid::History::Attributes::Destroy do
|
|
207
222
|
let(:base) { described_class.new(obj_two) }
|
208
223
|
|
209
224
|
it { expect(subject['em_twos']).to eq [[{ '_id' => em_obj_two._id, 'em_foo' => 'Em-Foo' }], nil] }
|
210
|
-
|
211
|
-
after(:all) do
|
212
|
-
Object.send(:remove_const, :ModelTwo)
|
213
|
-
Object.send(:remove_const, :EmTwo)
|
214
|
-
end
|
215
225
|
end
|
216
226
|
end
|
217
227
|
end
|
@@ -4,25 +4,33 @@ describe Mongoid::History::Attributes::Update do
|
|
4
4
|
describe '#attributes' do
|
5
5
|
describe '#insert_embeds_one_changes' do
|
6
6
|
context 'Case: relation without alias' do
|
7
|
-
before
|
7
|
+
before :each do
|
8
8
|
class ModelOne
|
9
9
|
include Mongoid::Document
|
10
10
|
include Mongoid::History::Trackable
|
11
|
+
|
11
12
|
store_in collection: :model_ones
|
12
13
|
embeds_one :emb_one
|
14
|
+
|
13
15
|
track_history on: :fields
|
14
16
|
end
|
15
17
|
|
16
18
|
class EmbOne
|
17
19
|
include Mongoid::Document
|
20
|
+
|
18
21
|
field :em_foo
|
19
22
|
field :em_bar
|
23
|
+
|
20
24
|
embedded_in :model_one
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
|
-
|
25
|
-
ModelOne
|
28
|
+
after :each do
|
29
|
+
Object.send(:remove_const, :ModelOne)
|
30
|
+
Object.send(:remove_const, :EmbOne)
|
31
|
+
end
|
32
|
+
|
33
|
+
before :each do
|
26
34
|
allow(base).to receive(:changes) { changes }
|
27
35
|
end
|
28
36
|
|
@@ -34,17 +42,23 @@ describe Mongoid::History::Attributes::Update do
|
|
34
42
|
subject { base.attributes }
|
35
43
|
|
36
44
|
context 'with permitted attributes' do
|
37
|
-
before
|
45
|
+
before :each do
|
46
|
+
ModelOne.track_history on: { emb_one: :em_foo }
|
47
|
+
end
|
38
48
|
it { expect(subject['emb_one']).to eq [{ 'em_foo' => 'Em-Foo' }, { 'em_foo' => 'Em-Foo-new' }] }
|
39
49
|
end
|
40
50
|
|
41
51
|
context 'without permitted attributes' do
|
42
|
-
before
|
52
|
+
before :each do
|
53
|
+
ModelOne.track_history on: :emb_one
|
54
|
+
end
|
43
55
|
it { expect(subject['emb_one']).to eq [{ 'em_foo' => 'Em-Foo', 'em_bar' => 'Em-Bar' }, { 'em_foo' => 'Em-Foo-new', 'em_bar' => 'Em-Bar-new' }] }
|
44
56
|
end
|
45
57
|
|
46
58
|
context 'when old value soft-deleted' do
|
47
|
-
before
|
59
|
+
before :each do
|
60
|
+
ModelOne.track_history on: :emb_one
|
61
|
+
end
|
48
62
|
let(:changes) do
|
49
63
|
{ 'emb_one' => [{ 'em_foo' => 'Em-Foo', 'deleted_at' => Time.now }, { 'em_foo' => 'Em-Foo-new', 'em_bar' => 'Em-Bar-new' }] }
|
50
64
|
end
|
@@ -52,7 +66,9 @@ describe Mongoid::History::Attributes::Update do
|
|
52
66
|
end
|
53
67
|
|
54
68
|
context 'when new value soft-deleted' do
|
55
|
-
before
|
69
|
+
before :each do
|
70
|
+
ModelOne.track_history on: :emb_one
|
71
|
+
end
|
56
72
|
let(:changes) do
|
57
73
|
{ 'emb_one' => [{ 'em_foo' => 'Em-Foo' }, { 'em_foo' => 'Em-Foo-new', 'deleted_at' => Time.now }] }
|
58
74
|
end
|
@@ -60,21 +76,16 @@ describe Mongoid::History::Attributes::Update do
|
|
60
76
|
end
|
61
77
|
|
62
78
|
context 'when not tracked' do
|
63
|
-
before
|
79
|
+
before :each do
|
64
80
|
ModelOne.track_history on: :fields
|
65
81
|
allow(ModelOne).to receive(:dynamic_enabled?) { false }
|
66
82
|
end
|
67
83
|
it { expect(subject['emb_one']).to be_nil }
|
68
84
|
end
|
69
|
-
|
70
|
-
after(:all) do
|
71
|
-
Object.send(:remove_const, :ModelOne)
|
72
|
-
Object.send(:remove_const, :EmbOne)
|
73
|
-
end
|
74
85
|
end
|
75
86
|
|
76
87
|
context 'Case: relation with alias' do
|
77
|
-
before
|
88
|
+
before :each do
|
78
89
|
class ModelOne
|
79
90
|
include Mongoid::Document
|
80
91
|
include Mongoid::History::Trackable
|
@@ -91,8 +102,12 @@ describe Mongoid::History::Attributes::Update do
|
|
91
102
|
end
|
92
103
|
end
|
93
104
|
|
94
|
-
|
95
|
-
ModelOne
|
105
|
+
after :each do
|
106
|
+
Object.send(:remove_const, :ModelOne)
|
107
|
+
Object.send(:remove_const, :EmbOne)
|
108
|
+
end
|
109
|
+
|
110
|
+
before :each do
|
96
111
|
ModelOne.track_history on: :emb_one
|
97
112
|
allow(base).to receive(:changes) { changes }
|
98
113
|
end
|
@@ -104,15 +119,10 @@ describe Mongoid::History::Attributes::Update do
|
|
104
119
|
end
|
105
120
|
subject { base.attributes }
|
106
121
|
it { expect(subject['eon']).to eq [{ 'em_foo' => 'Em-Foo' }, { 'em_foo' => 'Em-Foo-new', 'em_bar' => 'Em-Bar-new' }] }
|
107
|
-
|
108
|
-
after(:all) do
|
109
|
-
Object.send(:remove_const, :ModelOne)
|
110
|
-
Object.send(:remove_const, :EmbOne)
|
111
|
-
end
|
112
122
|
end
|
113
123
|
|
114
124
|
context 'when original and modified value same' do
|
115
|
-
before
|
125
|
+
before :each do
|
116
126
|
class DummyUpdateModel
|
117
127
|
include Mongoid::Document
|
118
128
|
include Mongoid::History::Trackable
|
@@ -129,8 +139,12 @@ describe Mongoid::History::Attributes::Update do
|
|
129
139
|
end
|
130
140
|
end
|
131
141
|
|
132
|
-
|
133
|
-
DummyUpdateModel
|
142
|
+
after :each do
|
143
|
+
Object.send(:remove_const, :DummyUpdateModel)
|
144
|
+
Object.send(:remove_const, :DummyEmbeddedModel)
|
145
|
+
end
|
146
|
+
|
147
|
+
before :each do
|
134
148
|
allow(base).to receive(:changes) { changes }
|
135
149
|
DummyUpdateModel.track_history on: :dummy_embedded_model
|
136
150
|
end
|
@@ -142,22 +156,21 @@ describe Mongoid::History::Attributes::Update do
|
|
142
156
|
end
|
143
157
|
subject { base.attributes }
|
144
158
|
it { expect(subject.keys).to_not include 'dummy_embedded_model' }
|
145
|
-
|
146
|
-
after(:all) do
|
147
|
-
Object.send(:remove_const, :DummyUpdateModel)
|
148
|
-
Object.send(:remove_const, :DummyEmbeddedModel)
|
149
|
-
end
|
150
159
|
end
|
151
160
|
end
|
152
161
|
|
153
162
|
describe '#insert_embeds_many_changes' do
|
154
163
|
context 'Case: relation without alias' do
|
155
|
-
before
|
164
|
+
before :each do
|
156
165
|
class ModelOne
|
157
166
|
include Mongoid::Document
|
158
167
|
include Mongoid::History::Trackable
|
159
168
|
store_in collection: :model_ones
|
160
|
-
|
169
|
+
if Mongoid::Compatibility::Version.mongoid7_or_newer?
|
170
|
+
embeds_many :emb_ones
|
171
|
+
else
|
172
|
+
embeds_many :emb_ones, inverse_class_name: 'EmbOne'
|
173
|
+
end
|
161
174
|
track_history on: :fields
|
162
175
|
end
|
163
176
|
|
@@ -169,8 +182,7 @@ describe Mongoid::History::Attributes::Update do
|
|
169
182
|
end
|
170
183
|
end
|
171
184
|
|
172
|
-
before
|
173
|
-
ModelOne.clear_trackable_memoization
|
185
|
+
before :each do
|
174
186
|
allow(base).to receive(:changes) { changes }
|
175
187
|
end
|
176
188
|
|
@@ -179,7 +191,9 @@ describe Mongoid::History::Attributes::Update do
|
|
179
191
|
subject { base.attributes }
|
180
192
|
|
181
193
|
context 'with whitelist attributes' do
|
182
|
-
before
|
194
|
+
before :each do
|
195
|
+
ModelOne.track_history on: { emb_ones: :em_foo }
|
196
|
+
end
|
183
197
|
let(:changes) do
|
184
198
|
{ 'emb_ones' => [[{ 'em_foo' => 'Em-Foo', 'em_bar' => 'Em-Bar' }], [{ 'em_foo' => 'Em-Foo-new', 'em_bar' => 'Em-Bar-new' }]] }
|
185
199
|
end
|
@@ -189,7 +203,9 @@ describe Mongoid::History::Attributes::Update do
|
|
189
203
|
end
|
190
204
|
|
191
205
|
context 'without whitelist attributes' do
|
192
|
-
before
|
206
|
+
before :each do
|
207
|
+
ModelOne.track_history(on: :emb_ones)
|
208
|
+
end
|
193
209
|
let(:changes) do
|
194
210
|
{ 'emb_ones' => [[{ 'em_foo' => 'Em-Foo', 'deleted_at' => Time.now }], [{ 'em_foo' => 'Em-Foo-new', 'em_bar' => 'Em-Bar-new' }]] }
|
195
211
|
end
|
@@ -198,19 +214,23 @@ describe Mongoid::History::Attributes::Update do
|
|
198
214
|
end
|
199
215
|
end
|
200
216
|
|
201
|
-
after
|
217
|
+
after :each do
|
202
218
|
Object.send(:remove_const, :ModelOne)
|
203
219
|
Object.send(:remove_const, :EmbOne)
|
204
220
|
end
|
205
221
|
end
|
206
222
|
|
207
223
|
context 'Case: relation with alias' do
|
208
|
-
before
|
224
|
+
before :each do
|
209
225
|
class ModelOne
|
210
226
|
include Mongoid::Document
|
211
227
|
include Mongoid::History::Trackable
|
212
228
|
store_in collection: :model_ones
|
213
|
-
|
229
|
+
if Mongoid::Compatibility::Version.mongoid7_or_newer?
|
230
|
+
embeds_many :emb_ones, store_as: :eons
|
231
|
+
else
|
232
|
+
embeds_many :emb_ones, store_as: :eons, inverse_class_name: 'EmbOne'
|
233
|
+
end
|
214
234
|
track_history on: :fields
|
215
235
|
end
|
216
236
|
|
@@ -222,8 +242,7 @@ describe Mongoid::History::Attributes::Update do
|
|
222
242
|
end
|
223
243
|
end
|
224
244
|
|
225
|
-
before
|
226
|
-
ModelOne.clear_trackable_memoization
|
245
|
+
before :each do
|
227
246
|
ModelOne.track_history on: :emb_ones
|
228
247
|
allow(base).to receive(:changes) { changes }
|
229
248
|
end
|
@@ -238,19 +257,23 @@ describe Mongoid::History::Attributes::Update do
|
|
238
257
|
expect(subject['eons']).to eq [[{ 'em_foo' => 'Em-Foo' }], [{ 'em_foo' => 'Em-Foo-new', 'em_bar' => 'Em-Bar-new' }]]
|
239
258
|
end
|
240
259
|
|
241
|
-
after
|
260
|
+
after :each do
|
242
261
|
Object.send(:remove_const, :ModelOne)
|
243
262
|
Object.send(:remove_const, :EmbOne)
|
244
263
|
end
|
245
264
|
end
|
246
265
|
|
247
266
|
context 'when original and modified value same' do
|
248
|
-
before
|
267
|
+
before :each do
|
249
268
|
class ModelOne
|
250
269
|
include Mongoid::Document
|
251
270
|
include Mongoid::History::Trackable
|
252
271
|
store_in collection: :model_ones
|
253
|
-
|
272
|
+
if Mongoid::Compatibility::Version.mongoid7_or_newer?
|
273
|
+
embeds_many :emb_ones
|
274
|
+
else
|
275
|
+
embeds_many :emb_ones, inverse_class_name: 'EmbOne'
|
276
|
+
end
|
254
277
|
track_history on: :fields
|
255
278
|
end
|
256
279
|
|
@@ -262,8 +285,7 @@ describe Mongoid::History::Attributes::Update do
|
|
262
285
|
end
|
263
286
|
end
|
264
287
|
|
265
|
-
before
|
266
|
-
ModelOne.clear_trackable_memoization
|
288
|
+
before :each do
|
267
289
|
allow(base).to receive(:changes) { changes }
|
268
290
|
ModelOne.track_history on: :emb_ones
|
269
291
|
end
|
@@ -276,7 +298,7 @@ describe Mongoid::History::Attributes::Update do
|
|
276
298
|
subject { base.attributes }
|
277
299
|
it { expect(subject.keys).to_not include 'emb_ones' }
|
278
300
|
|
279
|
-
after
|
301
|
+
after :each do
|
280
302
|
Object.send(:remove_const, :ModelOne)
|
281
303
|
Object.send(:remove_const, :EmbOne)
|
282
304
|
end
|
@@ -284,7 +306,7 @@ describe Mongoid::History::Attributes::Update do
|
|
284
306
|
end
|
285
307
|
|
286
308
|
context 'when original and modified values blank' do
|
287
|
-
before
|
309
|
+
before :each do
|
288
310
|
class DummyParent
|
289
311
|
include Mongoid::Document
|
290
312
|
include Mongoid::History::Trackable
|
@@ -299,8 +321,7 @@ describe Mongoid::History::Attributes::Update do
|
|
299
321
|
end
|
300
322
|
end
|
301
323
|
|
302
|
-
before
|
303
|
-
DummyParent.clear_trackable_memoization
|
324
|
+
before :each do
|
304
325
|
allow(base).to receive(:changes) { changes }
|
305
326
|
DummyParent.track_history on: :other_dummy_parent_ids
|
306
327
|
end
|
@@ -312,7 +333,7 @@ describe Mongoid::History::Attributes::Update do
|
|
312
333
|
subject { base.attributes }
|
313
334
|
it { expect(subject.keys).to_not include 'other_dummy_parent_ids' }
|
314
335
|
|
315
|
-
after
|
336
|
+
after :each do
|
316
337
|
Object.send(:remove_const, :DummyParent)
|
317
338
|
Object.send(:remove_const, :OtherDummyParent)
|
318
339
|
end
|