mongoid-history 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +47 -38
- data/CHANGELOG.md +5 -0
- data/Gemfile +6 -5
- data/README.md +53 -2
- data/RELEASING.md +68 -0
- data/Rakefile +1 -1
- data/UPGRADING.md +9 -0
- data/lib/mongoid/history.rb +1 -1
- data/lib/mongoid/history/attributes/create.rb +2 -2
- data/lib/mongoid/history/attributes/destroy.rb +9 -9
- data/lib/mongoid/history/attributes/update.rb +2 -2
- data/lib/mongoid/history/options.rb +4 -4
- data/lib/mongoid/history/trackable.rb +27 -16
- data/lib/mongoid/history/tracker.rb +8 -6
- data/lib/mongoid/history/version.rb +1 -1
- data/spec/integration/embedded_in_polymorphic_spec.rb +1 -1
- data/spec/integration/integration_spec.rb +10 -10
- data/spec/integration/multi_relation_spec.rb +1 -1
- data/spec/integration/multiple_trackers_spec.rb +71 -0
- data/spec/integration/nested_embedded_polymorphic_documents_spec.rb +2 -2
- data/spec/integration/validation_failure_spec.rb +63 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/unit/attributes/base_spec.rb +3 -3
- data/spec/unit/my_instance_methods_spec.rb +1 -1
- data/spec/unit/options_spec.rb +52 -52
- data/spec/unit/singleton_methods_spec.rb +13 -13
- data/spec/unit/trackable_spec.rb +66 -7
- metadata +9 -3
@@ -31,7 +31,7 @@ describe Mongoid::History::Trackable do
|
|
31
31
|
embedded_in :my_trackable_model
|
32
32
|
end
|
33
33
|
|
34
|
-
MyTrackableModel.track_history(on: [
|
34
|
+
MyTrackableModel.track_history(on: %i[foo my_embed_one_model my_embed_many_models my_dynamic_field])
|
35
35
|
end
|
36
36
|
|
37
37
|
describe '#tracked?' do
|
@@ -143,7 +143,7 @@ describe Mongoid::History::Trackable do
|
|
143
143
|
|
144
144
|
describe '#tracked_fields' do
|
145
145
|
it 'should include fields and dynamic fields' do
|
146
|
-
expect(MyTrackableModel.tracked_fields).to eq %w
|
146
|
+
expect(MyTrackableModel.tracked_fields).to eq %w[foo my_dynamic_field]
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
@@ -199,17 +199,17 @@ describe Mongoid::History::Trackable do
|
|
199
199
|
|
200
200
|
context 'when relation tracked' do
|
201
201
|
before(:each) { ModelOne.track_history(on: :emb_one) }
|
202
|
-
it { expect(ModelOne.tracked_embeds_one_attributes('emb_one')).to eq %w
|
202
|
+
it { expect(ModelOne.tracked_embeds_one_attributes('emb_one')).to eq %w[_id em_foo em_bar] }
|
203
203
|
end
|
204
204
|
|
205
205
|
context 'when relation tracked with alias' do
|
206
206
|
before(:each) { ModelOne.track_history(on: :emb_two) }
|
207
|
-
it { expect(ModelOne.tracked_embeds_one_attributes('emb_two')).to eq %w
|
207
|
+
it { expect(ModelOne.tracked_embeds_one_attributes('emb_two')).to eq %w[_id em_bar] }
|
208
208
|
end
|
209
209
|
|
210
210
|
context 'when relation tracked with attributes' do
|
211
211
|
before(:each) { ModelOne.track_history(on: { emb_one: :em_foo }) }
|
212
|
-
it { expect(ModelOne.tracked_embeds_one_attributes('emb_one')).to eq %w
|
212
|
+
it { expect(ModelOne.tracked_embeds_one_attributes('emb_one')).to eq %w[_id em_foo] }
|
213
213
|
end
|
214
214
|
|
215
215
|
context 'when relation not tracked' do
|
@@ -268,17 +268,17 @@ describe Mongoid::History::Trackable do
|
|
268
268
|
|
269
269
|
context 'when relation tracked' do
|
270
270
|
before(:each) { ModelOne.track_history(on: :emb_ones) }
|
271
|
-
it { expect(ModelOne.tracked_embeds_many_attributes('emb_ones')).to eq %w
|
271
|
+
it { expect(ModelOne.tracked_embeds_many_attributes('emb_ones')).to eq %w[_id em_foo em_bar] }
|
272
272
|
end
|
273
273
|
|
274
274
|
context 'when relation tracked with alias' do
|
275
275
|
before(:each) { ModelOne.track_history(on: :emb_twos) }
|
276
|
-
it { expect(ModelOne.tracked_embeds_many_attributes('emb_twos')).to eq %w
|
276
|
+
it { expect(ModelOne.tracked_embeds_many_attributes('emb_twos')).to eq %w[_id em_bar] }
|
277
277
|
end
|
278
278
|
|
279
279
|
context 'when relation tracked with attributes' do
|
280
280
|
before(:each) { ModelOne.track_history(on: { emb_ones: :em_foo }) }
|
281
|
-
it { expect(ModelOne.tracked_embeds_many_attributes('emb_ones')).to eq %w
|
281
|
+
it { expect(ModelOne.tracked_embeds_many_attributes('emb_ones')).to eq %w[_id em_foo] }
|
282
282
|
end
|
283
283
|
|
284
284
|
context 'when relation not tracked' do
|
@@ -309,12 +309,12 @@ describe Mongoid::History::Trackable do
|
|
309
309
|
|
310
310
|
describe '#clear_trackable_memoization' do
|
311
311
|
before do
|
312
|
-
MyTrackableModel.instance_variable_set(:@reserved_tracked_fields, %w
|
313
|
-
MyTrackableModel.instance_variable_set(:@history_trackable_options, on: %w
|
312
|
+
MyTrackableModel.instance_variable_set(:@reserved_tracked_fields, %w[_id _type])
|
313
|
+
MyTrackableModel.instance_variable_set(:@history_trackable_options, on: %w[fields])
|
314
314
|
MyTrackableModel.instance_variable_set(:@trackable_settings, paranoia_field: 'deleted_at')
|
315
|
-
MyTrackableModel.instance_variable_set(:@tracked_fields, %w
|
316
|
-
MyTrackableModel.instance_variable_set(:@tracked_embeds_one, %w
|
317
|
-
MyTrackableModel.instance_variable_set(:@tracked_embeds_many, %w
|
315
|
+
MyTrackableModel.instance_variable_set(:@tracked_fields, %w[foo])
|
316
|
+
MyTrackableModel.instance_variable_set(:@tracked_embeds_one, %w[my_embed_one_model])
|
317
|
+
MyTrackableModel.instance_variable_set(:@tracked_embeds_many, %w[my_embed_many_models])
|
318
318
|
MyTrackableModel.clear_trackable_memoization
|
319
319
|
end
|
320
320
|
|
data/spec/unit/trackable_spec.rb
CHANGED
@@ -34,8 +34,8 @@ describe Mongoid::History::Trackable do
|
|
34
34
|
end
|
35
35
|
before(:each) { Mongoid::History.trackable_class_options = @persisted_history_options }
|
36
36
|
let(:expected_option) do
|
37
|
-
{ on: %i
|
38
|
-
except: %w
|
37
|
+
{ on: %i[foo],
|
38
|
+
except: %w[created_at updated_at],
|
39
39
|
tracker_class_name: nil,
|
40
40
|
modifier_field: :modifier,
|
41
41
|
version_field: :version,
|
@@ -44,13 +44,13 @@ describe Mongoid::History::Trackable do
|
|
44
44
|
track_create: false,
|
45
45
|
track_update: true,
|
46
46
|
track_destroy: false,
|
47
|
-
fields: %w
|
47
|
+
fields: %w[foo],
|
48
48
|
relations: { embeds_one: {}, embeds_many: {} },
|
49
49
|
dynamic: [],
|
50
50
|
format: {} }
|
51
51
|
end
|
52
52
|
let(:regular_fields) { ['foo'] }
|
53
|
-
let(:reserved_fields) { %w
|
53
|
+
let(:reserved_fields) { %w[_id version modifier_id] }
|
54
54
|
|
55
55
|
it 'should have default options' do
|
56
56
|
expect(Mongoid::History.trackable_class_options[:my_model]).to eq(expected_option)
|
@@ -217,7 +217,7 @@ describe Mongoid::History::Trackable do
|
|
217
217
|
it 'should be rescued if an exception occurs' do
|
218
218
|
begin
|
219
219
|
MyModel.disable_tracking do
|
220
|
-
|
220
|
+
raise 'exception'
|
221
221
|
end
|
222
222
|
rescue
|
223
223
|
end
|
@@ -260,7 +260,7 @@ describe Mongoid::History::Trackable do
|
|
260
260
|
Mongoid::History.disable do
|
261
261
|
begin
|
262
262
|
MyModel.disable_tracking do
|
263
|
-
|
263
|
+
raise 'exception'
|
264
264
|
end
|
265
265
|
rescue
|
266
266
|
end
|
@@ -289,7 +289,7 @@ describe Mongoid::History::Trackable do
|
|
289
289
|
begin
|
290
290
|
Mongoid::History.disable do
|
291
291
|
MyModel.disable_tracking do
|
292
|
-
|
292
|
+
raise 'exception'
|
293
293
|
end
|
294
294
|
end
|
295
295
|
rescue
|
@@ -583,4 +583,63 @@ describe Mongoid::History::Trackable do
|
|
583
583
|
Object.send(:remove_const, :MyTrackerClass)
|
584
584
|
end
|
585
585
|
end
|
586
|
+
|
587
|
+
describe '#track_update' do
|
588
|
+
before :all do
|
589
|
+
MyModel.track_history(on: :foo, track_update: true)
|
590
|
+
@persisted_history_options = Mongoid::History.trackable_class_options
|
591
|
+
end
|
592
|
+
before(:each) { Mongoid::History.trackable_class_options = @persisted_history_options }
|
593
|
+
let(:m) { MyModel.create!(foo: 'bar') }
|
594
|
+
|
595
|
+
it 'should create history' do
|
596
|
+
expect { m.update_attributes!(foo: 'bar2') }.to change(Tracker, :count).by(1)
|
597
|
+
end
|
598
|
+
|
599
|
+
it 'should not create history when error raised' do
|
600
|
+
expect(m).to receive(:update_attributes!).and_raise(StandardError)
|
601
|
+
expect do
|
602
|
+
expect { m.update_attributes!(foo: 'bar2') }.to raise_error(StandardError)
|
603
|
+
end.to change(Tracker, :count).by(0)
|
604
|
+
end
|
605
|
+
end
|
606
|
+
|
607
|
+
describe '#track_destroy' do
|
608
|
+
before :all do
|
609
|
+
MyModel.track_history(on: :foo, track_destroy: true)
|
610
|
+
@persisted_history_options = Mongoid::History.trackable_class_options
|
611
|
+
end
|
612
|
+
before(:each) { Mongoid::History.trackable_class_options = @persisted_history_options }
|
613
|
+
let(:m) { MyModel.create!(foo: 'bar') }
|
614
|
+
|
615
|
+
it 'should create history' do
|
616
|
+
expect { m.destroy }.to change(Tracker, :count).by(1)
|
617
|
+
end
|
618
|
+
|
619
|
+
it 'should not create history when error raised' do
|
620
|
+
expect(m).to receive(:destroy).and_raise(StandardError)
|
621
|
+
expect do
|
622
|
+
expect { m.destroy }.to raise_error(StandardError)
|
623
|
+
end.to change(Tracker, :count).by(0)
|
624
|
+
end
|
625
|
+
end
|
626
|
+
|
627
|
+
describe '#track_create' do
|
628
|
+
before :all do
|
629
|
+
MyModel.track_history(on: :foo, track_create: true)
|
630
|
+
@persisted_history_options = Mongoid::History.trackable_class_options
|
631
|
+
end
|
632
|
+
before(:each) { Mongoid::History.trackable_class_options = @persisted_history_options }
|
633
|
+
|
634
|
+
it 'should create history' do
|
635
|
+
expect { MyModel.create!(foo: 'bar') }.to change(Tracker, :count).by(1)
|
636
|
+
end
|
637
|
+
|
638
|
+
it 'should not create history when error raised' do
|
639
|
+
expect(MyModel).to receive(:create!).and_raise(StandardError)
|
640
|
+
expect do
|
641
|
+
expect { MyModel.create!(foo: 'bar') }.to raise_error(StandardError)
|
642
|
+
end.to change(Tracker, :count).by(0)
|
643
|
+
end
|
644
|
+
end
|
586
645
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-history
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Qian
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: easy_diff
|
@@ -98,7 +98,9 @@ files:
|
|
98
98
|
- Gemfile
|
99
99
|
- LICENSE.txt
|
100
100
|
- README.md
|
101
|
+
- RELEASING.md
|
101
102
|
- Rakefile
|
103
|
+
- UPGRADING.md
|
102
104
|
- lib/mongoid-history.rb
|
103
105
|
- lib/mongoid/history.rb
|
104
106
|
- lib/mongoid/history/attributes/base.rb
|
@@ -113,9 +115,11 @@ files:
|
|
113
115
|
- spec/integration/embedded_in_polymorphic_spec.rb
|
114
116
|
- spec/integration/integration_spec.rb
|
115
117
|
- spec/integration/multi_relation_spec.rb
|
118
|
+
- spec/integration/multiple_trackers_spec.rb
|
116
119
|
- spec/integration/nested_embedded_documents_spec.rb
|
117
120
|
- spec/integration/nested_embedded_polymorphic_documents_spec.rb
|
118
121
|
- spec/integration/subclasses_spec.rb
|
122
|
+
- spec/integration/validation_failure_spec.rb
|
119
123
|
- spec/spec_helper.rb
|
120
124
|
- spec/support/mongoid.rb
|
121
125
|
- spec/support/mongoid_history.rb
|
@@ -152,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
156
|
version: '0'
|
153
157
|
requirements: []
|
154
158
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
159
|
+
rubygems_version: 2.6.12
|
156
160
|
signing_key:
|
157
161
|
specification_version: 4
|
158
162
|
summary: Track and audit, undo and redo changes on Mongoid documents.
|
@@ -160,9 +164,11 @@ test_files:
|
|
160
164
|
- spec/integration/embedded_in_polymorphic_spec.rb
|
161
165
|
- spec/integration/integration_spec.rb
|
162
166
|
- spec/integration/multi_relation_spec.rb
|
167
|
+
- spec/integration/multiple_trackers_spec.rb
|
163
168
|
- spec/integration/nested_embedded_documents_spec.rb
|
164
169
|
- spec/integration/nested_embedded_polymorphic_documents_spec.rb
|
165
170
|
- spec/integration/subclasses_spec.rb
|
171
|
+
- spec/integration/validation_failure_spec.rb
|
166
172
|
- spec/spec_helper.rb
|
167
173
|
- spec/support/mongoid.rb
|
168
174
|
- spec/support/mongoid_history.rb
|