mongoid-history 0.8.3 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -1
  3. data/.document +5 -5
  4. data/.github/workflows/test.yml +72 -0
  5. data/.gitignore +46 -46
  6. data/.rspec +2 -2
  7. data/.rubocop.yml +6 -6
  8. data/.rubocop_todo.yml +99 -99
  9. data/CHANGELOG.md +173 -163
  10. data/CONTRIBUTING.md +117 -118
  11. data/Dangerfile +1 -1
  12. data/Gemfile +49 -40
  13. data/LICENSE.txt +20 -20
  14. data/README.md +609 -608
  15. data/RELEASING.md +66 -67
  16. data/Rakefile +24 -24
  17. data/UPGRADING.md +53 -53
  18. data/lib/mongoid/history/attributes/base.rb +72 -72
  19. data/lib/mongoid/history/attributes/create.rb +45 -45
  20. data/lib/mongoid/history/attributes/destroy.rb +34 -34
  21. data/lib/mongoid/history/attributes/update.rb +104 -104
  22. data/lib/mongoid/history/options.rb +177 -177
  23. data/lib/mongoid/history/trackable.rb +588 -583
  24. data/lib/mongoid/history/tracker.rb +247 -247
  25. data/lib/mongoid/history/version.rb +5 -5
  26. data/lib/mongoid/history.rb +77 -77
  27. data/lib/mongoid-history.rb +1 -1
  28. data/mongoid-history.gemspec +25 -25
  29. data/perf/benchmark_modified_attributes_for_create.rb +65 -65
  30. data/perf/gc_suite.rb +21 -21
  31. data/spec/integration/embedded_in_polymorphic_spec.rb +112 -112
  32. data/spec/integration/integration_spec.rb +976 -976
  33. data/spec/integration/multi_relation_spec.rb +47 -47
  34. data/spec/integration/multiple_trackers_spec.rb +68 -68
  35. data/spec/integration/nested_embedded_documents_spec.rb +64 -64
  36. data/spec/integration/nested_embedded_documents_tracked_in_parent_spec.rb +124 -124
  37. data/spec/integration/nested_embedded_polymorphic_documents_spec.rb +115 -115
  38. data/spec/integration/subclasses_spec.rb +47 -47
  39. data/spec/integration/track_history_order_spec.rb +84 -84
  40. data/spec/integration/validation_failure_spec.rb +76 -76
  41. data/spec/spec_helper.rb +32 -30
  42. data/spec/support/error_helpers.rb +7 -0
  43. data/spec/support/mongoid.rb +11 -11
  44. data/spec/support/mongoid_history.rb +12 -12
  45. data/spec/unit/attributes/base_spec.rb +141 -141
  46. data/spec/unit/attributes/create_spec.rb +342 -342
  47. data/spec/unit/attributes/destroy_spec.rb +228 -228
  48. data/spec/unit/attributes/update_spec.rb +342 -342
  49. data/spec/unit/callback_options_spec.rb +165 -165
  50. data/spec/unit/embedded_methods_spec.rb +87 -87
  51. data/spec/unit/history_spec.rb +58 -58
  52. data/spec/unit/my_instance_methods_spec.rb +555 -555
  53. data/spec/unit/options_spec.rb +365 -365
  54. data/spec/unit/singleton_methods_spec.rb +406 -406
  55. data/spec/unit/store/default_store_spec.rb +11 -11
  56. data/spec/unit/store/request_store_spec.rb +13 -13
  57. data/spec/unit/trackable_spec.rb +1057 -987
  58. data/spec/unit/tracker_spec.rb +190 -190
  59. metadata +9 -7
  60. 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