mongoid-history 0.8.3 → 0.8.5
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/.coveralls.yml +1 -1
- data/.document +5 -5
- data/.github/workflows/test.yml +72 -0
- data/.gitignore +46 -46
- data/.rspec +2 -2
- data/.rubocop.yml +6 -6
- data/.rubocop_todo.yml +99 -99
- data/CHANGELOG.md +173 -163
- data/CONTRIBUTING.md +117 -118
- data/Dangerfile +1 -1
- data/Gemfile +49 -40
- data/LICENSE.txt +20 -20
- data/README.md +609 -608
- data/RELEASING.md +66 -67
- data/Rakefile +24 -24
- data/UPGRADING.md +53 -53
- data/lib/mongoid/history/attributes/base.rb +72 -72
- data/lib/mongoid/history/attributes/create.rb +45 -45
- data/lib/mongoid/history/attributes/destroy.rb +34 -34
- data/lib/mongoid/history/attributes/update.rb +104 -104
- data/lib/mongoid/history/options.rb +177 -177
- data/lib/mongoid/history/trackable.rb +588 -583
- data/lib/mongoid/history/tracker.rb +247 -247
- data/lib/mongoid/history/version.rb +5 -5
- data/lib/mongoid/history.rb +77 -77
- data/lib/mongoid-history.rb +1 -1
- data/mongoid-history.gemspec +25 -25
- data/perf/benchmark_modified_attributes_for_create.rb +65 -65
- data/perf/gc_suite.rb +21 -21
- data/spec/integration/embedded_in_polymorphic_spec.rb +112 -112
- data/spec/integration/integration_spec.rb +976 -976
- data/spec/integration/multi_relation_spec.rb +47 -47
- data/spec/integration/multiple_trackers_spec.rb +68 -68
- data/spec/integration/nested_embedded_documents_spec.rb +64 -64
- data/spec/integration/nested_embedded_documents_tracked_in_parent_spec.rb +124 -124
- data/spec/integration/nested_embedded_polymorphic_documents_spec.rb +115 -115
- data/spec/integration/subclasses_spec.rb +47 -47
- data/spec/integration/track_history_order_spec.rb +84 -84
- data/spec/integration/validation_failure_spec.rb +76 -76
- data/spec/spec_helper.rb +32 -30
- data/spec/support/error_helpers.rb +7 -0
- data/spec/support/mongoid.rb +11 -11
- data/spec/support/mongoid_history.rb +12 -12
- data/spec/unit/attributes/base_spec.rb +141 -141
- data/spec/unit/attributes/create_spec.rb +342 -342
- data/spec/unit/attributes/destroy_spec.rb +228 -228
- data/spec/unit/attributes/update_spec.rb +342 -342
- data/spec/unit/callback_options_spec.rb +165 -165
- data/spec/unit/embedded_methods_spec.rb +87 -87
- data/spec/unit/history_spec.rb +58 -58
- data/spec/unit/my_instance_methods_spec.rb +555 -555
- data/spec/unit/options_spec.rb +365 -365
- data/spec/unit/singleton_methods_spec.rb +406 -406
- data/spec/unit/store/default_store_spec.rb +11 -11
- data/spec/unit/store/request_store_spec.rb +13 -13
- data/spec/unit/trackable_spec.rb +1057 -987
- data/spec/unit/tracker_spec.rb +190 -190
- metadata +9 -7
- data/.travis.yml +0 -36
@@ -1,228 +1,228 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Mongoid::History::Attributes::Destroy do
|
4
|
-
before :each do
|
5
|
-
class ModelOne
|
6
|
-
include Mongoid::Document
|
7
|
-
include Mongoid::History::Trackable
|
8
|
-
|
9
|
-
store_in collection: :model_ones
|
10
|
-
|
11
|
-
field :foo
|
12
|
-
field :b, as: :bar
|
13
|
-
|
14
|
-
track_history on: :foo, modifier_field_optional: true
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
after :each do
|
19
|
-
Object.send(:remove_const, :ModelOne)
|
20
|
-
end
|
21
|
-
|
22
|
-
let(:obj_one) { ModelOne.new }
|
23
|
-
let(:base) { described_class.new(obj_one) }
|
24
|
-
subject { base }
|
25
|
-
|
26
|
-
describe '#attributes' do
|
27
|
-
subject { base.attributes }
|
28
|
-
|
29
|
-
describe '#fields' do
|
30
|
-
before :each do
|
31
|
-
obj_one.save!
|
32
|
-
end
|
33
|
-
|
34
|
-
let(:obj_one) { ModelOne.new(foo: 'Foo', bar: 'Bar') }
|
35
|
-
it { is_expected.to eq('_id' => [obj_one._id, nil], 'foo' => ['Foo', nil], 'version' => [1, nil]) }
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#insert_embeds_one_changes' do
|
39
|
-
before :each do
|
40
|
-
class ModelTwo
|
41
|
-
include Mongoid::Document
|
42
|
-
include Mongoid::History::Trackable
|
43
|
-
|
44
|
-
store_in collection: :model_twos
|
45
|
-
|
46
|
-
embeds_one :emb_two
|
47
|
-
|
48
|
-
track_history on: :fields, modifier_field_optional: true
|
49
|
-
end
|
50
|
-
|
51
|
-
class EmbTwo
|
52
|
-
include Mongoid::Document
|
53
|
-
|
54
|
-
field :em_foo
|
55
|
-
field :em_bar
|
56
|
-
|
57
|
-
embedded_in :model_two
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
after :each do
|
62
|
-
Object.send(:remove_const, :ModelTwo)
|
63
|
-
Object.send(:remove_const, :EmbTwo)
|
64
|
-
end
|
65
|
-
|
66
|
-
let(:obj_two) { ModelTwo.new(emb_two: emb_obj_two) }
|
67
|
-
let(:emb_obj_two) { EmbTwo.new(em_foo: 'Em-Foo', em_bar: 'Em-Bar') }
|
68
|
-
let(:base) { described_class.new(obj_two) }
|
69
|
-
|
70
|
-
context 'when relation tracked' do
|
71
|
-
before :each do
|
72
|
-
ModelTwo.track_history on: :emb_two, modifier_field_optional: true
|
73
|
-
obj_two.save!
|
74
|
-
end
|
75
|
-
it { expect(subject['emb_two']).to eq [{ '_id' => emb_obj_two._id, 'em_foo' => 'Em-Foo', 'em_bar' => 'Em-Bar' }, nil] }
|
76
|
-
end
|
77
|
-
|
78
|
-
context 'when relation not tracked' do
|
79
|
-
before :each do
|
80
|
-
ModelTwo.track_history on: :fields, modifier_field_optional: true
|
81
|
-
allow(ModelTwo).to receive(:dynamic_enabled?) { false }
|
82
|
-
obj_two.save!
|
83
|
-
end
|
84
|
-
it { expect(subject['emb_two']).to be_nil }
|
85
|
-
end
|
86
|
-
|
87
|
-
context 'when relation with alias' do
|
88
|
-
before :each do
|
89
|
-
class ModelThree
|
90
|
-
include Mongoid::Document
|
91
|
-
include Mongoid::History::Trackable
|
92
|
-
|
93
|
-
store_in collection: :model_threes
|
94
|
-
embeds_one :emb_three, store_as: :emtr
|
95
|
-
|
96
|
-
track_history on: :emb_three, modifier_field_optional: true
|
97
|
-
end
|
98
|
-
|
99
|
-
class EmbThree
|
100
|
-
include Mongoid::Document
|
101
|
-
|
102
|
-
field :em_foo
|
103
|
-
embedded_in :model_three
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
after :each do
|
108
|
-
Object.send(:remove_const, :ModelThree)
|
109
|
-
Object.send(:remove_const, :EmbThree)
|
110
|
-
end
|
111
|
-
|
112
|
-
before :each do
|
113
|
-
obj_three.save!
|
114
|
-
end
|
115
|
-
|
116
|
-
let(:obj_three) { ModelThree.new(emb_three: emb_obj_three) }
|
117
|
-
let(:emb_obj_three) { EmbThree.new(em_foo: 'Em-Foo') }
|
118
|
-
let(:base) { described_class.new(obj_three) }
|
119
|
-
|
120
|
-
it { expect(subject['emb_three']).to eq [{ '_id' => emb_obj_three._id, 'em_foo' => 'Em-Foo' }, nil] }
|
121
|
-
end
|
122
|
-
|
123
|
-
context 'relation with permitted attributes' do
|
124
|
-
before :each do
|
125
|
-
ModelTwo.track_history on: [{ emb_two: :em_foo }], modifier_field_optional: true
|
126
|
-
obj_two.save!
|
127
|
-
end
|
128
|
-
|
129
|
-
it { expect(subject['emb_two']).to eq [{ '_id' => emb_obj_two._id, 'em_foo' => 'Em-Foo' }, nil] }
|
130
|
-
end
|
131
|
-
|
132
|
-
context 'when relation object not built' do
|
133
|
-
before :each do
|
134
|
-
ModelTwo.track_history on: :emb_two, modifier_field_optional: true
|
135
|
-
obj_two.save!
|
136
|
-
end
|
137
|
-
|
138
|
-
let(:obj_two) { ModelTwo.new }
|
139
|
-
it { expect(subject['emb_two']).to be_nil }
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe '#insert_embeds_many_changes' do
|
144
|
-
context 'Case 1:' do
|
145
|
-
before :each do
|
146
|
-
class ModelTwo
|
147
|
-
include Mongoid::Document
|
148
|
-
include Mongoid::History::Trackable
|
149
|
-
|
150
|
-
embeds_many :em_twos
|
151
|
-
track_history on: :fields
|
152
|
-
end
|
153
|
-
|
154
|
-
class EmTwo
|
155
|
-
include Mongoid::Document
|
156
|
-
|
157
|
-
field :em_foo
|
158
|
-
field :em_bar
|
159
|
-
|
160
|
-
embedded_in :model_two
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
after :each do
|
165
|
-
Object.send(:remove_const, :ModelTwo)
|
166
|
-
Object.send(:remove_const, :EmTwo)
|
167
|
-
end
|
168
|
-
|
169
|
-
let(:obj_two) { ModelTwo.new(em_twos: [em_obj_two]) }
|
170
|
-
let(:em_obj_two) { EmTwo.new(em_foo: 'Em-Foo', em_bar: 'Em-Bar') }
|
171
|
-
let(:base) { described_class.new(obj_two) }
|
172
|
-
|
173
|
-
context 'when relation tracked' do
|
174
|
-
before :each do
|
175
|
-
ModelTwo.track_history on: :em_twos
|
176
|
-
end
|
177
|
-
it { expect(subject['em_twos']).to eq [[{ '_id' => em_obj_two._id, 'em_foo' => 'Em-Foo', 'em_bar' => 'Em-Bar' }], nil] }
|
178
|
-
end
|
179
|
-
|
180
|
-
context 'when relation not tracked' do
|
181
|
-
before :each do
|
182
|
-
ModelTwo.track_history on: :fields
|
183
|
-
end
|
184
|
-
it { expect(subject['em_twos']).to be_nil }
|
185
|
-
end
|
186
|
-
|
187
|
-
context 'when relation with permitted attributes for tracking' do
|
188
|
-
before :each do
|
189
|
-
ModelTwo.track_history on: { em_twos: :em_foo }
|
190
|
-
end
|
191
|
-
it { expect(subject['em_twos']).to eq [[{ '_id' => em_obj_two._id, 'em_foo' => 'Em-Foo' }], nil] }
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
context 'when relation with alias' do
|
196
|
-
before :each do
|
197
|
-
class ModelTwo
|
198
|
-
include Mongoid::Document
|
199
|
-
include Mongoid::History::Trackable
|
200
|
-
|
201
|
-
embeds_many :em_twos, store_as: :emws
|
202
|
-
track_history on: :fields
|
203
|
-
|
204
|
-
track_history on: :em_twos
|
205
|
-
end
|
206
|
-
|
207
|
-
class EmTwo
|
208
|
-
include Mongoid::Document
|
209
|
-
|
210
|
-
field :em_foo
|
211
|
-
embedded_in :model_two
|
212
|
-
end
|
213
|
-
end
|
214
|
-
|
215
|
-
after :each do
|
216
|
-
Object.send(:remove_const, :ModelTwo)
|
217
|
-
Object.send(:remove_const, :EmTwo)
|
218
|
-
end
|
219
|
-
|
220
|
-
let(:obj_two) { ModelTwo.new(em_twos: [em_obj_two]) }
|
221
|
-
let(:em_obj_two) { EmTwo.new(em_foo: 'Em-Foo') }
|
222
|
-
let(:base) { described_class.new(obj_two) }
|
223
|
-
|
224
|
-
it { expect(subject['em_twos']).to eq [[{ '_id' => em_obj_two._id, 'em_foo' => 'Em-Foo' }], nil] }
|
225
|
-
end
|
226
|
-
end
|
227
|
-
end
|
228
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongoid::History::Attributes::Destroy do
|
4
|
+
before :each do
|
5
|
+
class ModelOne
|
6
|
+
include Mongoid::Document
|
7
|
+
include Mongoid::History::Trackable
|
8
|
+
|
9
|
+
store_in collection: :model_ones
|
10
|
+
|
11
|
+
field :foo
|
12
|
+
field :b, as: :bar
|
13
|
+
|
14
|
+
track_history on: :foo, modifier_field_optional: true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
after :each do
|
19
|
+
Object.send(:remove_const, :ModelOne)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:obj_one) { ModelOne.new }
|
23
|
+
let(:base) { described_class.new(obj_one) }
|
24
|
+
subject { base }
|
25
|
+
|
26
|
+
describe '#attributes' do
|
27
|
+
subject { base.attributes }
|
28
|
+
|
29
|
+
describe '#fields' do
|
30
|
+
before :each do
|
31
|
+
obj_one.save!
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:obj_one) { ModelOne.new(foo: 'Foo', bar: 'Bar') }
|
35
|
+
it { is_expected.to eq('_id' => [obj_one._id, nil], 'foo' => ['Foo', nil], 'version' => [1, nil]) }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#insert_embeds_one_changes' do
|
39
|
+
before :each do
|
40
|
+
class ModelTwo
|
41
|
+
include Mongoid::Document
|
42
|
+
include Mongoid::History::Trackable
|
43
|
+
|
44
|
+
store_in collection: :model_twos
|
45
|
+
|
46
|
+
embeds_one :emb_two
|
47
|
+
|
48
|
+
track_history on: :fields, modifier_field_optional: true
|
49
|
+
end
|
50
|
+
|
51
|
+
class EmbTwo
|
52
|
+
include Mongoid::Document
|
53
|
+
|
54
|
+
field :em_foo
|
55
|
+
field :em_bar
|
56
|
+
|
57
|
+
embedded_in :model_two
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
after :each do
|
62
|
+
Object.send(:remove_const, :ModelTwo)
|
63
|
+
Object.send(:remove_const, :EmbTwo)
|
64
|
+
end
|
65
|
+
|
66
|
+
let(:obj_two) { ModelTwo.new(emb_two: emb_obj_two) }
|
67
|
+
let(:emb_obj_two) { EmbTwo.new(em_foo: 'Em-Foo', em_bar: 'Em-Bar') }
|
68
|
+
let(:base) { described_class.new(obj_two) }
|
69
|
+
|
70
|
+
context 'when relation tracked' do
|
71
|
+
before :each do
|
72
|
+
ModelTwo.track_history on: :emb_two, modifier_field_optional: true
|
73
|
+
obj_two.save!
|
74
|
+
end
|
75
|
+
it { expect(subject['emb_two']).to eq [{ '_id' => emb_obj_two._id, 'em_foo' => 'Em-Foo', 'em_bar' => 'Em-Bar' }, nil] }
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when relation not tracked' do
|
79
|
+
before :each do
|
80
|
+
ModelTwo.track_history on: :fields, modifier_field_optional: true
|
81
|
+
allow(ModelTwo).to receive(:dynamic_enabled?) { false }
|
82
|
+
obj_two.save!
|
83
|
+
end
|
84
|
+
it { expect(subject['emb_two']).to be_nil }
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when relation with alias' do
|
88
|
+
before :each do
|
89
|
+
class ModelThree
|
90
|
+
include Mongoid::Document
|
91
|
+
include Mongoid::History::Trackable
|
92
|
+
|
93
|
+
store_in collection: :model_threes
|
94
|
+
embeds_one :emb_three, store_as: :emtr
|
95
|
+
|
96
|
+
track_history on: :emb_three, modifier_field_optional: true
|
97
|
+
end
|
98
|
+
|
99
|
+
class EmbThree
|
100
|
+
include Mongoid::Document
|
101
|
+
|
102
|
+
field :em_foo
|
103
|
+
embedded_in :model_three
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
after :each do
|
108
|
+
Object.send(:remove_const, :ModelThree)
|
109
|
+
Object.send(:remove_const, :EmbThree)
|
110
|
+
end
|
111
|
+
|
112
|
+
before :each do
|
113
|
+
obj_three.save!
|
114
|
+
end
|
115
|
+
|
116
|
+
let(:obj_three) { ModelThree.new(emb_three: emb_obj_three) }
|
117
|
+
let(:emb_obj_three) { EmbThree.new(em_foo: 'Em-Foo') }
|
118
|
+
let(:base) { described_class.new(obj_three) }
|
119
|
+
|
120
|
+
it { expect(subject['emb_three']).to eq [{ '_id' => emb_obj_three._id, 'em_foo' => 'Em-Foo' }, nil] }
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'relation with permitted attributes' do
|
124
|
+
before :each do
|
125
|
+
ModelTwo.track_history on: [{ emb_two: :em_foo }], modifier_field_optional: true
|
126
|
+
obj_two.save!
|
127
|
+
end
|
128
|
+
|
129
|
+
it { expect(subject['emb_two']).to eq [{ '_id' => emb_obj_two._id, 'em_foo' => 'Em-Foo' }, nil] }
|
130
|
+
end
|
131
|
+
|
132
|
+
context 'when relation object not built' do
|
133
|
+
before :each do
|
134
|
+
ModelTwo.track_history on: :emb_two, modifier_field_optional: true
|
135
|
+
obj_two.save!
|
136
|
+
end
|
137
|
+
|
138
|
+
let(:obj_two) { ModelTwo.new }
|
139
|
+
it { expect(subject['emb_two']).to be_nil }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '#insert_embeds_many_changes' do
|
144
|
+
context 'Case 1:' do
|
145
|
+
before :each do
|
146
|
+
class ModelTwo
|
147
|
+
include Mongoid::Document
|
148
|
+
include Mongoid::History::Trackable
|
149
|
+
|
150
|
+
embeds_many :em_twos
|
151
|
+
track_history on: :fields
|
152
|
+
end
|
153
|
+
|
154
|
+
class EmTwo
|
155
|
+
include Mongoid::Document
|
156
|
+
|
157
|
+
field :em_foo
|
158
|
+
field :em_bar
|
159
|
+
|
160
|
+
embedded_in :model_two
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
after :each do
|
165
|
+
Object.send(:remove_const, :ModelTwo)
|
166
|
+
Object.send(:remove_const, :EmTwo)
|
167
|
+
end
|
168
|
+
|
169
|
+
let(:obj_two) { ModelTwo.new(em_twos: [em_obj_two]) }
|
170
|
+
let(:em_obj_two) { EmTwo.new(em_foo: 'Em-Foo', em_bar: 'Em-Bar') }
|
171
|
+
let(:base) { described_class.new(obj_two) }
|
172
|
+
|
173
|
+
context 'when relation tracked' do
|
174
|
+
before :each do
|
175
|
+
ModelTwo.track_history on: :em_twos
|
176
|
+
end
|
177
|
+
it { expect(subject['em_twos']).to eq [[{ '_id' => em_obj_two._id, 'em_foo' => 'Em-Foo', 'em_bar' => 'Em-Bar' }], nil] }
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'when relation not tracked' do
|
181
|
+
before :each do
|
182
|
+
ModelTwo.track_history on: :fields
|
183
|
+
end
|
184
|
+
it { expect(subject['em_twos']).to be_nil }
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'when relation with permitted attributes for tracking' do
|
188
|
+
before :each do
|
189
|
+
ModelTwo.track_history on: { em_twos: :em_foo }
|
190
|
+
end
|
191
|
+
it { expect(subject['em_twos']).to eq [[{ '_id' => em_obj_two._id, 'em_foo' => 'Em-Foo' }], nil] }
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context 'when relation with alias' do
|
196
|
+
before :each do
|
197
|
+
class ModelTwo
|
198
|
+
include Mongoid::Document
|
199
|
+
include Mongoid::History::Trackable
|
200
|
+
|
201
|
+
embeds_many :em_twos, store_as: :emws
|
202
|
+
track_history on: :fields
|
203
|
+
|
204
|
+
track_history on: :em_twos
|
205
|
+
end
|
206
|
+
|
207
|
+
class EmTwo
|
208
|
+
include Mongoid::Document
|
209
|
+
|
210
|
+
field :em_foo
|
211
|
+
embedded_in :model_two
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
after :each do
|
216
|
+
Object.send(:remove_const, :ModelTwo)
|
217
|
+
Object.send(:remove_const, :EmTwo)
|
218
|
+
end
|
219
|
+
|
220
|
+
let(:obj_two) { ModelTwo.new(em_twos: [em_obj_two]) }
|
221
|
+
let(:em_obj_two) { EmTwo.new(em_foo: 'Em-Foo') }
|
222
|
+
let(:base) { described_class.new(obj_two) }
|
223
|
+
|
224
|
+
it { expect(subject['em_twos']).to eq [[{ '_id' => em_obj_two._id, 'em_foo' => 'Em-Foo' }], nil] }
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|