audited 4.3.0 → 4.6.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of audited might be problematic. Click here for more details.

Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +19 -2
  3. data/Appraisals +8 -2
  4. data/CHANGELOG.md +260 -0
  5. data/README.md +32 -12
  6. data/gemfiles/rails40.gemfile +1 -1
  7. data/gemfiles/rails41.gemfile +1 -1
  8. data/gemfiles/rails42.gemfile +1 -1
  9. data/gemfiles/rails50.gemfile +1 -2
  10. data/gemfiles/rails51.gemfile +7 -0
  11. data/gemfiles/rails52.gemfile +8 -0
  12. data/lib/audited.rb +6 -4
  13. data/lib/audited/audit.rb +57 -8
  14. data/lib/audited/auditor.rb +54 -59
  15. data/lib/audited/rspec_matchers.rb +2 -2
  16. data/lib/audited/sweeper.rb +18 -29
  17. data/lib/audited/version.rb +1 -1
  18. data/lib/generators/audited/install_generator.rb +5 -0
  19. data/lib/generators/audited/migration_helper.rb +9 -0
  20. data/lib/generators/audited/templates/add_association_to_audits.rb +1 -1
  21. data/lib/generators/audited/templates/add_comment_to_audits.rb +1 -1
  22. data/lib/generators/audited/templates/add_remote_address_to_audits.rb +1 -1
  23. data/lib/generators/audited/templates/add_request_uuid_to_audits.rb +1 -1
  24. data/lib/generators/audited/templates/install.rb +5 -5
  25. data/lib/generators/audited/templates/rename_association_to_associated.rb +1 -1
  26. data/lib/generators/audited/templates/rename_changes_to_audited_changes.rb +1 -1
  27. data/lib/generators/audited/templates/rename_parent_to_association.rb +1 -1
  28. data/lib/generators/audited/templates/revert_polymorphic_indexes_order.rb +20 -0
  29. data/lib/generators/audited/upgrade_generator.rb +7 -0
  30. data/spec/audited/audit_spec.rb +71 -2
  31. data/spec/audited/auditor_spec.rb +69 -3
  32. data/spec/audited/sweeper_spec.rb +24 -6
  33. data/spec/audited_spec_helpers.rb +1 -1
  34. data/spec/spec_helper.rb +1 -1
  35. data/spec/support/active_record/models.rb +2 -1
  36. data/spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb +12 -0
  37. data/spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb +12 -0
  38. data/spec/support/active_record/schema.rb +1 -0
  39. data/test/install_generator_test.rb +49 -3
  40. data/test/upgrade_generator_test.rb +16 -1
  41. metadata +14 -22
  42. data/CHANGELOG +0 -34
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b04e8c93cc4b6351654924948b663708433e8a01
4
- data.tar.gz: ce147cca64fde0e62e06bd7235851a907ec4ccb5
3
+ metadata.gz: 11243e8bfb9c50162f0f939a283270f7bf706387
4
+ data.tar.gz: 9b081dea623844e1bd37b71f774490dc8596ef84
5
5
  SHA512:
6
- metadata.gz: f9fc970bef11b25088cc77123857efad07fb319b84a82696e6f195cce0b9cb1c90cac1a3b0330e57143a61b8a38d9973b13a9618421adeebae030f8f483a9f42
7
- data.tar.gz: a7841493a1889185d35c323287d98fd9ca332a91fa18f5d751fcff77508baafb5a2e1a5056eeeb1d6e5fd8efe3d9f13aa407403c85038303642dbd631c7817f9
6
+ metadata.gz: f5ca8463b13d3c2fc463749a1ff46c1522b5ed6c049dd743e72d47577c5da025f46f3ab90492fa19a88cfbf7cd38ee302e2aefced16098dcd3bd7846a6be0eb9
7
+ data.tar.gz: e4e5b349f6a8db618deb7a6fd48a853eb75729ddbff3b78c431c89247ec17aaceb2e4a67dd206defbfeb5fe4e8b6a47c4af0212c5898fd777848c08625aca90e
@@ -2,24 +2,41 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
4
  - 2.1
