mongoid-history 0.8.0 → 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 +5 -5
  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 -101
  9. data/CHANGELOG.md +173 -144
  10. data/CONTRIBUTING.md +117 -118
  11. data/Dangerfile +1 -1
  12. data/Gemfile +49 -37
  13. data/LICENSE.txt +20 -20
  14. data/README.md +609 -595
  15. data/RELEASING.md +66 -67
  16. data/Rakefile +24 -24
  17. data/UPGRADING.md +53 -34
  18. data/lib/mongoid/history/attributes/base.rb +72 -72
  19. data/lib/mongoid/history/attributes/create.rb +45 -50
  20. data/lib/mongoid/history/attributes/destroy.rb +34 -34
  21. data/lib/mongoid/history/attributes/update.rb +104 -45
  22. data/lib/mongoid/history/options.rb +177 -179
  23. data/lib/mongoid/history/trackable.rb +588 -521
  24. data/lib/mongoid/history/tracker.rb +247 -244
  25. data/lib/mongoid/history/version.rb +5 -5
  26. data/lib/mongoid/history.rb +77 -52
  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 -0
  30. data/perf/gc_suite.rb +21 -0
  31. data/spec/integration/embedded_in_polymorphic_spec.rb +112 -135
  32. data/spec/integration/integration_spec.rb +976 -942
  33. data/spec/integration/multi_relation_spec.rb +47 -53
  34. data/spec/integration/multiple_trackers_spec.rb +68 -71
  35. data/spec/integration/nested_embedded_documents_spec.rb +64 -84
  36. data/spec/integration/nested_embedded_documents_tracked_in_parent_spec.rb +124 -0
  37. data/spec/integration/nested_embedded_polymorphic_documents_spec.rb +115 -127
  38. data/spec/integration/subclasses_spec.rb +47 -29
  39. data/spec/integration/track_history_order_spec.rb +84 -52
  40. data/spec/integration/validation_failure_spec.rb +76 -63
  41. data/spec/spec_helper.rb +32 -25
  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 -13
  45. data/spec/unit/attributes/base_spec.rb +141 -150
  46. data/spec/unit/attributes/create_spec.rb +342 -315
  47. data/spec/unit/attributes/destroy_spec.rb +228 -218
  48. data/spec/unit/attributes/update_spec.rb +342 -321
  49. data/spec/unit/callback_options_spec.rb +165 -159
  50. data/spec/unit/embedded_methods_spec.rb +87 -69
  51. data/spec/unit/history_spec.rb +58 -35
  52. data/spec/unit/my_instance_methods_spec.rb +555 -485
  53. data/spec/unit/options_spec.rb +365 -327
  54. data/spec/unit/singleton_methods_spec.rb +406 -338
  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 -689
  58. data/spec/unit/tracker_spec.rb +190 -163
  59. metadata +13 -8
  60. data/.travis.yml +0 -35
