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.
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,165 +1,165 @@
1
- require 'spec_helper'
2
-
3
- describe Mongoid::History::Options do
4
- describe ':if' do
5
- before :each do
6
- class DummyModel
7
- include Mongoid::Document
8
- include Mongoid::History::Trackable
9
-
10
- store_in collection: :model_ones
11
- field :foo
12
-
13
- attr_accessor :bar
14
-
15
- track_history modifier_field_optional: true, if: :bar
16
- end
17
- end
18
-
19
- after :each do
20
- Object.send(:remove_const, :DummyModel)
21
- end
22
-
23
- let(:obj) { DummyModel.new(foo: 'Foo') }
24
-
25
- context 'when condition evaluates to true' do
26
- before { obj.bar = true }
27
- it 'should create history tracks' do
28
- expect { obj.save }.to change(Tracker, :count).by(1)
29
- expect do
30
- obj.update_attributes(foo: 'Foo-2')
31
- end.to change(Tracker, :count).by(1)
32
- expect { obj.destroy }.to change(Tracker, :count).by(1)
33
- end
34
- end
35
-
36
- context 'when condition evaluates to false' do
37
- before { obj.bar = false }
38
- it 'should not create history tracks' do
39
- expect { obj.save }.to_not change(Tracker, :count)
40
- expect do
41
- obj.update_attributes(foo: 'Foo-2')
42
- end.to_not change(Tracker, :count)
43
- expect { obj.destroy }.to_not change(Tracker, :count)
44
- end
45
- end
46
- end
47
-
48
- describe ':unless' do
49
- before :each do
50
- class DummyModel
51
- include Mongoid::Document
52
- include Mongoid::History::Trackable
53
-
54
- store_in collection: :model_ones
55
- field :foo
56
-
57
- attr_accessor :bar
58
-
59
- track_history modifier_field_optional: true, unless: ->(obj) { obj.bar }
60
- end
61
- end
62
-
63
- after :each do
64
- Object.send(:remove_const, :DummyModel)
65
- end
66
-
67
- let(:obj) { DummyModel.new(foo: 'Foo') }
68
-
69
- context 'when condition evaluates to true' do
70
- before { obj.bar = true }
71
- it 'should not create history tracks' do
72
- expect { obj.save }.to_not change(Tracker, :count)
73
- expect do
74
- obj.update_attributes(foo: 'Foo-2')
75
- end.to_not change(Tracker, :count)
76
- expect { obj.destroy }.to_not change(Tracker, :count)
77
- end
78
- end
79
-
80
- context 'when condition evaluates to false' do
81
- before { obj.bar = false }
82
- it 'should create history tracks' do
83
- expect { obj.save }.to change(Tracker, :count).by(1)
84
- expect do
85
- obj.update_attributes(foo: 'Foo-2')
86
- end.to change(Tracker, :count).by(1)
87
- expect { obj.destroy }.to change(Tracker, :count).by(1)
88
- end
89
- end
90
- end
91
-
92
- describe ':if and :unless' do
93
- before :each do
94
- class DummyModel
95
- include Mongoid::Document
96
- include Mongoid::History::Trackable
97
-
98
- store_in collection: :model_ones
99
- field :foo
100
-
101
- attr_accessor :bar, :baz
102
-
103
- track_history modifier_field_optional: true, if: :bar, unless: ->(obj) { obj.baz }
104
- end
105
- end
106
-
107
- after :each do
108
- Object.send(:remove_const, :DummyModel)
109
- end
110
-
111
- let(:obj) { DummyModel.new(foo: 'Foo') }
112
-
113
- context 'when :if condition evaluates to true' do
114
- before { obj.bar = true }
115
-
116
- context 'and :unless condition evaluates to true' do
117
- before { obj.baz = true }
118
- it 'should not create history tracks' do
119
- expect { obj.save }.to_not change(Tracker, :count)
120
- expect do
121
- obj.update_attributes(foo: 'Foo-2')
122
- end.to_not change(Tracker, :count)
123
- expect { obj.destroy }.to_not change(Tracker, :count)
124
- end
125
- end
126
-
127
- context 'and :unless condition evaluates to false' do
128
- before { obj.baz = false }
129
- it 'should create history tracks' do
130
- expect { obj.save }.to change(Tracker, :count).by(1)
131
- expect do
132
- obj.update_attributes(foo: 'Foo-2')
133
- end.to change(Tracker, :count).by(1)
134
- expect { obj.destroy }.to change(Tracker, :count).by(1)
135
- end
136
- end
137
- end
138
-
139
- context 'when :if condition evaluates to false' do
140
- before { obj.bar = false }
141
-
142
- context 'and :unless condition evaluates to true' do
143
- before { obj.baz = true }
144
- it 'should not create history tracks' do
145
- expect { obj.save }.to_not change(Tracker, :count)
146
- expect do
147
- obj.update_attributes(foo: 'Foo-2')
148
- end.to_not change(Tracker, :count)
149
- expect { obj.destroy }.to_not change(Tracker, :count)
150
- end
151
- end
152
-
153
- context 'and :unless condition evaluates to false' do
154
- before { obj.baz = false }
155
- it 'should not create history tracks' do
156
- expect { obj.save }.to_not change(Tracker, :count)
157
- expect do
158
- obj.update_attributes(foo: 'Foo-2')
159
- end.to_not change(Tracker, :count)
160
- expect { obj.destroy }.to_not change(Tracker, :count)
161
- end
162
- end
163
- end
164
- end
165
- end
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid::History::Options do
4
+ describe ':if' do
5
+ before :each do
6
+ class DummyModel
7
+ include Mongoid::Document
8
+ include Mongoid::History::Trackable
9
+
10
+ store_in collection: :model_ones
11
+ field :foo
12
+
13
+ attr_accessor :bar
14
+
15
+ track_history modifier_field_optional: true, if: :bar
16
+ end
17
+ end
18
+
19
+ after :each do
20
+ Object.send(:remove_const, :DummyModel)
21
+ end
22
+
23
+ let(:obj) { DummyModel.new(foo: 'Foo') }
24
+
25
+ context 'when condition evaluates to true' do
26
+ before { obj.bar = true }
27
+ it 'should create history tracks' do
28
+ expect { obj.save }.to change(Tracker, :count).by(1)
29
+ expect do
30
+ obj.update_attributes(foo: 'Foo-2')
31
+ end.to change(Tracker, :count).by(1)
32
+ expect { obj.destroy }.to change(Tracker, :count).by(1)
33
+ end
34
+ end
35
+
36
+ context 'when condition evaluates to false' do
37
+ before { obj.bar = false }
38
+ it 'should not create history tracks' do
39
+ expect { obj.save }.to_not change(Tracker, :count)
40
+ expect do
41
+ obj.update_attributes(foo: 'Foo-2')
42
+ end.to_not change(Tracker, :count)
43
+ expect { obj.destroy }.to_not change(Tracker, :count)
44
+ end
45
+ end
46
+ end
47
+
48
+ describe ':unless' do
49
+ before :each do
50
+ class DummyModel
51
+ include Mongoid::Document
52
+ include Mongoid::History::Trackable
53
+
54
+ store_in collection: :model_ones
55
+ field :foo
56
+
57
+ attr_accessor :bar
58
+
59
+ track_history modifier_field_optional: true, unless: ->(obj) { obj.bar }
60
+ end
61
+ end
62
+
63
+ after :each do
64
+ Object.send(:remove_const, :DummyModel)
65
+ end
66
+
67
+ let(:obj) { DummyModel.new(foo: 'Foo') }
68
+
69
+ context 'when condition evaluates to true' do
70
+ before { obj.bar = true }
71
+ it 'should not create history tracks' do
72
+ expect { obj.save }.to_not change(Tracker, :count)
73
+ expect do
74
+ obj.update_attributes(foo: 'Foo-2')
75
+ end.to_not change(Tracker, :count)
76
+ expect { obj.destroy }.to_not change(Tracker, :count)
77
+ end
78
+ end
79
+
80
+ context 'when condition evaluates to false' do
81
+ before { obj.bar = false }
82
+ it 'should create history tracks' do
83
+ expect { obj.save }.to change(Tracker, :count).by(1)
84
+ expect do
85
+ obj.update_attributes(foo: 'Foo-2')
86
+ end.to change(Tracker, :count).by(1)
87
+ expect { obj.destroy }.to change(Tracker, :count).by(1)
88
+ end
89
+ end
90
+ end
91
+
92
+ describe ':if and :unless' do
93
+ before :each do
94
+ class DummyModel
95
+ include Mongoid::Document
96
+ include Mongoid::History::Trackable
97
+
98
+ store_in collection: :model_ones
99
+ field :foo
100
+
101
+ attr_accessor :bar, :baz
102
+
103
+ track_history modifier_field_optional: true, if: :bar, unless: ->(obj) { obj.baz }
104
+ end
105
+ end
106
+
107
+ after :each do
108
+ Object.send(:remove_const, :DummyModel)
109
+ end
110
+
111
+ let(:obj) { DummyModel.new(foo: 'Foo') }
112
+
113
+ context 'when :if condition evaluates to true' do
114
+ before { obj.bar = true }
115
+
116
+ context 'and :unless condition evaluates to true' do
117
+ before { obj.baz = true }
118
+ it 'should not create history tracks' do
119
+ expect { obj.save }.to_not change(Tracker, :count)
120
+ expect do
121
+ obj.update_attributes(foo: 'Foo-2')
122
+ end.to_not change(Tracker, :count)
123
+ expect { obj.destroy }.to_not change(Tracker, :count)
124
+ end
125
+ end
126
+
127
+ context 'and :unless condition evaluates to false' do
128
+ before { obj.baz = false }
129
+ it 'should create history tracks' do
130
+ expect { obj.save }.to change(Tracker, :count).by(1)
131
+ expect do
132
+ obj.update_attributes(foo: 'Foo-2')
133
+ end.to change(Tracker, :count).by(1)
134
+ expect { obj.destroy }.to change(Tracker, :count).by(1)
135
+ end
136
+ end
137
+ end
138
+
139
+ context 'when :if condition evaluates to false' do
140
+ before { obj.bar = false }
141
+
142
+ context 'and :unless condition evaluates to true' do
143
+ before { obj.baz = true }
144
+ it 'should not create history tracks' do
145
+ expect { obj.save }.to_not change(Tracker, :count)
146
+ expect do
147
+ obj.update_attributes(foo: 'Foo-2')
148
+ end.to_not change(Tracker, :count)
149
+ expect { obj.destroy }.to_not change(Tracker, :count)
150
+ end
151
+ end
152
+
153
+ context 'and :unless condition evaluates to false' do
154
+ before { obj.baz = false }
155
+ it 'should not create history tracks' do
156
+ expect { obj.save }.to_not change(Tracker, :count)
157
+ expect do
158
+ obj.update_attributes(foo: 'Foo-2')
159
+ end.to_not change(Tracker, :count)
160
+ expect { obj.destroy }.to_not change(Tracker, :count)
161
+ end
162
+ end
163
+ end
164
+ end
165
+ end
@@ -1,87 +1,87 @@
1
- require 'spec_helper'
2
-
3
- describe Mongoid::History::Trackable do
4
- describe 'EmbeddedMethods' do
5
- describe 'relation_class_of' do
6
- before :each do
7
- class ModelOne
8
- include Mongoid::Document
9
- include Mongoid::History::Trackable
10
-
11
- if Mongoid::Compatibility::Version.mongoid7_or_newer?
12
- embeds_one :emb_one
13
- embeds_one :emb_two, store_as: 'emt'
14
- else
15
- embeds_one :emb_one, inverse_class_name: 'EmbOne'
16
- embeds_one :emb_two, store_as: 'emt', inverse_class_name: 'EmbTwo'
17
- end
18
-
19
- track_history
20
- end
21
-
22
- class EmbOne
23
- include Mongoid::Document
24
-
25
- embedded_in :model_one
26
- end
27
-
28
- class EmbTwo
29
- include Mongoid::Document
30
-
31
- embedded_in :model_one
32
- end
33
- end
34
-
35
- after :each do
36
- Object.send(:remove_const, :ModelOne)
37
- Object.send(:remove_const, :EmbOne)
38
- Object.send(:remove_const, :EmbTwo)
39
- end
40
-
41
- it { expect(ModelOne.relation_class_of('emb_one')).to eq EmbOne }
42
- it { expect(ModelOne.relation_class_of('emt')).to eq EmbTwo }
43
- it { expect(ModelOne.relation_class_of('invalid')).to be_nil }
44
- end
45
-
46
- describe 'relation_class_of' do
47
- before :each do
48
- class ModelOne
49
- include Mongoid::Document
50
- include Mongoid::History::Trackable
51
-
52
- if Mongoid::Compatibility::Version.mongoid7_or_newer?
53
- embeds_many :emb_ones
54
- embeds_many :emb_twos, store_as: 'emts'
55
- else
56
- embeds_many :emb_ones, inverse_class_name: 'EmbOne'
57
- embeds_many :emb_twos, store_as: 'emts', inverse_class_name: 'EmbTwo'
58
- end
59
-
60
- track_history
61
- end
62
-
63
- class EmbOne
64
- include Mongoid::Document
65
-
66
- embedded_in :model_one
67
- end
68
-
69
- class EmbTwo
70
- include Mongoid::Document
71
-
72
- embedded_in :model_one
73
- end
74
- end
75
-
76
- after :each do
77
- Object.send(:remove_const, :ModelOne)
78
- Object.send(:remove_const, :EmbOne)
79
- Object.send(:remove_const, :EmbTwo)
80
- end
81
-
82
- it { expect(ModelOne.relation_class_of('emb_ones')).to eq EmbOne }
83
- it { expect(ModelOne.relation_class_of('emts')).to eq EmbTwo }
84
- it { expect(ModelOne.relation_class_of('invalid')).to be_nil }
85
- end
86
- end
87
- end
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid::History::Trackable do
4
+ describe 'EmbeddedMethods' do
5
+ describe 'relation_class_of' do
6
+ before :each do
7
+ class ModelOne
8
+ include Mongoid::Document
9
+ include Mongoid::History::Trackable
10
+
11
+ if Mongoid::Compatibility::Version.mongoid7_or_newer?
12
+ embeds_one :emb_one
13
+ embeds_one :emb_two, store_as: 'emt'
14
+ else
15
+ embeds_one :emb_one, inverse_class_name: 'EmbOne'
16
+ embeds_one :emb_two, store_as: 'emt', inverse_class_name: 'EmbTwo'
17
+ end
18
+
19
+ track_history
20
+ end
21
+
22
+ class EmbOne
23
+ include Mongoid::Document
24
+
25
+ embedded_in :model_one
26
+ end
27
+
28
+ class EmbTwo
29
+ include Mongoid::Document
30
+
31
+ embedded_in :model_one
32
+ end
33
+ end
34
+
35
+ after :each do
36
+ Object.send(:remove_const, :ModelOne)
37
+ Object.send(:remove_const, :EmbOne)
38
+ Object.send(:remove_const, :EmbTwo)
39
+ end
40
+
41
+ it { expect(ModelOne.relation_class_of('emb_one')).to eq EmbOne }
42
+ it { expect(ModelOne.relation_class_of('emt')).to eq EmbTwo }
43
+ it { expect(ModelOne.relation_class_of('invalid')).to be_nil }
44
+ end
45
+
46
+ describe 'relation_class_of' do
47
+ before :each do
48
+ class ModelOne
49
+ include Mongoid::Document
50
+ include Mongoid::History::Trackable
51
+
52
+ if Mongoid::Compatibility::Version.mongoid7_or_newer?
53
+ embeds_many :emb_ones
54
+ embeds_many :emb_twos, store_as: 'emts'
55
+ else
56
+ embeds_many :emb_ones, inverse_class_name: 'EmbOne'
57
+ embeds_many :emb_twos, store_as: 'emts', inverse_class_name: 'EmbTwo'
58
+ end
59
+
60
+ track_history
61
+ end
62
+
63
+ class EmbOne
64
+ include Mongoid::Document
65
+
66
+ embedded_in :model_one
67
+ end
68
+
69
+ class EmbTwo
70
+ include Mongoid::Document
71
+
72
+ embedded_in :model_one
73
+ end
74
+ end
75
+
76
+ after :each do
77
+ Object.send(:remove_const, :ModelOne)
78
+ Object.send(:remove_const, :EmbOne)
79
+ Object.send(:remove_const, :EmbTwo)
80
+ end
81
+
82
+ it { expect(ModelOne.relation_class_of('emb_ones')).to eq EmbOne }
83
+ it { expect(ModelOne.relation_class_of('emts')).to eq EmbTwo }
84
+ it { expect(ModelOne.relation_class_of('invalid')).to be_nil }
85
+ end
86
+ end
87
+ end
@@ -1,58 +1,58 @@
1
- require 'spec_helper'
2
-
3
- describe Mongoid::History do
4
- it { is_expected.to respond_to(:trackable_settings) }
5
- it { is_expected.to respond_to(:trackable_settings=) }
6
-
7
- describe '#default_settings' do
8
- let(:default_settings) { { paranoia_field: 'deleted_at' } }
9
- it { expect(described_class.default_settings).to eq(default_settings) }
10
- end
11
-
12
- describe '#trackable_class_settings' do
13
- before :each do
14
- class ModelOne
15
- include Mongoid::Document
16
- include Mongoid::History::Trackable
17
-
18
- store_in collection: :model_ones
19
- end
20
- end
21
-
22
- after :each do
23
- Object.send(:remove_const, :ModelOne)
24
- end
25
-
26
- context 'when present' do
27
- before :each do
28
- ModelOne.history_settings paranoia_field: :annuled_at
29
- end
30
- it { expect(described_class.trackable_class_settings(ModelOne)).to eq(paranoia_field: 'annuled_at') }
31
- end
32
-
33
- context 'when not present' do
34
- it { expect(described_class.trackable_class_settings(ModelOne)).to eq(paranoia_field: 'deleted_at') }
35
- end
36
- end
37
-
38
- describe '#reset!' do
39
- before :each do
40
- class ModelTwo
41
- include Mongoid::Document
42
- include Mongoid::History::Trackable
43
-
44
- track_history
45
- end
46
- end
47
-
48
- after :each do
49
- Object.send(:remove_const, :ModelTwo)
50
- end
51
-
52
- it 'should remove all configurations' do
53
- expect(ModelTwo).to have_attributes mongoid_history_options: be_a(Mongoid::History::Options)
54
- Mongoid::History.reset!
55
- expect(ModelTwo).to_not respond_to :mongoid_history_options
56
- end
57
- end
58
- end
1
+ require 'spec_helper'
2
+
3
+ describe Mongoid::History do
4
+ it { is_expected.to respond_to(:trackable_settings) }
5
+ it { is_expected.to respond_to(:trackable_settings=) }
6
+
7
+ describe '#default_settings' do
8
+ let(:default_settings) { { paranoia_field: 'deleted_at' } }
9
+ it { expect(described_class.default_settings).to eq(default_settings) }
10
+ end
11
+
12
+ describe '#trackable_class_settings' do
13
+ before :each do
14
+ class ModelOne
15
+ include Mongoid::Document
16
+ include Mongoid::History::Trackable
17
+
18
+ store_in collection: :model_ones
19
+ end
20
+ end
21
+
22
+ after :each do
23
+ Object.send(:remove_const, :ModelOne)
24
+ end
25
+
26
+ context 'when present' do
27
+ before :each do
28
+ ModelOne.history_settings paranoia_field: :annuled_at
29
+ end
30
+ it { expect(described_class.trackable_class_settings(ModelOne)).to eq(paranoia_field: 'annuled_at') }
31
+ end
32
+
33
+ context 'when not present' do
34
+ it { expect(described_class.trackable_class_settings(ModelOne)).to eq(paranoia_field: 'deleted_at') }
35
+ end
36
+ end
37
+
38
+ describe '#reset!' do
39
+ before :each do
40
+ class ModelTwo
41
+ include Mongoid::Document
42
+ include Mongoid::History::Trackable
43
+
44
+ track_history
45
+ end
46
+ end
47
+
48
+ after :each do
49
+ Object.send(:remove_const, :ModelTwo)
50
+ end
51
+
52
+ it 'should remove all configurations' do
53
+ expect(ModelTwo).to have_attributes mongoid_history_options: be_a(Mongoid::History::Options)
54
+ Mongoid::History.reset!
55
+ expect(ModelTwo).to_not respond_to :mongoid_history_options
56
+ end
57
+ end
58
+ end