mongoid-history 0.6.1 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop_todo.yml +50 -43
- data/.travis.yml +2 -1
- data/CHANGELOG.md +33 -0
- data/CONTRIBUTING.md +4 -4
- data/Gemfile +16 -11
- data/LICENSE.txt +1 -1
- data/README.md +97 -20
- data/RELEASING.md +67 -0
- data/Rakefile +1 -1
- data/UPGRADING.md +53 -0
- data/lib/mongoid/history.rb +33 -8
- data/lib/mongoid/history/attributes/base.rb +2 -2
- data/lib/mongoid/history/attributes/create.rb +6 -11
- data/lib/mongoid/history/attributes/destroy.rb +9 -9
- data/lib/mongoid/history/attributes/update.rb +82 -21
- data/lib/mongoid/history/options.rb +60 -67
- data/lib/mongoid/history/trackable.rb +173 -91
- data/lib/mongoid/history/tracker.rb +22 -13
- data/lib/mongoid/history/version.rb +1 -1
- data/mongoid-history.gemspec +1 -1
- data/perf/benchmark_modified_attributes_for_create.rb +65 -0
- data/perf/gc_suite.rb +21 -0
- data/spec/integration/embedded_in_polymorphic_spec.rb +26 -49
- data/spec/integration/integration_spec.rb +186 -146
- data/spec/integration/multi_relation_spec.rb +14 -20
- data/spec/integration/multiple_trackers_spec.rb +68 -0
- data/spec/integration/nested_embedded_documents_spec.rb +31 -51
- data/spec/integration/nested_embedded_documents_tracked_in_parent_spec.rb +124 -0
- data/spec/integration/nested_embedded_polymorphic_documents_spec.rb +64 -76
- data/spec/integration/subclasses_spec.rb +24 -6
- data/spec/integration/track_history_order_spec.rb +84 -0
- data/spec/integration/validation_failure_spec.rb +76 -0
- data/spec/spec_helper.rb +6 -1
- data/spec/support/mongoid_history.rb +0 -1
- data/spec/unit/attributes/base_spec.rb +17 -26
- data/spec/unit/attributes/create_spec.rb +152 -125
- data/spec/unit/attributes/destroy_spec.rb +69 -59
- data/spec/unit/attributes/update_spec.rb +165 -33
- data/spec/unit/callback_options_spec.rb +165 -0
- data/spec/unit/embedded_methods_spec.rb +42 -24
- data/spec/unit/history_spec.rb +33 -10
- data/spec/unit/my_instance_methods_spec.rb +191 -121
- data/spec/unit/options_spec.rb +121 -82
- data/spec/unit/singleton_methods_spec.rb +168 -100
- data/spec/unit/trackable_spec.rb +549 -148
- data/spec/unit/tracker_spec.rb +81 -54
- metadata +19 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7f7558f1c6033e5350cdeb3732e385d483c7abfa71ffc7f89acfbba22befff97
|
4
|
+
data.tar.gz: 71c5f5ab67e1bd040e14b040211b1acc5532449f048919c83adcb4e875f7eac4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f528411205ca81444296803927b54c1bd1ef570611b2b4a9bb79f6e4165fb038c5b13ad5fb79c8adde96c62eaefa1142bf5f4c6b5f44d72a80743f38a0aa5d48
|
7
|
+
data.tar.gz: 4149122d3f6c474f5f0105772fa64a9fe237d299005e97ad021e887f42687d1a81ede778c589070231319704b9c71e2f99a5e660d04c2581a078178e965b0425
|
data/.rubocop_todo.yml
CHANGED
@@ -1,92 +1,99 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
3
|
+
# on 2020-04-10 17:25:32 -0500 using RuboCop version 0.48.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
+
# Offense count: 7
|
10
|
+
# Configuration parameters: Include.
|
11
|
+
# Include: **/Gemfile, **/gems.rb
|
12
|
+
Bundler/DuplicatedGem:
|
13
|
+
Exclude:
|
14
|
+
- 'Gemfile'
|
15
|
+
|
9
16
|
# Offense count: 3
|
10
17
|
Lint/HandleExceptions:
|
11
18
|
Exclude:
|
12
19
|
- 'spec/unit/trackable_spec.rb'
|
13
20
|
|
14
|
-
|
15
|
-
|
21
|
+
# Offense count: 3
|
22
|
+
Lint/ParenthesesAsGroupedExpression:
|
23
|
+
Exclude:
|
24
|
+
- 'spec/integration/integration_spec.rb'
|
25
|
+
- 'spec/integration/nested_embedded_polymorphic_documents_spec.rb'
|
16
26
|
|
17
|
-
# Offense count:
|
27
|
+
# Offense count: 22
|
18
28
|
Metrics/AbcSize:
|
19
|
-
Max:
|
29
|
+
Max: 52
|
30
|
+
|
31
|
+
# Offense count: 122
|
32
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
33
|
+
Metrics/BlockLength:
|
34
|
+
Max: 837
|
20
35
|
|
21
|
-
# Offense count:
|
36
|
+
# Offense count: 1
|
37
|
+
# Configuration parameters: CountComments.
|
38
|
+
Metrics/ClassLength:
|
39
|
+
Max: 120
|
40
|
+
|
41
|
+
# Offense count: 6
|
22
42
|
Metrics/CyclomaticComplexity:
|
23
|
-
Max:
|
43
|
+
Max: 13
|
24
44
|
|
25
|
-
# Offense count:
|
26
|
-
# Configuration parameters: AllowURI, URISchemes.
|
45
|
+
# Offense count: 412
|
46
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
47
|
+
# URISchemes: http, https
|
27
48
|
Metrics/LineLength:
|
28
49
|
Max: 688
|
29
50
|
|
30
|
-
# Offense count:
|
51
|
+
# Offense count: 17
|
31
52
|
# Configuration parameters: CountComments.
|
32
53
|
Metrics/MethodLength:
|
33
|
-
Max:
|
54
|
+
Max: 23
|
34
55
|
|
35
56
|
# Offense count: 2
|
36
57
|
# Configuration parameters: CountComments.
|
37
58
|
Metrics/ModuleLength:
|
38
|
-
Max:
|
59
|
+
Max: 191
|
39
60
|
|
40
|
-
# Offense count:
|
61
|
+
# Offense count: 6
|
41
62
|
Metrics/PerceivedComplexity:
|
42
|
-
Max:
|
63
|
+
Max: 15
|
43
64
|
|
44
|
-
# Offense count:
|
65
|
+
# Offense count: 15
|
45
66
|
Style/Documentation:
|
46
67
|
Exclude:
|
68
|
+
- 'spec/**/*'
|
69
|
+
- 'test/**/*'
|
47
70
|
- 'lib/mongoid/history.rb'
|
48
|
-
- 'lib/mongoid/history/options.rb'
|
49
|
-
- 'lib/mongoid/history/trackable.rb'
|
50
|
-
- 'lib/mongoid/history/tracker.rb'
|
51
|
-
- 'lib/mongoid/history/version.rb'
|
52
71
|
- 'lib/mongoid/history/attributes/base.rb'
|
53
72
|
- 'lib/mongoid/history/attributes/create.rb'
|
54
73
|
- 'lib/mongoid/history/attributes/destroy.rb'
|
55
74
|
- 'lib/mongoid/history/attributes/update.rb'
|
56
|
-
- '
|
57
|
-
- '
|
58
|
-
- '
|
59
|
-
- '
|
60
|
-
- '
|
61
|
-
- 'spec/integration/subclasses_spec.rb'
|
62
|
-
- 'spec/support/mongoid_history.rb'
|
63
|
-
- 'spec/unit/options_spec.rb'
|
64
|
-
- 'spec/unit/singleton_methods_spec.rb'
|
65
|
-
- 'spec/unit/trackable_spec.rb'
|
66
|
-
- 'spec/unit/tracker_spec.rb'
|
67
|
-
- 'spec/unit/attributes/base_spec.rb'
|
68
|
-
- 'spec/unit/attributes/create_spec.rb'
|
69
|
-
- 'spec/unit/attributes/destroy_spec.rb'
|
70
|
-
- 'spec/unit/attributes/update_spec.rb'
|
75
|
+
- 'lib/mongoid/history/options.rb'
|
76
|
+
- 'lib/mongoid/history/trackable.rb'
|
77
|
+
- 'lib/mongoid/history/tracker.rb'
|
78
|
+
- 'perf/benchmark_modified_attributes_for_create.rb'
|
79
|
+
- 'perf/gc_suite.rb'
|
71
80
|
|
72
|
-
# Offense count:
|
81
|
+
# Offense count: 3
|
82
|
+
# Cop supports --auto-correct.
|
73
83
|
Style/EachWithObject:
|
74
84
|
Exclude:
|
75
85
|
- 'lib/mongoid/history/trackable.rb'
|
76
86
|
- 'lib/mongoid/history/tracker.rb'
|
77
87
|
|
78
|
-
# Offense count:
|
79
|
-
# Configuration parameters:
|
88
|
+
# Offense count: 2
|
89
|
+
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms.
|
90
|
+
# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS
|
80
91
|
Style/FileName:
|
81
92
|
Exclude:
|
93
|
+
- 'Dangerfile'
|
82
94
|
- 'lib/mongoid-history.rb'
|
83
95
|
|
84
|
-
# Offense count:
|
96
|
+
# Offense count: 1
|
85
97
|
Style/MultilineBlockChain:
|
86
98
|
Exclude:
|
87
|
-
- 'lib/mongoid/history/trackable.rb'
|
88
99
|
- 'lib/mongoid/history/tracker.rb'
|
89
|
-
|
90
|
-
Style/ClassLength:
|
91
|
-
Exclude:
|
92
|
-
- 'lib/mongoid/history/options.rb'
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
### 0.8.3 (2020/05/17)
|
2
|
+
|
3
|
+
* [#236](https://github.com/mongoid/mongoid-history/pull/236): Fix Ruby 2.7 keyword argument warnings - [@vasilysn](https://github.com/vasilysn).
|
4
|
+
* [#237](https://github.com/mongoid/mongoid-history/pull/237): Fix tracking subclasses with additional fields - [@getaroom](https://github.com/getaroom).
|
5
|
+
* [#239](https://github.com/mongoid/mongoid-history/pull/239): Optimize `modified_attributes_for_create` 6-7x - [@getaroom](https://github.com/getaroom).
|
6
|
+
* [#240](https://github.com/mongoid/mongoid-history/pull/240): `Mongoid::History.disable` and `disable_tracking` now restore the original state - [@getaroom](https://github.com/getaroom).
|
7
|
+
* [#240](https://github.com/mongoid/mongoid-history/pull/240): Added `Mongoid::History.enable`, `Mongoid::History.enable!`, `Mongoid::History.disable!`, `enable_tracking`, `enable_tracking!`, and `disable_tracking!` - [@getaroom](https://github.com/getaroom).
|
8
|
+
|
9
|
+
### 0.8.2 (2019/12/02)
|
10
|
+
|
11
|
+
* [#233](https://github.com/mongoid/mongoid-history/pull/233): Bug fix-Track ALL embedded relations when used with fields and filtered attributes on embedded objects - [@jagdeepsingh](https://github.com/jagdeepsingh).
|
12
|
+
* [#232](https://github.com/mongoid/mongoid-history/pull/232): Bug/187 track changes from embedded documents (not deeply nested) - [@Startouf](https://github.com/Startouf).
|
13
|
+
* [#227](https://github.com/mongoid/mongoid-history/pull/227): Store options in inheritable class attributes - [@jnfeinstein](https://github.com/jnfeinstein).
|
14
|
+
* [#229](https://github.com/mongoid/mongoid-history/pull/229), [#225](https://github.com/mongoid/mongoid-history/pull/225): Fixed inheritance of `history_trackable_options` - [@jnfeinstein](https://github.com/jnfeinstein).
|
15
|
+
|
16
|
+
### 0.8.1 (2018/06/28)
|
17
|
+
|
18
|
+
* [#221](https://github.com/mongoid/mongoid-history/pull/221): Mongoid 7 support - [@dblock](https://github.com/dblock).
|
19
|
+
|
20
|
+
### 0.8.0 (2018/01/16)
|
21
|
+
|
22
|
+
* [#180](https://github.com/mongoid/mongoid-history/pull/180): Removed deprecation notice - [@sivagollapalli](https://github.com/sivagollapalli).
|
23
|
+
* [#208](https://github.com/mongoid/mongoid-history/pull/208): Fix: history tracks fields declared after `track_history` - [@mikwat](https://github.com/mikwat).
|
24
|
+
* [#210](https://github.com/mongoid/mongoid-history/pull/210): Do not track unmodified embedded relations - [@jagdeepsingh](https://github.com/jagdeepsingh).
|
25
|
+
* [#205](https://github.com/mongoid/mongoid-history/pull/205): Allow modifier field to be optional - [@yads](https://github.com/yads).
|
26
|
+
* [#211](https://github.com/mongoid/mongoid-history/pull/211): Enable tracking create/destroy by default - [@jagdeepsingh](https://github.com/jagdeepsingh).
|
27
|
+
* [#212](https://github.com/mongoid/mongoid-history/pull/212): `track_history` method support for `:if` and `:unless` options - [@jagdeepsingh](https://github.com/jagdeepsingh).
|
28
|
+
|
29
|
+
### 0.7.0 (2017/11/14)
|
30
|
+
|
31
|
+
* [#202](https://github.com/mongoid/mongoid-history/pull/202): Do not create tracker on persistence error - [@mikwat](https://github.com/mikwat).
|
32
|
+
* [#196](https://github.com/mongoid/mongoid-history/pull/196): Fix bug causing history tracks to get mixed up between multiple trackers when using multiple trackers - [@ojbucao](https://github.com/ojbucao).
|
33
|
+
|
1
34
|
### 0.6.1 (2017/01/04)
|
2
35
|
|
3
36
|
* [#182](https://github.com/mongoid/mongoid-history/pull/182): No-op on repeated calls to destroy - [@msaffitz](https://github.com/msaffitz).
|
data/CONTRIBUTING.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
Contributing to Mongoid-History
|
2
2
|
===============================
|
3
3
|
|
4
|
-
Mongoid-History is work of [many of contributors](https://github.com/
|
4
|
+
Mongoid-History is work of [many of contributors](https://github.com/mongoid/mongoid-history/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/mongoid/mongoid-history/pulls), [propose features, ask questions and discuss issues](https://github.com/mongoid/mongoid-history/issues).
|
5
5
|
|
6
6
|
#### Fork the Project
|
7
7
|
|
8
|
-
Fork the [project on Github](https://github.com/
|
8
|
+
Fork the [project on Github](https://github.com/mongoid/mongoid-history) and check out your copy.
|
9
9
|
|
10
10
|
```
|
11
11
|
git clone https://github.com/contributor/mongoid-history.git
|
12
12
|
cd mongoid-history
|
13
|
-
git remote add upstream https://github.com/
|
13
|
+
git remote add upstream https://github.com/mongoid/mongoid-history.git
|
14
14
|
```
|
15
15
|
|
16
16
|
#### Create a Topic Branch
|
@@ -95,7 +95,7 @@ git push origin my-feature-branch -f
|
|
95
95
|
Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.
|
96
96
|
|
97
97
|
```
|
98
|
-
* [#123](https://github.com/
|
98
|
+
* [#123](https://github.com/mongoid/mongoid-history/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
|
99
99
|
```
|
100
100
|
|
101
101
|
Amend your previous commit and force push the changes.
|
data/Gemfile
CHANGED
@@ -2,34 +2,39 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
-
case version = ENV['MONGOID_VERSION'] || '~>
|
5
|
+
case version = ENV['MONGOID_VERSION'] || '~> 7.0.0'
|
6
6
|
when 'HEAD'
|
7
7
|
gem 'mongoid', github: 'mongodb/mongoid'
|
8
|
-
when /
|
8
|
+
when /\b7/
|
9
|
+
gem 'mongoid', '~> 7.0.0'
|
10
|
+
when /\b6/
|
9
11
|
gem 'mongoid', '~> 6.0.0'
|
10
|
-
when /
|
12
|
+
when /\b5/
|
11
13
|
gem 'mongoid', '~> 5.0'
|
12
14
|
gem 'mongoid-observers', '~> 0.2.0'
|
13
|
-
when /
|
15
|
+
when /\b4/
|
14
16
|
gem 'mongoid', '~> 4.0'
|
15
17
|
gem 'mongoid-observers', '~> 0.2.0'
|
16
|
-
when /
|
17
|
-
gem 'mongoid', '~> 3.1'
|
18
|
+
when /\b3/
|
19
|
+
gem 'mongoid', '~> 3.1.7'
|
18
20
|
else
|
19
21
|
gem 'mongoid', version
|
20
22
|
end
|
23
|
+
gem 'mongoid-compatibility'
|
21
24
|
|
22
25
|
group :development, :test do
|
23
|
-
gem 'rake', '< 11.0'
|
24
26
|
gem 'bundler'
|
27
|
+
gem 'pry'
|
28
|
+
gem 'rake', '< 11.0'
|
25
29
|
end
|
26
30
|
|
27
31
|
group :test do
|
32
|
+
gem 'benchmark-ips', require: false
|
33
|
+
gem 'coveralls'
|
34
|
+
gem 'gem-release'
|
28
35
|
gem 'mongoid-danger', '~> 0.1.0', require: false
|
36
|
+
gem 'request_store'
|
29
37
|
gem 'rspec', '~> 3.1'
|
30
|
-
gem 'rubocop', '0.
|
38
|
+
gem 'rubocop', '0.48.1'
|
31
39
|
gem 'yard'
|
32
|
-
gem 'gem-release'
|
33
|
-
gem 'coveralls'
|
34
|
-
gem 'request_store'
|
35
40
|
end
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,6 @@ mongoid-history
|
|
3
3
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/mongoid-history.svg)](http://badge.fury.io/rb/mongoid-history)
|
5
5
|
[![Build Status](https://secure.travis-ci.org/mongoid/mongoid-history.svg?branch=master)](http://travis-ci.org/mongoid/mongoid-history)
|
6
|
-
[![Dependency Status](https://gemnasium.com/mongoid/mongoid-history.svg)](https://gemnasium.com/mongoid/mongoid-history)
|
7
6
|
[![Code Climate](https://codeclimate.com/github/mongoid/mongoid-history.svg)](https://codeclimate.com/github/mongoid/mongoid-history)
|
8
7
|
[![Coverage Status](https://coveralls.io/repos/mongoid/mongoid-history/badge.svg)](https://coveralls.io/r/mongoid/mongoid-history?branch=coveralls)
|
9
8
|
|
@@ -14,7 +13,7 @@ This gem also implements multi-user undo, which allows users to undo any history
|
|
14
13
|
Install
|
15
14
|
-------
|
16
15
|
|
17
|
-
This gem supports Mongoid 3, 4, 5 on Ruby 1.9.3 or newer and Mongoid 6 on Ruby 2.2.2+. Add it to your `Gemfile` or run `gem install mongoid-history`.
|
16
|
+
This gem supports Mongoid 3, 4, 5 on Ruby 1.9.3 or newer and Mongoid 6 and 7 on Ruby 2.2.2+. Add it to your `Gemfile` or run `gem install mongoid-history`.
|
18
17
|
|
19
18
|
```ruby
|
20
19
|
gem 'mongoid-history'
|
@@ -37,8 +36,8 @@ end
|
|
37
36
|
**Set default tracker class name (Optional)**
|
38
37
|
|
39
38
|
Mongoid::History will use the first loaded class to include Mongoid::History::Tracker as the
|
40
|
-
default history tracker. If you are using multiple Tracker classes
|
41
|
-
|
39
|
+
default history tracker. If you are using multiple Tracker classes, you should set a global
|
40
|
+
default in a Rails initializer:
|
42
41
|
|
43
42
|
```ruby
|
44
43
|
# config/initializers/mongoid_history.rb
|
@@ -66,12 +65,13 @@ class Post
|
|
66
65
|
# telling Mongoid::History how you want to track changes
|
67
66
|
# dynamic fields will be tracked automatically (for MongoId 4.0+ you should include Mongoid::Attributes::Dynamic to your model)
|
68
67
|
track_history :on => [:title, :body], # track title and body fields only, default is :all
|
69
|
-
:modifier_field => :modifier, # adds "belongs_to :modifier" to track who made the change, default is :modifier
|
68
|
+
:modifier_field => :modifier, # adds "belongs_to :modifier" to track who made the change, default is :modifier, set to nil to not create modifier_field
|
70
69
|
:modifier_field_inverse_of => :nil, # adds an ":inverse_of" option to the "belongs_to :modifier" relation, default is not set
|
70
|
+
:modifier_field_optional => true, # marks the modifier relationship as optional (requires Mongoid 6 or higher)
|
71
71
|
:version_field => :version, # adds "field :version, :type => Integer" to track current version, default is :version
|
72
|
-
:track_create
|
73
|
-
:track_update
|
74
|
-
:track_destroy
|
72
|
+
:track_create => true, # track document creation, default is true
|
73
|
+
:track_update => true, # track document updates, default is true
|
74
|
+
:track_destroy => true # track document destruction, default is true
|
75
75
|
end
|
76
76
|
|
77
77
|
class Comment
|
@@ -149,11 +149,34 @@ Comment.disable_tracking do
|
|
149
149
|
comment.update_attributes(:title => "Test 3")
|
150
150
|
end
|
151
151
|
|
152
|
-
#
|
152
|
+
# disable tracking for comments by default
|
153
|
+
Comment.disable_tracking!
|
154
|
+
|
155
|
+
# enable tracking for comments within a block
|
156
|
+
Comment.enable_tracking do
|
157
|
+
comment.update_attributes(:title => "Test 3")
|
158
|
+
end
|
159
|
+
|
160
|
+
# renable tracking for comments by default
|
161
|
+
Comment.enable_tracking!
|
162
|
+
|
163
|
+
# globally disable all history tracking within a block
|
153
164
|
Mongoid::History.disable do
|
154
165
|
comment.update_attributes(:title => "Test 3")
|
155
166
|
user.update_attributes(:name => "Eddie Van Halen")
|
156
167
|
end
|
168
|
+
|
169
|
+
# globally disable all history tracking by default
|
170
|
+
Mongoid::History.disable!
|
171
|
+
|
172
|
+
# globally enable all history tracking within a block
|
173
|
+
Mongoid::History.enable do
|
174
|
+
comment.update_attributes(:title => "Test 3")
|
175
|
+
user.update_attributes(:name => "Eddie Van Halen")
|
176
|
+
end
|
177
|
+
|
178
|
+
# globally renable all history tracking by default
|
179
|
+
Mongoid::History.enable!
|
157
180
|
```
|
158
181
|
|
159
182
|
You may want to track changes on all fields.
|
@@ -388,7 +411,7 @@ In your View, you might do something like (example in HAML format):
|
|
388
411
|
|
389
412
|
**Adding Userstamp on History Trackers**
|
390
413
|
|
391
|
-
To track the User in the application who created the HistoryTracker,
|
414
|
+
To track the User in the application who created the HistoryTracker, add the
|
392
415
|
[Mongoid::Userstamp gem](https://github.com/tbpro/mongoid_userstamp) to your HistoryTracker class.
|
393
416
|
This will add a field called `created_by` and an accessor `creator` to the model (you can rename these via gem config).
|
394
417
|
|
@@ -399,15 +422,6 @@ class MyHistoryTracker
|
|
399
422
|
end
|
400
423
|
```
|
401
424
|
|
402
|
-
*Migrating Userstamp from Previous Versions*
|
403
|
-
|
404
|
-
Since October 2013 (mongoid-history version 0.4.1 and onwards), Mongoid::History itself no longer supports the userstamp natively. In order to migrate, follow the
|
405
|
-
instructions above then run the following command:
|
406
|
-
|
407
|
-
```
|
408
|
-
MyHistoryTracker.all.rename(modifier_id: :created_by)
|
409
|
-
```
|
410
|
-
|
411
425
|
**Setting Modifier Class Name**
|
412
426
|
|
413
427
|
If your app will track history changes to a user, Mongoid History looks for these modifiers in the ``User`` class by default. If you have named your 'user' accounts differently, you will need to add that to your Mongoid History config:
|
@@ -429,6 +443,18 @@ Or perhaps you are namespacing to a module:
|
|
429
443
|
Mongoid::History.modifier_class_name = 'CMS::Author'
|
430
444
|
```
|
431
445
|
|
446
|
+
**Conditional :if and :unless options**
|
447
|
+
|
448
|
+
The `track_history` method supports `:if` and `:unless` options which will skip generating
|
449
|
+
the history tracker unless they are satisfied. These options can take either a method
|
450
|
+
`Symbol` or a `Proc`. They behave identical to how `:if` and `:unless` behave in Rails model callbacks.
|
451
|
+
|
452
|
+
```ruby
|
453
|
+
track_history on: [:ip],
|
454
|
+
if: :should_i_track_history?,
|
455
|
+
unless: ->(obj){ obj.method_to_skip_history }
|
456
|
+
```
|
457
|
+
|
432
458
|
**Using an alternate changes method**
|
433
459
|
|
434
460
|
Sometimes you may wish to provide an alternate method for determining which changes should be tracked. For example, if you are using embedded documents
|
@@ -509,6 +535,57 @@ end
|
|
509
535
|
|
510
536
|
For more examples, check out [spec/integration/integration_spec.rb](spec/integration/integration_spec.rb).
|
511
537
|
|
538
|
+
**Multiple Trackers**
|
539
|
+
|
540
|
+
You can have different trackers for different classes like so.
|
541
|
+
|
542
|
+
``` ruby
|
543
|
+
class First
|
544
|
+
include Mongoid::Document
|
545
|
+
include Mongoid::History::Trackable
|
546
|
+
|
547
|
+
field :text, type: String
|
548
|
+
track_history on: [:text],
|
549
|
+
tracker_class_name: :first_history_tracker
|
550
|
+
end
|
551
|
+
|
552
|
+
class Second
|
553
|
+
include Mongoid::Document
|
554
|
+
include Mongoid::History::Trackable
|
555
|
+
|
556
|
+
field :text, type: String
|
557
|
+
track_history on: [:text],
|
558
|
+
tracker_class_name: :second_history_tracker
|
559
|
+
end
|
560
|
+
|
561
|
+
class FirstHistoryTracker
|
562
|
+
include Mongoid::History::Tracker
|
563
|
+
end
|
564
|
+
|
565
|
+
class SecondHistoryTracker
|
566
|
+
include Mongoid::History::Tracker
|
567
|
+
end
|
568
|
+
```
|
569
|
+
|
570
|
+
Note that if you are using a tracker for an embedded object that is different
|
571
|
+
from the parent's tracker, redos and undos will not work. You have to use the
|
572
|
+
same tracker for these to work across embedded relationships.
|
573
|
+
|
574
|
+
If you are using multiple trackers and the `tracker_class_name` parameter is
|
575
|
+
not specified, Mongoid::History will use the default tracker configured in the
|
576
|
+
initializer file or whatever the first tracker was loaded.
|
577
|
+
|
578
|
+
|
579
|
+
**Dependent Restrict Associations**
|
580
|
+
|
581
|
+
When `dependent: :restrict` is used on an association, a call to `destroy` on
|
582
|
+
the model will raise `Mongoid::Errors::DeleteRestriction` when the dependency
|
583
|
+
is violated. Just be aware that this gem will create a history track document
|
584
|
+
before the `destroy` call and then remove if an error is raised. This applies
|
585
|
+
to all persistence calls: create, update and destroy.
|
586
|
+
|
587
|
+
See [spec/integration/validation_failure_spec.rb](spec/integration/validation_failure_spec.rb)
|
588
|
+
for examples.
|
512
589
|
|
513
590
|
**Thread Safety**
|
514
591
|
|
@@ -526,6 +603,6 @@ You're encouraged to contribute to this library. See [CONTRIBUTING](CONTRIBUTING
|
|
526
603
|
Copyright
|
527
604
|
---------
|
528
605
|
|
529
|
-
Copyright (c) 2011-
|
606
|
+
Copyright (c) 2011-2018 Aaron Qian and Contributors.
|
530
607
|
|
531
608
|
MIT License. See [LICENSE.txt](LICENSE.txt) for further details.
|