5
- - 2.2.4
6
- - 2.3.1
5
+ - 2.2.8
6
+ - 2.3.5
7
+ - 2.4.2
7
8
  - ruby-head
8
9
  env:
9
10
  - DB=SQLITE
10
11
  - DB=POSTGRES
11
12
  - DB=MYSQL
13
+ addons:
14
+ postgresql: "9.4"
12
15
  gemfile:
13
16
  - gemfiles/rails40.gemfile
14
17
  - gemfiles/rails41.gemfile
15
18
  - gemfiles/rails42.gemfile
16
19
  - gemfiles/rails50.gemfile
20
+ - gemfiles/rails51.gemfile
21
+ - gemfiles/rails52.gemfile
17
22
  matrix:
18
23
  allow_failures:
19
24
  - rvm: ruby-head
20
25
  exclude:
21
26
  - rvm: 2.1
22
27
  gemfile: gemfiles/rails50.gemfile
28
+ - rvm: 2.1
29
+ gemfile: gemfiles/rails51.gemfile
30
+ - rvm: 2.1
31
+ gemfile: gemfiles/rails52.gemfile
32
+ - rvm: 2.4.2
33
+ gemfile: gemfiles/rails40.gemfile
34
+ - rvm: 2.4.2
35
+ gemfile: gemfiles/rails41.gemfile
36
+ - rvm: ruby-head
37
+ gemfile: gemfiles/rails40.gemfile
38
+ - rvm: ruby-head
39
+ gemfile: gemfiles/rails41.gemfile
23
40
  fast_finish: true
24
41
  branches:
25
42
  only:
data/Appraisals CHANGED
@@ -16,7 +16,13 @@ end
16
16
 
17
17
  appraise 'rails50' do
18
18
  gem 'rails', '~> 5.0.0'
19
+ end
20
+
21
+ appraise 'rails51' do
22
+ gem 'rails', '~> 5.1.4'
23
+ end
19
24
 
20
- # The following needs to point to Github until the release of 0.1.3
21
- gem 'rails-observers', github: 'rails/rails-observers', branch: 'master'
25
+ appraise 'rails52' do
26
+ gem 'rails', '>= 5.2.0.beta2', '< 5.3'
27
+ gem 'mysql2', '~> 0.4.4'
22
28
  end
