audited 4.2.1 → 4.4.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +20 -9
- data/Appraisals +11 -6
- data/CHANGELOG.md +190 -0
- data/Gemfile +1 -13
- data/README.md +65 -34
- data/Rakefile +3 -18
- data/gemfiles/rails40.gemfile +1 -5
- data/gemfiles/rails41.gemfile +1 -5
- data/gemfiles/rails42.gemfile +1 -5
- data/gemfiles/rails50.gemfile +7 -0
- data/gemfiles/rails51.gemfile +7 -0
- data/lib/audited/audit.rb +126 -56
- data/lib/audited/auditor.rb +76 -44
- data/lib/audited/rspec_matchers.rb +5 -1
- data/lib/audited/sweeper.rb +24 -46
- data/lib/audited/version.rb +1 -1
- data/lib/audited-rspec.rb +4 -0
- data/lib/audited.rb +16 -2
- data/lib/generators/audited/install_generator.rb +24 -0
- data/lib/generators/audited/migration.rb +15 -0
- data/lib/generators/audited/migration_helper.rb +9 -0
- data/lib/generators/audited/templates/add_association_to_audits.rb +11 -0
- data/lib/generators/audited/templates/add_comment_to_audits.rb +9 -0
- data/lib/generators/audited/templates/add_remote_address_to_audits.rb +10 -0
- data/lib/generators/audited/templates/add_request_uuid_to_audits.rb +10 -0
- data/lib/generators/audited/templates/install.rb +30 -0
- data/lib/generators/audited/templates/rename_association_to_associated.rb +23 -0
- data/lib/generators/audited/templates/rename_changes_to_audited_changes.rb +9 -0
- data/lib/generators/audited/templates/rename_parent_to_association.rb +11 -0
- data/lib/generators/audited/upgrade_generator.rb +59 -0
- data/spec/audited/audit_spec.rb +246 -0
- data/spec/audited/auditor_spec.rb +648 -0
- data/spec/audited/sweeper_spec.rb +108 -0
- data/spec/audited_spec_helpers.rb +6 -22
- data/spec/rails_app/config/environments/test.rb +7 -4
- data/spec/rails_app/config/initializers/secret_token.rb +1 -1
- data/spec/rails_app/config/routes.rb +1 -4
- data/spec/spec_helper.rb +7 -9
- data/spec/support/active_record/models.rb +24 -13
- data/spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb +12 -0
- data/spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb +12 -0
- data/spec/support/active_record/schema.rb +37 -12
- data/test/db/version_1.rb +4 -4
- data/test/db/version_2.rb +4 -4
- data/test/db/version_3.rb +4 -4
- data/test/db/version_4.rb +4 -4
- data/test/db/version_5.rb +2 -2
- data/test/db/version_6.rb +2 -2
- data/test/install_generator_test.rb +31 -3
- data/test/upgrade_generator_test.rb +25 -10
- metadata +69 -43
- data/CHANGELOG +0 -34
- data/lib/audited/active_record/version.rb +0 -5
- data/lib/audited/mongo_mapper/version.rb +0 -5
- data/spec/support/mongo_mapper/connection.rb +0 -4
- data/spec/support/mongo_mapper/models.rb +0 -214
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b999065ad92a0fbe08d0739e44dfe966d35ee57f
|
|
4
|
+
data.tar.gz: 258e418fcfaf0b839c209435dda7ab509c25b52b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: acb5cb634042722106e7b120791723d879677992628572c830c03d2594e472857127d09714ed6d61cd3aaec635b82e4396441d94a900556e01bc795ad1ed05a1
|
|
7
|
+
data.tar.gz: 41fff32c9c1b060f040007a038d2840c6e7c43f528dbc9924d3ac1727fee692c10e959bc43bbe2c25882c2cfad9f69b54d8bb21836a3786a1c11928ed10a5770
|
data/.travis.yml
CHANGED
|
@@ -1,28 +1,39 @@
|
|
|
1
1
|
language: ruby
|
|
2
|
-
|
|
2
|
+
cache: bundler
|
|
3
3
|
rvm:
|
|
4
|
-
- 2.0
|
|
5
4
|
- 2.1
|
|
6
|
-
- 2.2
|
|
7
|
-
-
|
|
5
|
+
- 2.2.4
|
|
6
|
+
- 2.3.1
|
|
7
|
+
- 2.4.1
|
|
8
|
+
- ruby-head
|
|
8
9
|
env:
|
|
9
10
|
- DB=SQLITE
|
|
10
11
|
- DB=POSTGRES
|
|
11
12
|
- DB=MYSQL
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
- psql -c 'create database audited_test;' -U postgres
|
|
13
|
+
addons:
|
|
14
|
+
postgresql: "9.4"
|
|
15
15
|
gemfile:
|
|
16
16
|
- gemfiles/rails40.gemfile
|
|
17
17
|
- gemfiles/rails41.gemfile
|
|
18
18
|
- gemfiles/rails42.gemfile
|
|
19
|
+
- gemfiles/rails50.gemfile
|
|
20
|
+
- gemfiles/rails51.gemfile
|
|
19
21
|
matrix:
|
|
20
22
|
allow_failures:
|
|
21
|
-
- rvm:
|
|
23
|
+
- rvm: ruby-head
|
|
24
|
+
exclude:
|
|
25
|
+
- rvm: 2.1
|
|
26
|
+
gemfile: gemfiles/rails50.gemfile
|
|
27
|
+
- rvm: 2.1
|
|
28
|
+
gemfile: gemfiles/rails51.gemfile
|
|
29
|
+
- rvm: 2.4.1
|
|
30
|
+
gemfile: gemfiles/rails40.gemfile
|
|
31
|
+
- rvm: 2.4.1
|
|
32
|
+
gemfile: gemfiles/rails41.gemfile
|
|
33
|
+
fast_finish: true
|
|
22
34
|
branches:
|
|
23
35
|
only:
|
|
24
36
|
- master
|
|
25
|
-
- 4.2-stable
|
|
26
37
|
sudo: false
|
|
27
38
|
notifications:
|
|
28
39
|
webhooks:
|
data/Appraisals
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
appraise 'rails40' do
|
|
2
2
|
gem 'rails', '~> 4.0.0'
|
|
3
|
-
gem '
|
|
3
|
+
gem 'protected_attributes'
|
|
4
4
|
gem 'test-unit'
|
|
5
|
-
gem 'mysql2', '~> 0.3.0'
|
|
6
5
|
end
|
|
7
6
|
|
|
8
7
|
appraise 'rails41' do
|
|
9
8
|
gem 'rails', '~> 4.1.0'
|
|
10
|
-
gem '
|
|
11
|
-
gem 'mysql2', '~> 0.3.0'
|
|
9
|
+
gem 'protected_attributes'
|
|
12
10
|
end
|
|
13
11
|
|
|
14
12
|
appraise 'rails42' do
|
|
15
13
|
gem 'rails', '~> 4.2.0'
|
|
16
|
-
gem '
|
|
17
|
-
|
|
14
|
+
gem 'protected_attributes'
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
appraise 'rails50' do
|
|
18
|
+
gem 'rails', '~> 5.0.0'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
appraise 'rails51' do
|
|
22
|
+
gem 'rails', '>= 5.1.0.rc1', '< 5.2'
|
|
18
23
|
end
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
# Audited ChangeLog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
Breaking changes
|
|
6
|
+
|
|
7
|
+
- None
|
|
8
|
+
|
|
9
|
+
Added
|
|
10
|
+
|
|
11
|
+
- None
|
|
12
|
+
|
|
13
|
+
Changed
|
|
14
|
+
|
|
15
|
+
- None
|
|
16
|
+
|
|
17
|
+
Fixed
|
|
18
|
+
|
|
19
|
+
- None
|
|
20
|
+
|
|
21
|
+
## 4.4.0 (2017-03-29)
|
|
22
|
+
|
|
23
|
+
Breaking changes
|
|
24
|
+
|
|
25
|
+
- None
|
|
26
|
+
|
|
27
|
+
Added
|
|
28
|
+
|
|
29
|
+
- Support for `audited_changes` to be a `json` or `jsonb` column in PostgreSQL
|
|
30
|
+
[#216](https://github.com/collectiveidea/audited/issues/216)
|
|
31
|
+
- Allow `Audited::Audit` to be subclassed by configuring `Audited.audit_class`
|
|
32
|
+
[#314](https://github.com/collectiveidea/audited/issues/314)
|
|
33
|
+
- Support for Ruby on Rails 5.1
|
|
34
|
+
[#329](https://github.com/collectiveidea/audited/issues/329)
|
|
35
|
+
- Support for Ruby 2.4
|
|
36
|
+
[#329](https://github.com/collectiveidea/audited/issues/329)
|
|
37
|
+
|
|
38
|
+
Changed
|
|
39
|
+
|
|
40
|
+
- Remove rails-observer dependency
|
|
41
|
+
[#325](https://github.com/collectiveidea/audited/issues/325)
|
|
42
|
+
- Undeprecated `Audited.audit_class` reader
|
|
43
|
+
[#314](https://github.com/collectiveidea/audited/issues/314)
|
|
44
|
+
|
|
45
|
+
Fixed
|
|
46
|
+
|
|
47
|
+
- SQL error in Rails Conditional GET (304 caching)
|
|
48
|
+
[#295](https://github.com/collectiveidea/audited/pull/295)
|
|
49
|
+
- Fix missing non_audited_columns= configuration setter
|
|
50
|
+
[#320](https://github.com/collectiveidea/audited/issues/320)
|
|
51
|
+
- Fix migration generators to specify AR migration version
|
|
52
|
+
[#329](https://github.com/collectiveidea/audited/issues/329)
|
|
53
|
+
|
|
54
|
+
## 4.3.0 (2016-09-17)
|
|
55
|
+
|
|
56
|
+
Breaking changes
|
|
57
|
+
|
|
58
|
+
- None
|
|
59
|
+
|
|
60
|
+
Added
|
|
61
|
+
|
|
62
|
+
- Support singular arguments for options: `on` and `only`
|
|
63
|
+
|
|
64
|
+
Fixed
|
|
65
|
+
|
|
66
|
+
- Fix auditing instance attributes if "only" option specified
|
|
67
|
+
- Allow private / protected callback declarations
|
|
68
|
+
- Do not eagerly connect to database
|
|
69
|
+
|
|
70
|
+
## 4.2.2 (2016-08-01)
|
|
71
|
+
|
|
72
|
+
- Correct auditing_enabled for STI models
|
|
73
|
+
- Properly set table name for mongomapper
|
|
74
|
+
|
|
75
|
+
## 4.2.1 (2016-07-29)
|
|
76
|
+
|
|
77
|
+
- Fix bug when only: is a single field.
|
|
78
|
+
- update gemspec to use mongomapper 0.13
|
|
79
|
+
- sweeper need not run observer for mongomapper
|
|
80
|
+
- Make temporary disabling of auditing threadsafe
|
|
81
|
+
- Centralize `Audited.store` as thread safe variable store
|
|
82
|
+
|
|
83
|
+
## 4.2.0 (2015-03-31)
|
|
84
|
+
|
|
85
|
+
Not yet documented.
|
|
86
|
+
|
|
87
|
+
## 4.0.0 (2014-09-04)
|
|
88
|
+
|
|
89
|
+
Not yet documented.
|
|
90
|
+
|
|
91
|
+
## 4.0.0.rc1 (2014-07-30)
|
|
92
|
+
|
|
93
|
+
Not yet documented.
|
|
94
|
+
|
|
95
|
+
## 3.0.0 (2012-09-25)
|
|
96
|
+
|
|
97
|
+
Not yet documented.
|
|
98
|
+
|
|
99
|
+
## 3.0.0.rc2 (2012-07-09)
|
|
100
|
+
|
|
101
|
+
Not yet documented.
|
|
102
|
+
|
|
103
|
+
## 3.0.0.rc1 (2012-04-25)
|
|
104
|
+
|
|
105
|
+
Not yet documented.
|
|
106
|
+
|
|
107
|
+
## 2012-04-10
|
|
108
|
+
|
|
109
|
+
- Add Audit scopes for creates, updates and destroys [chriswfx]
|
|
110
|
+
|
|
111
|
+
## 2011-10-25
|
|
112
|
+
|
|
113
|
+
- Made ignored_attributes configurable [senny]
|
|
114
|
+
|
|
115
|
+
## 2011-09-09
|
|
116
|
+
|
|
117
|
+
- Rails 3.x support
|
|
118
|
+
- Support for associated audits
|
|
119
|
+
- Support for remote IP address storage
|
|
120
|
+
- Plenty of bug fixes and refactoring
|
|
121
|
+
- [kennethkalmer, ineu, PatrickMa, jrozner, dwarburton, bsiggelkow, dgm]
|
|
122
|
+
|
|
123
|
+
## 2009-01-27
|
|
124
|
+
|
|
125
|
+
- Store old and new values for updates, and store all attributes on destroy.
|
|
126
|
+
- Refactored revisioning methods to work as expected
|
|
127
|
+
|
|
128
|
+
## 2008-10-10
|
|
129
|
+
|
|
130
|
+
- changed to make it work in development mode
|
|
131
|
+
|
|
132
|
+
## 2008-09-24
|
|
133
|
+
|
|
134
|
+
- Add ability to record parent record of the record being audited [Kenneth Kalmer]
|
|
135
|
+
|
|
136
|
+
## 2008-04-19
|
|
137
|
+
|
|
138
|
+
- refactored to make compatible with dirty tracking in edge rails
|
|
139
|
+
and to stop storing both old and new values in a single audit
|
|
140
|
+
|
|
141
|
+
## 2008-04-18
|
|
142
|
+
|
|
143
|
+
- Fix NoMethodError when trying to access the :previous revision
|
|
144
|
+
on a model that doesn't have previous revisions [Alex Soto]
|
|
145
|
+
|
|
146
|
+
## 2008-03-21
|
|
147
|
+
|
|
148
|
+
- added #changed_attributes to get access to the changes before a
|
|
149
|
+
save [Chris Parker]
|
|
150
|
+
|
|
151
|
+
## 2007-12-16
|
|
152
|
+
|
|
153
|
+
- Added #revision_at for retrieving a revision from a specific
|
|
154
|
+
time [Jacob Atzen]
|
|
155
|
+
|
|
156
|
+
## 2007-12-16
|
|
157
|
+
|
|
158
|
+
- Fix error when getting revision from audit with no changes
|
|
159
|
+
[Geoffrey Wiseman]
|
|
160
|
+
|
|
161
|
+
## 2007-12-16
|
|
162
|
+
|
|
163
|
+
- Remove dependency on acts_as_list
|
|
164
|
+
|
|
165
|
+
## 2007-06-17
|
|
166
|
+
|
|
167
|
+
- Added support getting previous revisions
|
|
168
|
+
|
|
169
|
+
## 2006-11-17
|
|
170
|
+
|
|
171
|
+
- Replaced use of singleton User.current_user with cache sweeper
|
|
172
|
+
implementation for auditing the user that made the change
|
|
173
|
+
|
|
174
|
+
## 2006-11-17
|
|
175
|
+
|
|
176
|
+
- added migration generator
|
|
177
|
+
|
|
178
|
+
## 2006-08-14
|
|
179
|
+
|
|
180
|
+
- incorporated changes from Michael Schuerig to write_attribute
|
|
181
|
+
that saves the new value after every change and not just the
|
|
182
|
+
first, and performs proper type-casting before doing comparisons
|
|
183
|
+
|
|
184
|
+
## 2006-08-14
|
|
185
|
+
|
|
186
|
+
- The "changes" are now saved as a serialized hash
|
|
187
|
+
|
|
188
|
+
## 2006-07-21
|
|
189
|
+
|
|
190
|
+
- initial version
|
data/Gemfile
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
1
|
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
|
-
gemspec :
|
|
4
|
-
# JRuby support for the test ENV
|
|
5
|
-
unless defined?(JRUBY_VERSION)
|
|
6
|
-
gem 'sqlite3', '~> 1.2'
|
|
7
|
-
gem 'mysql2', '~> 0.3'
|
|
8
|
-
gem 'pg', '~> 0.17'
|
|
9
|
-
gem 'bson_ext', '~> 1.6'
|
|
10
|
-
else
|
|
11
|
-
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3'
|
|
12
|
-
gem 'activerecord-jdbcpostgresql-adapter', '~> 1.3'
|
|
13
|
-
gem 'activerecord-jdbcmysql-adapter', '~> 1.3'
|
|
14
|
-
gem 'bson', '~> 1.6'
|
|
15
|
-
end
|
|
3
|
+
gemspec name: "audited"
|
data/README.md
CHANGED
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
Audited [](http://travis-ci.org/collectiveidea/audited) [](https://gemnasium.com/collectiveidea/audited)[](https://codeclimate.com/github/collectiveidea/audited) [](https://hakiri.io/github/collectiveidea/audited/master)
|
|
2
2
|
=======
|
|
3
3
|
|
|
4
|
-
**Audited** (previously acts_as_audited) is an ORM extension that logs all changes to your models. Audited also
|
|
4
|
+
**Audited** (previously acts_as_audited) is an ORM extension that logs all changes to your models. Audited can also record who made those changes, save comments and associate models related to the changes.
|
|
5
5
|
|
|
6
|
-
Audited currently (4.x) works with Rails 4.2.
|
|
6
|
+
Audited currently (4.x) works with Rails 5.1, 5.0 and 4.2. It may work with 4.1 and 4.0, but this is not guaranteed.
|
|
7
|
+
|
|
8
|
+
For Rails 3, use gem version 3.0 or see the [3.0-stable branch](https://github.com/collectiveidea/audited/tree/3.0-stable).
|
|
7
9
|
|
|
8
10
|
## Supported Rubies
|
|
9
11
|
|
|
10
12
|
Audited supports and is [tested against](http://travis-ci.org/collectiveidea/audited) the following Ruby versions:
|
|
11
13
|
|
|
12
|
-
* 2.0.0
|
|
13
14
|
* 2.1.5
|
|
14
|
-
* 2.2.
|
|
15
|
+
* 2.2.4
|
|
16
|
+
* 2.3.1
|
|
17
|
+
* 2.4.1
|
|
15
18
|
|
|
16
19
|
Audited may work just fine with a Ruby version not listed above, but we can't guarantee that it will. If you'd like to maintain a Ruby that isn't listed, please let us know with a [pull request](https://github.com/collectiveidea/audited/pulls).
|
|
17
20
|
|
|
18
21
|
## Supported ORMs
|
|
19
22
|
|
|
20
|
-
In a previous life, Audited
|
|
21
|
-
|
|
22
|
-
* ActiveRecord
|
|
23
|
-
* MongoMapper
|
|
23
|
+
Audited is currently ActiveRecord-only. In a previous life, Audited worked with MongoMapper. Use the [4.2-stable branch](https://github.com/collectiveidea/audited/tree/4.2-stable) if you need MongoMapper.
|
|
24
24
|
|
|
25
25
|
## Installation
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
### ActiveRecord
|
|
30
|
-
|
|
31
|
-
Add the appropriate gem to your Gemfile:
|
|
27
|
+
Add the gem to your Gemfile:
|
|
32
28
|
|
|
33
29
|
```ruby
|
|
34
|
-
gem "audited
|
|
30
|
+
gem "audited", "~> 4.4"
|
|
35
31
|
```
|
|
36
32
|
|
|
37
33
|
Then, from your Rails app directory, create the `audits` table:
|
|
@@ -41,6 +37,8 @@ $ rails generate audited:install
|
|
|
41
37
|
$ rake db:migrate
|
|
42
38
|
```
|
|
43
39
|
|
|
40
|
+
If you're using PostgreSQL, then you can use `rails generate audited:install --audited-changes-column-type jsonb` (or `json`) to store audit changes natively with its JSON column types.
|
|
41
|
+
|
|
44
42
|
#### Upgrading
|
|
45
43
|
|
|
46
44
|
If you're already using Audited (or acts_as_audited), your `audits` table may require additional columns. After every upgrade, please run:
|
|
@@ -52,11 +50,6 @@ $ rake db:migrate
|
|
|
52
50
|
|
|
53
51
|
Upgrading will only make changes if changes are needed.
|
|
54
52
|
|
|
55
|
-
### MongoMapper
|
|
56
|
-
|
|
57
|
-
```ruby
|
|
58
|
-
gem "audited-mongo_mapper", "~> 4.0"
|
|
59
|
-
```
|
|
60
53
|
|
|
61
54
|
## Usage
|
|
62
55
|
|
|
@@ -88,6 +81,15 @@ audit.action # => "update"
|
|
|
88
81
|
audit.audited_changes # => {"name"=>["Steve", "Ryan"]}
|
|
89
82
|
```
|
|
90
83
|
|
|
84
|
+
You can get previous versions of a record by index or date, or list all
|
|
85
|
+
revisions.
|
|
86
|
+
|
|
87
|
+
```ruby
|
|
88
|
+
user.revisions
|
|
89
|
+
user.revision(1)
|
|
90
|
+
user.revision_at(Date.parse("2016-01-01"))
|
|
91
|
+
```
|
|
92
|
+
|
|
91
93
|
### Specifying columns
|
|
92
94
|
|
|
93
95
|
By default, a new audit is created for any attribute changes. You can, however, limit the columns to be considered.
|
|
@@ -143,7 +145,7 @@ end
|
|
|
143
145
|
|
|
144
146
|
If you're using Audited in a Rails application, all audited changes made within a request will automatically be attributed to the current user. By default, Audited uses the `current_user` method in your controller.
|
|
145
147
|
|
|
146
|
-
```
|
|
148
|
+
```ruby
|
|
147
149
|
class PostsController < ApplicationController
|
|
148
150
|
def create
|
|
149
151
|
current_user # => #<User name: "Steve">
|
|
@@ -168,6 +170,22 @@ end
|
|
|
168
170
|
post.audits.last.user # => #<User id: 1>
|
|
169
171
|
```
|
|
170
172
|
|
|
173
|
+
#### Custom Auditor
|
|
174
|
+
|
|
175
|
+
You might need to use a custom auditor from time to time. It can be done by simply passing in a string:
|
|
176
|
+
|
|
177
|
+
```ruby
|
|
178
|
+
class ApplicationController < ActionController::Base
|
|
179
|
+
def authenticated_user
|
|
180
|
+
if current_user
|
|
181
|
+
current_user
|
|
182
|
+
else
|
|
183
|
+
'Elon Musk'
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
187
|
+
```
|
|
188
|
+
|
|
171
189
|
### Associated Audits
|
|
172
190
|
|
|
173
191
|
Sometimes it's useful to associate an audit with a model other than the one being changed. For instance, given the following models:
|
|
@@ -197,7 +215,7 @@ class Company < ActiveRecord::Base
|
|
|
197
215
|
end
|
|
198
216
|
```
|
|
199
217
|
|
|
200
|
-
Now, when
|
|
218
|
+
Now, when an audit is created for a user, that user's company is also saved alongside the audit. This makes it much easier (and faster) to access audits indirectly related to a company.
|
|
201
219
|
|
|
202
220
|
```ruby
|
|
203
221
|
company = Company.create!(name: "Collective Idea")
|
|
@@ -238,17 +256,34 @@ To disable auditing on an entire model:
|
|
|
238
256
|
User.auditing_enabled = false
|
|
239
257
|
```
|
|
240
258
|
|
|
241
|
-
|
|
259
|
+
### Custom `Audit` model
|
|
242
260
|
|
|
243
|
-
|
|
261
|
+
If you want to extend or modify the audit model, create a new class that
|
|
262
|
+
inherits from `Audited::Audit`:
|
|
263
|
+
```ruby
|
|
264
|
+
class CustomAudit < Audited::Audit
|
|
265
|
+
def some_custom_behavior
|
|
266
|
+
"Hiya!"
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
```
|
|
270
|
+
Then set it in an initializer:
|
|
271
|
+
```ruby
|
|
272
|
+
# config/initializers/audited.rb
|
|
273
|
+
|
|
274
|
+
Audited.config do |config|
|
|
275
|
+
config.audit_class = CustomAudit
|
|
276
|
+
end
|
|
277
|
+
```
|
|
244
278
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
279
|
+
## Gotchas
|
|
280
|
+
|
|
281
|
+
### Using attr_protected with Rails 4.x
|
|
248
282
|
|
|
283
|
+
If you're using the `protected_attributes` gem with Rails 4.0, 4.1 or 4.2 (the gem isn't supported in Rails 5.0 or higher), you'll have to take an extra couple of steps to get `audited` working.
|
|
249
284
|
|
|
250
|
-
|
|
251
|
-
interfere with `
|
|
285
|
+
First be sure to add `allow_mass_assignment: true` to your `audited` call; otherwise Audited will
|
|
286
|
+
interfere with `protected_attributes` and none of your `save` calls will work.
|
|
252
287
|
|
|
253
288
|
```ruby
|
|
254
289
|
class User < ActiveRecord::Base
|
|
@@ -256,7 +291,7 @@ class User < ActiveRecord::Base
|
|
|
256
291
|
end
|
|
257
292
|
```
|
|
258
293
|
|
|
259
|
-
|
|
294
|
+
Second, be sure to add `audit_ids` to the list of protected attributes to prevent data loss.
|
|
260
295
|
|
|
261
296
|
```ruby
|
|
262
297
|
class User < ActiveRecord::Base
|
|
@@ -265,10 +300,6 @@ class User < ActiveRecord::Base
|
|
|
265
300
|
end
|
|
266
301
|
```
|
|
267
302
|
|
|
268
|
-
### MongoMapper Embedded Documents
|
|
269
|
-
|
|
270
|
-
Currently, Audited does not track changes on embedded documents. Audited works by tracking a model's [dirty changes](http://api.rubyonrails.org/classes/ActiveModel/Dirty.html) but changes to embedded documents don't appear in dirty tracking.
|
|
271
|
-
|
|
272
303
|
## Support
|
|
273
304
|
|
|
274
305
|
You can find documentation at: http://rdoc.info/github/collectiveidea/audited
|
data/Rakefile
CHANGED
|
@@ -5,24 +5,9 @@ require 'rspec/core/rake_task'
|
|
|
5
5
|
require 'rake/testtask'
|
|
6
6
|
require 'appraisal'
|
|
7
7
|
|
|
8
|
-
Bundler::GemHelper.install_tasks(:
|
|
9
|
-
Bundler::GemHelper.install_tasks(:name => 'audited-activerecord')
|
|
10
|
-
Bundler::GemHelper.install_tasks(:name => 'audited-mongo_mapper')
|
|
8
|
+
Bundler::GemHelper.install_tasks(name: 'audited')
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ADAPTERS.each do |adapter|
|
|
15
|
-
desc "Run RSpec code examples for #{adapter} adapter"
|
|
16
|
-
RSpec::Core::RakeTask.new(adapter) do |t|
|
|
17
|
-
t.pattern = "spec/audited/adapters/#{adapter}/**/*_spec.rb"
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
task :spec do
|
|
22
|
-
ADAPTERS.each do |adapter|
|
|
23
|
-
Rake::Task[adapter].invoke
|
|
24
|
-
end
|
|
25
|
-
end
|
|
10
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
26
11
|
|
|
27
12
|
Rake::TestTask.new do |t|
|
|
28
13
|
t.libs << "test"
|
|
@@ -30,4 +15,4 @@ Rake::TestTask.new do |t|
|
|
|
30
15
|
t.verbose = true
|
|
31
16
|
end
|
|
32
17
|
|
|
33
|
-
task :
|
|
18
|
+
task default: [:spec, :test]
|
data/gemfiles/rails40.gemfile
CHANGED
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
-
gem "sqlite3", "~> 1.2"
|
|
6
|
-
gem "mysql2", "~> 0.3.0"
|
|
7
|
-
gem "pg", "~> 0.17"
|
|
8
|
-
gem "bson_ext", "~> 1.6"
|
|
9
5
|
gem "rails", "~> 4.0.0"
|
|
10
|
-
gem "
|
|
6
|
+
gem "protected_attributes"
|
|
11
7
|
gem "test-unit"
|
|
12
8
|
|
|
13
9
|
gemspec :name => "audited", :path => "../"
|
data/gemfiles/rails41.gemfile
CHANGED
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
-
gem "sqlite3", "~> 1.2"
|
|
6
|
-
gem "mysql2", "~> 0.3.0"
|
|
7
|
-
gem "pg", "~> 0.17"
|
|
8
|
-
gem "bson_ext", "~> 1.6"
|
|
9
5
|
gem "rails", "~> 4.1.0"
|
|
10
|
-
gem "
|
|
6
|
+
gem "protected_attributes"
|
|
11
7
|
|
|
12
8
|
gemspec :name => "audited", :path => "../"
|
data/gemfiles/rails42.gemfile
CHANGED
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
source "https://rubygems.org"
|
|
4
4
|
|
|
5
|
-
gem "sqlite3", "~> 1.2"
|
|
6
|
-
gem "mysql2", "~> 0.4.0"
|
|
7
|
-
gem "pg", "~> 0.17"
|
|
8
|
-
gem "bson_ext", "~> 1.6"
|
|
9
5
|
gem "rails", "~> 4.2.0"
|
|
10
|
-
gem "
|
|
6
|
+
gem "protected_attributes"
|
|
11
7
|
|
|
12
8
|
gemspec :name => "audited", :path => "../"
|