@@ -1,163 +1,190 @@
1
- require 'spec_helper'
2
-
3
- describe Mongoid::History::Tracker do
4
- before do
5
- @tracker_class_name = Mongoid::History.tracker_class_name
6
- Mongoid::History.tracker_class_name = nil
7
- end
8
-
9
- it 'should set tracker_class_name when included' do
10
- class MyTracker
11
- include Mongoid::History::Tracker
12
- end
13
- expect(Mongoid::History.tracker_class_name).to eq(:my_tracker)
14
- end
15
-
16
- it 'should set fields defaults' do
17
- class MyTrackerTwo
18
- include Mongoid::History::Tracker
19
- end
20
- expect(MyTrackerTwo.new.association_chain).to eq([])
21
- expect(MyTrackerTwo.new.original).to eq({})
22
- expect(MyTrackerTwo.new.modified).to eq({})
23
- end
24
-
25
- describe '#tracked_edits' do
26
- before(:all) do
27
- TrackerOne = Class.new do
28
- def self.name
29
- 'TrackerOne'
30
- end
31
-
32
- include Mongoid::History::Tracker
33
- end
34
-
35
- ModelOne = Class.new do
36
- include Mongoid::Document
37
- include Mongoid::History::Trackable
38
- store_in collection: :model_ones
39
- embeds_many :emb_ones, inverse_class_name: 'EmbOne'
40
- end
41
-
42
- EmbOne = Class.new do
43
- include Mongoid::Document
44
- field :em_foo
45
- embedded_in :model_one
46
- end
47
- end
48
-
49
- context 'when embeds_many' do
50
- before(:each) do
51
- ModelOne.instance_variable_set(:@history_trackable_options, nil)
52
- ModelOne.track_history(on: :emb_ones)
53
- allow(tracker).to receive(:trackable_parent_class) { ModelOne }
54
- end
55
-
56
- let(:tracker) { TrackerOne.new }
57
-
58
- describe '#prepare_tracked_edits_for_embeds_many' do
59
- before(:each) do
60
- tracker.instance_variable_set(:@tracked_edits, nil)
61
- allow(tracker).to receive(:tracked_changes) { changes }
62
- end
63
- let(:emb_one) { EmbOne.new }
64
- let(:emb_one_2) { EmbOne.new }
65
- let(:emb_one_3) { EmbOne.new }
66
- let(:changes) { {} }
67
- subject { tracker.tracked_edits['embeds_many']['emb_ones'] }
68
-
69
- context 'when all values present' do
70
- let(:changes) do
71
- { 'emb_ones' => { from: [{ '_id' => emb_one._id, 'em_foo' => 'Em-Foo' },
72
- { '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }],
73
- to: [{ '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2-new' },
74
- { '_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3' }] } }
75
- end
76
- it 'should include :add, :remove, and :modify' do
77
- expect(subject['add']).to eq [{ '_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3' }]
78
- expect(subject['remove']).to eq [{ '_id' => emb_one._id, 'em_foo' => 'Em-Foo' }]
79
- expect(subject['modify'].size).to eq 1
80
- expect(subject['modify'][0]['from']).to eq('_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2')
81
- expect(subject['modify'][0]['to']).to eq('_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2-new')
82
- end
83
- end
84
-
85
- context 'when value :from blank' do
86
- let(:changes) do
87
- { 'emb_ones' => { to: [{ '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2-new' },
88
- { '_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3' }] } }
89
- end
90
- it 'should include :add' do
91
- expect(subject['add'].size).to eq 2
92
- expect(subject['add'][0]).to eq('_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2-new')
93
- expect(subject['add'][1]).to eq('_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3')
94
- expect(subject['remove']).to be_nil
95
- expect(subject['modify']).to be_nil
96
- end
97
- end
98
-
99
- context 'when value :to blank' do
100
- let(:changes) do
101
- { 'emb_ones' => { from: [{ '_id' => emb_one._id, 'em_foo' => 'Em-Foo' },
102
- { '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }] } }
103
- end
104
- it 'should include :remove' do
105
- expect(subject['add']).to be_nil
106
- expect(subject['modify']).to be_nil
107
- expect(subject['remove'].size).to eq 2
108
- expect(subject['remove'][0]).to eq('_id' => emb_one._id, 'em_foo' => 'Em-Foo')
109
- expect(subject['remove'][1]).to eq('_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2')
110
- end
111
- end
112
-
113
- context 'when no id common in :from and :to' do
114
- let(:changes) do
115
- { 'emb_ones' => { from: [{ '_id' => emb_one._id, 'em_foo' => 'Em-Foo' }],
116
- to: [{ '_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3' }] } }
117
- end
118
- it 'should include :add, and :remove' do
119
- expect(subject['add']).to eq [{ '_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3' }]
120
- expect(subject['modify']).to be_nil
121
- expect(subject['remove']).to eq [{ '_id' => emb_one._id, 'em_foo' => 'Em-Foo' }]
122
- end
123
- end
124
-
125
- context 'when _id attribute not set' do
126
- let(:changes) do
127
- { 'emb_ones' => { from: [{ 'em_foo' => 'Em-Foo' },
128
- { '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }],
129
- to: [{ 'em_foo' => 'Em-Foo-2-new' },
130
- { 'em_foo' => 'Em-Foo-3' }] } }
131
- end
132
- it 'should include :add, and :remove' do
133
- expect(subject['add']).to eq([{ 'em_foo' => 'Em-Foo-2-new' }, { 'em_foo' => 'Em-Foo-3' }])
134
- expect(subject['modify']).to be_nil
135
- expect(subject['remove']).to eq [{ 'em_foo' => 'Em-Foo' }, { '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }]
136
- end
137
- end
138
-
139
- context 'when no change in an object' do
140
- let(:changes) do
141
- { 'emb_ones' => { from: [{ '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }],
142
- to: [{ '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }] } }
143
- end
144
- it 'should include not :add, :remove, and :modify' do
145
- expect(subject['add']).to be_nil
146
- expect(subject['modify']).to be_nil
147
- expect(subject['remove']).to be_nil
148
- end
149
- end
150
- end
151
- end
152
-
153
- after(:all) do
154
- Object.send(:remove_const, :TrackerOne)
155
- Object.send(:remove_const, :ModelOne)
156
- Object.send(:remove_const, :EmbOne)
157
- end
158
- end
159
-
160
- after do
161
- Mongoid::History.tracker_class_name = @tracker_class_name
162
- end
163
- end
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid::History::Tracker do
4
+ context 'when included' do
5
+ before :each do
6
+ Mongoid::History.tracker_class_name = nil
7
+
8
+ class MyTracker
9
+ include Mongoid::History::Tracker
10
+ end
11
+ end
12
+
13
+ after :each do
14
+ Object.send(:remove_const, :MyTracker)
15
+ end
16
+
17
+ it 'should set tracker_class_name when included' do
18
+ expect(Mongoid::History.tracker_class_name).to eq(:my_tracker)
19
+ end
20
+
21
+ it 'should set fields defaults' do
22
+ expect(MyTracker.new.association_chain).to eq([])
23
+ expect(MyTracker.new.original).to eq({})
24
+ expect(MyTracker.new.modified).to eq({})
25
+ end
26
+ end
27
+
28
+ describe '#tracked_edits' do
29
+ before :each do
30
+ class TrackerOne
31
+ include Mongoid::History::Tracker
32
+ end
33
+
34
+ class ModelOne
35
+ include Mongoid::Document
36
+ include Mongoid::History::Trackable
37
+
38
+ store_in collection: :model_ones
39
+
40
+ if Mongoid::Compatibility::Version.mongoid7_or_newer?
41
+ embeds_many :emb_ones
42
+ else
43
+ embeds_many :emb_ones, inverse_class_name: 'EmbOne'
44
+ end
45
+ end
46
+
47
+ class EmbOne
48
+ include Mongoid::Document
49
+
50
+ field :em_foo
51
+ embedded_in :model_one
52
+ end
53
+ end
54
+
55
+ after :each do
56
+ Object.send(:remove_const, :TrackerOne)
57
+ Object.send(:remove_const, :ModelOne)
58
+ Object.send(:remove_const, :EmbOne)
59
+ end
60
+
61
+ context 'when embeds_many' do
62
+ before :each do
63
+ ModelOne.track_history(on: :emb_ones)
64
+ allow(tracker).to receive(:trackable_parent_class) { ModelOne }
65
+ end
66
+
67
+ let(:tracker) { TrackerOne.new }
68
+
69
+ describe '#prepare_tracked_edits_for_embeds_many' do
70
+ before :each do
71
+ allow(tracker).to receive(:tracked_changes) { changes }
72
+ end
73
+
74
+ let(:emb_one) { EmbOne.new }
75
+ let(:emb_one_2) { EmbOne.new }
76
+ let(:emb_one_3) { EmbOne.new }
77
+ let(:changes) { {} }
78
+
79
+ subject { tracker.tracked_edits['embeds_many']['emb_ones'] }
80
+
81
+ context 'when all values present' do
82
+ let(:changes) do
83
+ {
84
+ 'emb_ones' => {
85
+ from: [{ '_id' => emb_one._id, 'em_foo' => 'Em-Foo' },
86
+ { '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }],
87
+ to: [{ '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2-new' },
88
+ { '_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3' }]
89
+ }
90
+ }
91
+ end
92
+
93
+ it 'should include :add, :remove, and :modify' do
94
+ expect(subject['add']).to eq [{ '_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3' }]
95
+ expect(subject['remove']).to eq [{ '_id' => emb_one._id, 'em_foo' => 'Em-Foo' }]
96
+ expect(subject['modify'].size).to eq 1
97
+ expect(subject['modify'][0]['from']).to eq('_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2')
98
+ expect(subject['modify'][0]['to']).to eq('_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2-new')
99
+ end
100
+ end
101
+
102
+ context 'when value :from blank' do
103
+ let(:changes) do
104
+ {
105
+ 'emb_ones' => {
106
+ to: [{ '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2-new' },
107
+ { '_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3' }]
108
+ }
109
+ }
110
+ end
111
+ it 'should include :add' do
112
+ expect(subject['add'].size).to eq 2
113
+ expect(subject['add'][0]).to eq('_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2-new')
114
+ expect(subject['add'][1]).to eq('_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3')
115
+ expect(subject['remove']).to be_nil
116
+ expect(subject['modify']).to be_nil
117
+ end
118
+ end
119
+
120
+ context 'when value :to blank' do
121
+ let(:changes) do
122
+ {
123
+ 'emb_ones' => {
124
+ from: [{ '_id' => emb_one._id, 'em_foo' => 'Em-Foo' },
125
+ { '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }]
126
+ }
127
+ }
128
+ end
129
+ it 'should include :remove' do
130
+ expect(subject['add']).to be_nil
131
+ expect(subject['modify']).to be_nil
132
+ expect(subject['remove'].size).to eq 2
133
+ expect(subject['remove'][0]).to eq('_id' => emb_one._id, 'em_foo' => 'Em-Foo')
134
+ expect(subject['remove'][1]).to eq('_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2')
135
+ end
136
+ end
137
+
138
+ context 'when no id common in :from and :to' do
139
+ let(:changes) do
140
+ {
141
+ 'emb_ones' => {
142
+ from: [{ '_id' => emb_one._id, 'em_foo' => 'Em-Foo' }],
143
+ to: [{ '_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3' }]
144
+ }
145
+ }
146
+ end
147
+ it 'should include :add, and :remove' do
148
+ expect(subject['add']).to eq [{ '_id' => emb_one_3._id, 'em_foo' => 'Em-Foo-3' }]
149
+ expect(subject['modify']).to be_nil
150
+ expect(subject['remove']).to eq [{ '_id' => emb_one._id, 'em_foo' => 'Em-Foo' }]
151
+ end
152
+ end
153
+
154
+ context 'when _id attribute not set' do
155
+ let(:changes) do
156
+ {
157
+ 'emb_ones' => {
158
+ from: [{ 'em_foo' => 'Em-Foo' },
159
+ { '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }],
160
+ to: [{ 'em_foo' => 'Em-Foo-2-new' },
161
+ { 'em_foo' => 'Em-Foo-3' }]
162
+ }
163
+ }
164
+ end
165
+ it 'should include :add, and :remove' do
166
+ expect(subject['add']).to eq([{ 'em_foo' => 'Em-Foo-2-new' }, { 'em_foo' => 'Em-Foo-3' }])
167
+ expect(subject['modify']).to be_nil
168
+ expect(subject['remove']).to eq [{ 'em_foo' => 'Em-Foo' }, { '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }]
169
+ end
170
+ end
171
+
172
+ context 'when no change in an object' do
173
+ let(:changes) do
174
+ {
175
+ 'emb_ones' => {
176
+ from: [{ '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }],
177
+ to: [{ '_id' => emb_one_2._id, 'em_foo' => 'Em-Foo-2' }]
178
+ }
179
+ }
180
+ end
181
+ it 'should include not :add, :remove, and :modify' do
182
+ expect(subject['add']).to be_nil
183
+ expect(subject['modify']).to be_nil
184
+ expect(subject['remove']).to be_nil
185
+ end
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-history
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Qian
8
8
  - Justin Grimes
9
9
  - Daniel Doubrovkine
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-01-16 00:00:00.000000000 Z
13
+ date: 2021-09-18 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: easy_diff
@@ -87,11 +87,11 @@ extra_rdoc_files: []
87
87
  files:
88
88
  - ".coveralls.yml"
89
89
  - ".document"
90
+ - ".github/workflows/test.yml"
90
91
  - ".gitignore"
91
92
  - ".rspec"
92
93
  - ".rubocop.yml"
93
94
  - ".rubocop_todo.yml"
94
- - ".travis.yml"
95
95
  - CHANGELOG.md
96
96
  - CONTRIBUTING.md
97
97
  - Dangerfile
@@ -112,16 +112,20 @@ files:
112
112
  - lib/mongoid/history/tracker.rb
113
113
  - lib/mongoid/history/version.rb
114
114
  - mongoid-history.gemspec
115
+ - perf/benchmark_modified_attributes_for_create.rb
116
+ - perf/gc_suite.rb
115
117
  - spec/integration/embedded_in_polymorphic_spec.rb
116
118
  - spec/integration/integration_spec.rb
117
119
  - spec/integration/multi_relation_spec.rb
118
120
  - spec/integration/multiple_trackers_spec.rb
119
121
  - spec/integration/nested_embedded_documents_spec.rb
122
+ - spec/integration/nested_embedded_documents_tracked_in_parent_spec.rb
120
123
  - spec/integration/nested_embedded_polymorphic_documents_spec.rb
121
124
  - spec/integration/subclasses_spec.rb
122
125
  - spec/integration/track_history_order_spec.rb
123
126
  - spec/integration/validation_failure_spec.rb
124
127
  - spec/spec_helper.rb
128
+ - spec/support/error_helpers.rb
125
129
  - spec/support/mongoid.rb
126
130
  - spec/support/mongoid_history.rb
127
131
  - spec/unit/attributes/base_spec.rb
@@ -142,7 +146,7 @@ homepage: http://github.com/mongoid/mongoid-history
142
146
  licenses:
143
147
  - MIT
144
148
  metadata: {}
145
- post_install_message:
149
+ post_install_message:
146
150
  rdoc_options: []
147
151
  require_paths:
148
152
  - lib
@@ -157,9 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
161
  - !ruby/object:Gem::Version
158
162
  version: '0'
159
163
  requirements: []
160
- rubyforge_project:
161
- rubygems_version: 2.6.13
162
- signing_key:
164
+ rubygems_version: 3.2.3
165
+ signing_key:
163
166
  specification_version: 4
164
167
  summary: Track and audit, undo and redo changes on Mongoid documents.
165
168
  test_files:
@@ -168,11 +171,13 @@ test_files:
168
171
  - spec/integration/multi_relation_spec.rb
169
172
  - spec/integration/multiple_trackers_spec.rb
170
173
  - spec/integration/nested_embedded_documents_spec.rb
174
+ - spec/integration/nested_embedded_documents_tracked_in_parent_spec.rb
171
175
  - spec/integration/nested_embedded_polymorphic_documents_spec.rb
172
176
  - spec/integration/subclasses_spec.rb
173
177
  - spec/integration/track_history_order_spec.rb
174
178
  - spec/integration/validation_failure_spec.rb
175
179
  - spec/spec_helper.rb
180
+ - spec/support/error_helpers.rb
176
181
  - spec/support/mongoid.rb
177
182
  - spec/support/mongoid_history.rb
178
183
  - spec/unit/attributes/base_spec.rb
data/.travis.yml DELETED
@@ -1,35 +0,0 @@
1
-
2
- sudo: false
3
-
4
- language: ruby
5
-
6
- cache: bundler
7
-
8
- services: mongodb
9
-
10
- env:
11
- - MONGOID_VERSION=3
12
- - MONGOID_VERSION=4
13
- - MONGOID_VERSION=5
14
- - MONGOID_VERSION=6
15
- - MONGOID_VERSION=HEAD
16
-
17
- rvm:
18
- - 2.3.1
19
-
20
- before_install:
21
- - gem update bundler
22
-
23
- before_script:
24
- - bundle exec danger
25
-
26
- addons:
27
- apt:
28
- sources:
29
- - mongodb-3.2-precise
30
- packages:
31
- - mongodb-org-server
32
-
33
- matrix:
34
- allow_failures:
35
- - env: MONGOID_VERSION=HEAD