@@ -0,0 +1,260 @@
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
+
22
+ ## 4.6.0 (2018-01-10)
23
+
24
+ Breaking changes
25
+
26
+ - None
27
+
28
+ Added
29
+
30
+ - Add functionality to undo specific audit
31
+ [#381](https://github.com/collectiveidea/audited/pull/381)
32
+
33
+ Changed
34
+
35
+ - Removed duplicate declaration of `non_audited_columns` method
36
+ [#365](https://github.com/collectiveidea/audited/pull/365)
37
+ - Updated `audited_changes` calculation to support Rails>=5.1 change syntax
38
+ [#377](https://github.com/collectiveidea/audited/pull/377)
39
+ - Improve index ordering for polymorphic indexes
40
+ [#385](https://github.com/collectiveidea/audited/pull/385)
41
+ - Update CI to test on newer versions of Ruby and Rails
42
+ [#386](https://github.com/collectiveidea/audited/pull/386)
43
+ [#387](https://github.com/collectiveidea/audited/pull/387)
44
+ [#388](https://github.com/collectiveidea/audited/pull/388)
45
+ - Simplify `audited_columns` calculation
46
+ [#391](https://github.com/collectiveidea/audited/pull/391)
47
+ - Simplify `audited_changes` calculation
48
+ [#389](https://github.com/collectiveidea/audited/pull/389)
49
+ - Normalize options passed to `audited` method
50
+ [#397](https://github.com/collectiveidea/audited/pull/397)
51
+
52
+ Fixed
53
+
54
+ - Fixed typo in rspec causing incorrect test failure
55
+ [#360](https://github.com/collectiveidea/audited/pull/360)
56
+ - Allow running specs using rake
57
+ [#390](https://github.com/collectiveidea/audited/pull/390)
58
+ - Passing an invalid version to `revision` returns `nil` instead of last version
59
+ [#384](https://github.com/collectiveidea/audited/pull/384)
60
+ - Fix duplicate deceleration warnings
61
+ [#399](https://github.com/collectiveidea/audited/pull/399)
62
+
63
+
64
+ ## 4.5.0 (2017-05-22)
65
+
66
+ Breaking changes
67
+
68
+ - None
69
+
70
+ Added
71
+
72
+ - Support for `user_id` column to be a `uuid` type
73
+ [#333](https://github.com/collectiveidea/audited/pull/333)
74
+
75
+ Fixed
76
+
77
+ - Fix retrieval of user from controller when populated in before callbacks
78
+ [#336](https://github.com/collectiveidea/audited/issues/336)
79
+ - Fix column type check in serializer for Oracle DB adapter
80
+ [#335](https://github.com/collectiveidea/audited/pull/335)
81
+ - Fix `non_audited_columns` to allow symbol names
82
+ [#351](https://github.com/collectiveidea/audited/pull/351)
83
+
84
+ ## 4.4.1 (2017-03-29)
85
+
86
+ Fixed
87
+
88
+ - Fix ActiveRecord gem dependency to permit 5.1
89
+ [#332](https://github.com/collectiveidea/audited/pull/332)
90
+
91
+ ## 4.4.0 (2017-03-29)
92
+
93
+ Breaking changes
94
+
95
+ - None
96
+
97
+ Added
98
+
99
+ - Support for `audited_changes` to be a `json` or `jsonb` column in PostgreSQL
100
+ [#216](https://github.com/collectiveidea/audited/issues/216)
101
+ - Allow `Audited::Audit` to be subclassed by configuring `Audited.audit_class`
102
+ [#314](https://github.com/collectiveidea/audited/issues/314)
103
+ - Support for Ruby on Rails 5.1
104
+ [#329](https://github.com/collectiveidea/audited/issues/329)
105
+ - Support for Ruby 2.4
106
+ [#329](https://github.com/collectiveidea/audited/issues/329)
107
+
108
+ Changed
109
+
110
+ - Remove rails-observer dependency
111
+ [#325](https://github.com/collectiveidea/audited/issues/325)
112
+ - Undeprecated `Audited.audit_class` reader
113
+ [#314](https://github.com/collectiveidea/audited/issues/314)
114
+
115
+ Fixed
116
+
117
+ - SQL error in Rails Conditional GET (304 caching)
118
+ [#295](https://github.com/collectiveidea/audited/pull/295)
119
+ - Fix missing non_audited_columns= configuration setter
120
+ [#320](https://github.com/collectiveidea/audited/issues/320)
121
+ - Fix migration generators to specify AR migration version
122
+ [#329](https://github.com/collectiveidea/audited/issues/329)
123
+
124
+ ## 4.3.0 (2016-09-17)
125
+
126
+ Breaking changes
127
+
128
+ - None
129
+
130
+ Added
131
+
132
+ - Support singular arguments for options: `on` and `only`
133
+
134
+ Fixed
135
+
136
+ - Fix auditing instance attributes if "only" option specified
137
+ - Allow private / protected callback declarations
138
+ - Do not eagerly connect to database
139
+
140
+ ## 4.2.2 (2016-08-01)
141
+
142
+ - Correct auditing_enabled for STI models
143
+ - Properly set table name for mongomapper
144
+
145
+ ## 4.2.1 (2016-07-29)
146
+
147
+ - Fix bug when only: is a single field.
148
+ - update gemspec to use mongomapper 0.13
149
+ - sweeper need not run observer for mongomapper
150
+ - Make temporary disabling of auditing threadsafe
151
+ - Centralize `Audited.store` as thread safe variable store
152
+
153
+ ## 4.2.0 (2015-03-31)
154
+
155
+ Not yet documented.
156
+
157
+ ## 4.0.0 (2014-09-04)
158
+
159
+ Not yet documented.
160
+
161
+ ## 4.0.0.rc1 (2014-07-30)
162
+
163
+ Not yet documented.
164
+
165
+ ## 3.0.0 (2012-09-25)
166
+
167
+ Not yet documented.
168
+
169
+ ## 3.0.0.rc2 (2012-07-09)
170
+
171
+ Not yet documented.
172
+
173
+ ## 3.0.0.rc1 (2012-04-25)
174
+
175
+ Not yet documented.
176
+
177
+ ## 2012-04-10
178
+
179
+ - Add Audit scopes for creates, updates and destroys [chriswfx]
180
+
181
+ ## 2011-10-25
182
+
183
+ - Made ignored_attributes configurable [senny]
184
+
185
+ ## 2011-09-09
186
+
187
+ - Rails 3.x support
188
+ - Support for associated audits
189
+ - Support for remote IP address storage
190
+ - Plenty of bug fixes and refactoring
191
+ - [kennethkalmer, ineu, PatrickMa, jrozner, dwarburton, bsiggelkow, dgm]
192
+
193
+ ## 2009-01-27
194
+
195
+ - Store old and new values for updates, and store all attributes on destroy.
196
+ - Refactored revisioning methods to work as expected
197
+
198
+ ## 2008-10-10
199
+
200
+ - changed to make it work in development mode
201
+
202
+ ## 2008-09-24
203
+
204
+ - Add ability to record parent record of the record being audited [Kenneth Kalmer]
205
+
206
+ ## 2008-04-19
207
+
208
+ - refactored to make compatible with dirty tracking in edge rails
209
+ and to stop storing both old and new values in a single audit
210
+
211
+ ## 2008-04-18
212
+
213
+ - Fix NoMethodError when trying to access the :previous revision
214
+ on a model that doesn't have previous revisions [Alex Soto]
215
+
216
+ ## 2008-03-21
217
+
218
+ - added #changed_attributes to get access to the changes before a
219
+ save [Chris Parker]
220
+
221
+ ## 2007-12-16
222
+
223
+ - Added #revision_at for retrieving a revision from a specific
224
+ time [Jacob Atzen]
225
+
226
+ ## 2007-12-16
227
+
228
+ - Fix error when getting revision from audit with no changes
229
+ [Geoffrey Wiseman]
230
+
231
+ ## 2007-12-16
232
+
233
+ - Remove dependency on acts_as_list
234
+
235
+ ## 2007-06-17
236
+
237
+ - Added support getting previous revisions
238
+
239
+ ## 2006-11-17
240
+
241
+ - Replaced use of singleton User.current_user with cache sweeper
242
+ implementation for auditing the user that made the change
243
+
244
+ ## 2006-11-17
245
+
246
+ - added migration generator
247
+
248
+ ## 2006-08-14
249
+
250
+ - incorporated changes from Michael Schuerig to write_attribute
251
+ that saves the new value after every change and not just the
252
+ first, and performs proper type-casting before doing comparisons
253
+
254
+ ## 2006-08-14
255
+
256
+ - The "changes" are now saved as a serialized hash
257
+
258
+ ## 2006-07-21
259
+
260
+ - initial version
data/README.md CHANGED
@@ -3,7 +3,7 @@ Audited [![Build Status](https://secure.travis-ci.org/collectiveidea/audited.svg
3
3
 
4
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 5.0 and 4.2. It may work with 4.1 and 4.0, but this is not guaranteed.
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
7
 
8
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).
9
9
 
@@ -11,9 +11,10 @@ For Rails 3, use gem version 3.0 or see the [3.0-stable branch](https://github.c
11
11
 
12
12
  Audited supports and is [tested against](http://travis-ci.org/collectiveidea/audited) the following Ruby versions:
13
13
 
14
- * 2.1.5
15
- * 2.2.4
16
- * 2.3.1
14
+ * 2.1.10
15
+ * 2.2.8
16
+ * 2.3.5
17
+ * 2.4.2
17
18
 
18
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).
19
20
 
@@ -26,12 +27,7 @@ Audited is currently ActiveRecord-only. In a previous life, Audited worked with
26
27
  Add the gem to your Gemfile:
27
28
 
28
29
  ```ruby
29
- gem "audited", "~> 4.3"
30
- ```
31
-
32
- If you are using rails 5.0, you would also need the following line in your Gemfile.
33
- ```ruby
34
- gem "rails-observers", github: 'rails/rails-observers'
30
+ gem "audited", "~> 4.6"
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. If you're using something other than integer primary keys (e.g. UUID) for your User model, then you can use `rails generate audited:install --audited-user-id-column-type uuid` to customize the `audits` table `user_id` column type.
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:
@@ -166,12 +164,14 @@ Audited.current_user_method = :authenticated_user
166
164
  Outside of a request, Audited can still record the user with the `as_user` method:
167
165
 
168
166
  ```ruby
169
- Audited::Audit.as_user(User.find(1)) do
167
+ Audited.audit_class.as_user(User.find(1)) do
170
168
  post.update_attribute!(title: "Hello, world!")
171
169
  end
172
170
  post.audits.last.user # => #<User id: 1>
173
171
  ```
174
172
 
173
+ The standard Audited install assumes your User model has an integer primary key type. If this isn't true (e.g. you're using UUID primary keys), you'll need to create a migration to update the `audits` table `user_id` column type. (See Installation above for generator flags if you'd like to regenerate the install migration.)
174
+
175
175
  #### Custom Auditor
176
176
 
177
177
  You might need to use a custom auditor from time to time. It can be done by simply passing in a string:
@@ -217,7 +217,7 @@ class Company < ActiveRecord::Base
217
217
  end
218
218
  ```
219
219
 
220
- Now, when a 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.
220
+ 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.
221
221
 
222
222
  ```ruby
223
223
  company = Company.create!(name: "Collective Idea")
@@ -258,6 +258,26 @@ To disable auditing on an entire model:
258
258
  User.auditing_enabled = false
259
259
  ```
260
260
 
261
+ ### Custom `Audit` model
262
+
263
+ If you want to extend or modify the audit model, create a new class that
264
+ inherits from `Audited::Audit`:
265
+ ```ruby
266
+ class CustomAudit < Audited::Audit
267
+ def some_custom_behavior
268
+ "Hiya!"
269
+ end
270
+ end
271
+ ```
272
+ Then set it in an initializer:
273
+ ```ruby
274
+ # config/initializers/audited.rb
275
+
276
+ Audited.config do |config|
277
+ config.audit_class = CustomAudit
278
+ end
279
+ ```
280
+
261
281
  ## Gotchas
262
282
 
263
283
  ### Using attr_protected with Rails 4.x
@@ -6,4 +6,4 @@ gem "rails", "~> 4.0.0"
6
6
  gem "protected_attributes"
7
7
  gem "test-unit"
8
8
 
9
- gemspec :name => "audited", :path => "../"
9
+ gemspec name: "audited", path: "../"
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  gem "rails", "~> 4.1.0"
6
6
  gem "protected_attributes"
7
7
 
8
- gemspec :name => "audited", :path => "../"
8
+ gemspec name: "audited", path: "../"
@@ -5,4 +5,4 @@ source "https://rubygems.org"
5
5
  gem "rails", "~> 4.2.0"
6
6
  gem "protected_attributes"
7
7
 
8
- gemspec :name => "audited", :path => "../"
8
+ gemspec name: "audited", path: "../"