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,190 +1,190 @@
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
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.3
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: 2020-06-17 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
@@ -125,6 +125,7 @@ files:
125
125
  - spec/integration/track_history_order_spec.rb
126
126
  - spec/integration/validation_failure_spec.rb
127
127
  - spec/spec_helper.rb
128
+ - spec/support/error_helpers.rb
128
129
  - spec/support/mongoid.rb
129
130
  - spec/support/mongoid_history.rb
130
131
  - spec/unit/attributes/base_spec.rb
@@ -145,7 +146,7 @@ homepage: http://github.com/mongoid/mongoid-history
145
146
  licenses:
146
147
  - MIT
147
148
  metadata: {}
148
- post_install_message:
149
+ post_install_message:
149
150
  rdoc_options: []
150
151
  require_paths:
151
152
  - lib
@@ -160,8 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
161
  - !ruby/object:Gem::Version
161
162
  version: '0'
162
163
  requirements: []
163
- rubygems_version: 3.1.3
164
- signing_key:
164
+ rubygems_version: 3.2.3
165
+ signing_key:
165
166
  specification_version: 4
166
167
  summary: Track and audit, undo and redo changes on Mongoid documents.
167
168
  test_files:
@@ -176,6 +177,7 @@ test_files:
176
177
  - spec/integration/track_history_order_spec.rb
177
178
  - spec/integration/validation_failure_spec.rb
178
179
  - spec/spec_helper.rb
180
+ - spec/support/error_helpers.rb
179
181
  - spec/support/mongoid.rb
180
182
  - spec/support/mongoid_history.rb
181
183
  - spec/unit/attributes/base_spec.rb
data/.travis.yml DELETED
@@ -1,36 +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=7
16
- - MONGOID_VERSION=HEAD
17
-
18
- rvm:
19
- - 2.3
20
-
21
- before_install:
22
- - gem update bundler
23
-
24
- before_script:
25
- - bundle exec danger
26
-
27
- addons:
28
- apt:
29
- sources:
30
- - mongodb-3.2-precise
31
- packages:
32
- - mongodb-org-server
33
-
34
- matrix:
35
- allow_failures:
36
- - env: MONGOID_VERSION=HEAD