audited 4.7.0 → 4.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6a2d5a695157822691d7e8a980742c9dab27769c
4
- data.tar.gz: 41262a1baa392f65fd172c6971985ca43ab53e92
2
+ SHA256:
3
+ metadata.gz: 91cd155edfaec5e9cbe81994bdc5e12e8fd91b58886d8397a6f310ddade5ae03
4
+ data.tar.gz: 5d7b4f209cf8d8803dff66e4f19b8f85c586373ea757f1e84c1422d56feee1c0
5
5
  SHA512:
6
- metadata.gz: f4d0ebf2b9683b96d7954efb7e2ddab5c21e3c0cea29d9d7388334a9f9215f8729b337c850f60abf9b9084773158609d32e99ab580aec244393dc79d41846fad
7
- data.tar.gz: 32a48ffa57d8ebd24ece8714b4c26c8c0a0af4ed7021f165a625a619c058c71749510e20417e9a15629385e72b999409b39186e050af10f5cf73ad36760b25b5
6
+ metadata.gz: 48bab7914ba66c2e7e82bf1bb6936b113b4536ab1297e9d8cdad80036788506bc825594daf37d308b8acbff3321e7ea1936fe6bdb3481f48f311a8caaec9e4ec
7
+ data.tar.gz: f30cdcce78fd2c9202d3147af5d6e6844fb77f5e81300b79261d29f0d931580e67dd3bb04799d0247d3a8b4893314996a05d3ff25d477c43dbc3cf713ecd59fd
data/.gitignore CHANGED
@@ -9,7 +9,6 @@
9
9
  .ruby-version
10
10
  .rvmrc
11
11
  .yardoc
12
- coverage/
13
12
  doc/
14
13
  Gemfile.lock
15
14
  gemfiles/*.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+ TargetRubyVersion: 2.3
4
+ Exclude:
5
+ - lib/generators/audited/templates/**/*
6
+ - vendor/bundle/**/*
7
+ - gemfiles/vendor/bundle/**/*
8
+
9
+ Bundler/OrderedGems:
10
+ Enabled: false
11
+
12
+ Gemspec/OrderedDependencies:
13
+ Enabled: false
14
+
15
+ Layout:
16
+ Enabled: false
17
+
18
+ Metrics:
19
+ Enabled: false
20
+
21
+ Naming:
22
+ Enabled: false
23
+
24
+ Style:
25
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,11 +1,10 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.1
5
- - 2.2.9
6
- - 2.3.6
7
- - 2.4.3
8
- - 2.5.0
4
+ - 2.3.7
5
+ - 2.4.4
6
+ - 2.5.1
7
+ - 2.6.3
9
8
  - ruby-head
10
9
  env:
11
10
  - DB=SQLITE
@@ -13,44 +12,45 @@ env:
13
12
  - DB=MYSQL
14
13
  addons:
15
14
  postgresql: "9.4"
15
+ services:
16
+ - mysql
16
17
  before_install:
17
18
  # https://github.com/travis-ci/travis-ci/issues/8978
18
19
  - "travis_retry gem update --system"
19
- - "travis_retry gem install bundler"
20
+ # Rails 4.2 has a bundler 1.x requirement
21
+ - if [ $BUNDLE_GEMFILE = $PWD/gemfiles/rails42.gemfile ]; then
22
+ rvm @global do gem uninstall bundler -a -x;
23
+ travis_retry gem install -v '< 2.0.0' bundler;
24
+ else
25
+ travis_retry gem install bundler;
26
+ fi
20
27
  gemfile:
21
- - gemfiles/rails40.gemfile
22
- - gemfiles/rails41.gemfile
23
28
  - gemfiles/rails42.gemfile
24
29
  - gemfiles/rails50.gemfile
25
30
  - gemfiles/rails51.gemfile
26
31
  - gemfiles/rails52.gemfile
32
+ - gemfiles/rails60.gemfile
27
33
  matrix:
28
- allow_failures:
29
- - rvm: ruby-head
34
+ include:
35
+ - rvm: 2.6.3
36
+ script: bundle exec rubocop --parallel
37
+ env: DB=rubocop # make travis build display nicer
30
38
  exclude:
31
- - rvm: 2.1
32
- gemfile: gemfiles/rails50.gemfile
33
- - rvm: 2.1
34
- gemfile: gemfiles/rails51.gemfile
35
- - rvm: 2.1
36
- gemfile: gemfiles/rails52.gemfile
37
- - rvm: 2.4.3
38
- gemfile: gemfiles/rails40.gemfile
39
- - rvm: 2.4.3
40
- gemfile: gemfiles/rails41.gemfile
41
- - rvm: 2.5.0
42
- gemfile: gemfiles/rails40.gemfile
43
- - rvm: 2.5.0
44
- gemfile: gemfiles/rails41.gemfile
39
+ - rvm: 2.3.7
40
+ gemfile: gemfiles/rails60.gemfile
41
+ - rvm: 2.4.4
42
+ gemfile: gemfiles/rails60.gemfile
43
+ - rvm: 2.6.3
44
+ gemfile: gemfiles/rails42.gemfile
45
45
  - rvm: ruby-head
46
- gemfile: gemfiles/rails40.gemfile
46
+ gemfile: gemfiles/rails42.gemfile
47
+ allow_failures:
47
48
  - rvm: ruby-head
48
- gemfile: gemfiles/rails41.gemfile
49
49
  fast_finish: true
50
50
  branches:
51
51
  only:
52
52
  - master
53
- sudo: false
53
+ - /.*-stable$/
54
54
  notifications:
55
55
  webhooks:
56
56
  urls:
data/Appraisals CHANGED
@@ -1,28 +1,38 @@
1
- appraise 'rails40' do
2
- gem 'rails', '~> 4.0.0'
3
- gem 'protected_attributes'
4
- gem 'test-unit'
5
- end
6
-
7
- appraise 'rails41' do
8
- gem 'rails', '~> 4.1.0'
9
- gem 'protected_attributes'
10
- end
1
+ # Include DB adapters matching the version requirements in
2
+ # rails/activerecord/lib/active_record/connection_adapters/*adapter.rb
11
3
 
12
4
  appraise 'rails42' do
13
5
  gem 'rails', '~> 4.2.0'
14
6
  gem 'protected_attributes'
7
+ gem "mysql2", ">= 0.3.13", "< 0.6.0"
8
+ gem "pg", "~> 0.15"
9
+ gem "sqlite3", "~> 1.3.6"
15
10
  end
16
11
 
17
12
  appraise 'rails50' do
18
13
  gem 'rails', '~> 5.0.0'
14
+ gem "mysql2", ">= 0.3.18", "< 0.6.0"
15
+ gem "pg", ">= 0.18", "< 2.0"
16
+ gem "sqlite3", "~> 1.3.6"
19
17
  end
20
18
 
21
19
  appraise 'rails51' do
22
20
  gem 'rails', '~> 5.1.4'
21
+ gem "mysql2", ">= 0.3.18", "< 0.6.0"
22
+ gem "pg", ">= 0.18", "< 2.0"
23
+ gem "sqlite3", "~> 1.3.6"
23
24
  end
24
25
 
25
26
  appraise 'rails52' do
26
- gem 'rails', '>= 5.2.0.rc1', '< 5.3'
27
- gem 'mysql2', '~> 0.4.4'
27
+ gem 'rails', '>= 5.2.0', '< 5.3'
28
+ gem "mysql2", ">= 0.4.4", "< 0.6.0"
29
+ gem "pg", ">= 0.18", "< 2.0"
30
+ gem "sqlite3", "~> 1.3.6"
31
+ end
32
+
33
+ appraise 'rails60' do
34
+ gem 'rails', '>= 6.0.0.rc1', '< 6.1'
35
+ gem "mysql2", ">= 0.4.4"
36
+ gem "pg", ">= 0.18", "< 2.0"
37
+ gem "sqlite3", "~> 1.4"
28
38
  end
data/CHANGELOG.md CHANGED
@@ -2,6 +2,66 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.9.0 (2019-07-17)
6
+
7
+ Breaking changes
8
+
9
+ - removed block support for `Audit.reconstruct_attributes`
10
+ [#437](https://github.com/collectiveidea/audited/pull/437)
11
+ - removed `audited_columns`, `non_audited_columns`, `auditing_enabled=` instance methods,
12
+ use class methods instead
13
+ [#424](https://github.com/collectiveidea/audited/pull/424)
14
+ - removed rails 4.1 and 4.0 support
15
+ [#431](https://github.com/collectiveidea/audited/pull/431)
16
+
17
+ Added
18
+
19
+ - Add `with_auditing` methods to enable temporarily
20
+ [#502](https://github.com/collectiveidea/audited/pull/502)
21
+ - Add `update_with_comment_only` option to control audit creation with only comments
22
+ [#327](https://github.com/collectiveidea/audited/pull/327)
23
+ - Support for Rails 6.0 and Ruby 2.6
24
+ [#494](https://github.com/collectiveidea/audited/pull/494)
25
+
26
+ Changed
27
+
28
+ - None
29
+
30
+ Fixed
31
+
32
+ - Ensure enum changes are stored consistently
33
+ [#429](https://github.com/collectiveidea/audited/pull/429)
34
+
35
+ ## 4.8.0 (2018-08-19)
36
+
37
+ Breaking changes
38
+
39
+ - None
40
+
41
+ Added
42
+
43
+ - Add ability to globally disable auditing
44
+ [#426](https://github.com/collectiveidea/audited/pull/426)
45
+ - Add `own_and_associated_audits` method to auditable models
46
+ [#428](https://github.com/collectiveidea/audited/pull/428)
47
+ - Ability to nest `as_user` within itself
48
+ [#450](https://github.com/collectiveidea/audited/pull/450)
49
+ - Private methods can now be used for conditional auditing
50
+ [#454](https://github.com/collectiveidea/audited/pull/454)
51
+
52
+ Changed
53
+
54
+ - Add version to `auditable_index`
55
+ [#427](https://github.com/collectiveidea/audited/pull/427)
56
+ - Rename audited resource revision `version` attribute to `audit_version` and deprecate `version` attribute
57
+ [#443](https://github.com/collectiveidea/audited/pull/443)
58
+
59
+ Fixed
60
+
61
+ - None
62
+
63
+ ## 4.7.1 (2018-04-10)
64
+
5
65
  Breaking changes
6
66
 
7
67
  - None
@@ -16,7 +76,7 @@ Changed
16
76
 
17
77
  Fixed
18
78
 
19
- - None
79
+ - Allow use with Rails 5.2 final
20
80
 
21
81
  ## 4.7.0 (2018-03-14)
22
82
 
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
- Audited [![Build Status](https://secure.travis-ci.org/collectiveidea/audited.svg)](http://travis-ci.org/collectiveidea/audited) [![Dependency Status](https://gemnasium.com/collectiveidea/audited.svg)](https://gemnasium.com/collectiveidea/audited)[![Code Climate](https://codeclimate.com/github/collectiveidea/audited.svg)](https://codeclimate.com/github/collectiveidea/audited) [![Security](https://hakiri.io/github/collectiveidea/audited/master.svg)](https://hakiri.io/github/collectiveidea/audited/master)
1
+ Audited [![Build Status](https://secure.travis-ci.org/collectiveidea/audited.svg)](http://travis-ci.org/collectiveidea/audited) [![Code Climate](https://codeclimate.com/github/collectiveidea/audited.svg)](https://codeclimate.com/github/collectiveidea/audited) [![Security](https://hakiri.io/github/collectiveidea/audited/master.svg)](https://hakiri.io/github/collectiveidea/audited/master)
2
2
  =======
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.1, 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 6.0, 5.2, 5.1, 5.0 and 4.2.
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,11 +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.10
15
- * 2.2.9
16
- * 2.3.6
17
- * 2.4.3
18
- * 2.5.0
14
+ * 2.3.7
15
+ * 2.4.4
16
+ * 2.5.1
17
+ * 2.6.3
19
18
 
20
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).
21
20
 
@@ -28,7 +27,7 @@ Audited is currently ActiveRecord-only. In a previous life, Audited worked with
28
27
  Add the gem to your Gemfile:
29
28
 
30
29
  ```ruby
31
- gem "audited", "~> 4.7"
30
+ gem "audited", "~> 4.9"
32
31
  ```
33
32
 
34
33
  Then, from your Rails app directory, create the `audits` table:
@@ -38,7 +37,9 @@ $ rails generate audited:install
38
37
  $ rake db:migrate
39
38
  ```
40
39
 
41
- 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.
40
+ By default changes are stored in YAML format. If you're using PostgreSQL, then you can use `rails generate audited:install --audited-changes-column-type jsonb` (or `json` for MySQL 5.7+ and Rails 5+) to store audit changes natively with database JSON column types.
41
+
42
+ 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.
42
43
 
43
44
  #### Upgrading
44
45
 
@@ -67,7 +68,7 @@ By default, whenever a user is created, updated or destroyed, a new audit is cre
67
68
  ```ruby
68
69
  user = User.create!(name: "Steve")
69
70
  user.audits.count # => 1
70
- user.update_attributes!(name: "Ryan")
71
+ user.update!(name: "Ryan")
71
72
  user.audits.count # => 2
72
73
  user.destroy
73
74
  user.audits.count # => 3
@@ -76,7 +77,7 @@ user.audits.count # => 3
76
77
  Audits contain information regarding what action was taken on the model and what changes were made.
77
78
 
78
79
  ```ruby
79
- user.update_attributes!(name: "Ryan")
80
+ user.update!(name: "Ryan")
80
81
  audit = user.audits.last
81
82
  audit.action # => "update"
82
83
  audit.audited_changes # => {"name"=>["Steve", "Ryan"]}
@@ -130,7 +131,7 @@ end
130
131
  You can attach comments to each audit using an `audit_comment` attribute on your model.
131
132
 
132
133
  ```ruby
133
- user.update_attributes!(name: "Ryan", audit_comment: "Changing name, just because")
134
+ user.update!(name: "Ryan", audit_comment: "Changing name, just because")
134
135
  user.audits.last.comment # => "Changing name, just because"
135
136
  ```
136
137
 
@@ -142,6 +143,14 @@ class User < ActiveRecord::Base
142
143
  end
143
144
  ```
144
145
 
146
+ You can update an audit if only audit_comment is present. You can optionally add the `:update_with_comment_only` option set to `false` to your `audited` call to turn this behavior off for all audits.
147
+
148
+ ```ruby
149
+ class User < ActiveRecord::Base
150
+ audited :update_with_comment_only => false
151
+ end
152
+ ```
153
+
145
154
  ### Limiting stored audits
146
155
 
147
156
  You can limit the number of audits stored for your model. To configure limiting for all audited models, put the following in an initializer:
@@ -163,7 +172,7 @@ Whenever an object is updated or destroyed, extra audits are combined with newer
163
172
  ```ruby
164
173
  user = User.create!(name: "Steve")
165
174
  user.audits.count # => 1
166
- user.update_attributes!(name: "Ryan")
175
+ user.update!(name: "Ryan")
167
176
  user.audits.count # => 2
168
177
  user.destroy
169
178
  user.audits.count # => 2
@@ -193,16 +202,16 @@ Outside of a request, Audited can still record the user with the `as_user` metho
193
202
 
194
203
  ```ruby
195
204
  Audited.audit_class.as_user(User.find(1)) do
196
- post.update_attribute!(title: "Hello, world!")
205
+ post.update!(title: "Hello, world!")
197
206
  end
198
207
  post.audits.last.user # => #<User id: 1>
199
208
  ```
200
209
 
201
210
  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.)
202
211
 
203
- #### Custom Auditor
212
+ #### Custom Audit User
204
213
 
205
- You might need to use a custom auditor from time to time. It can be done by simply passing in a string:
214
+ You might need to use a custom auditor from time to time. This can be done by simply passing in a string:
206
215
 
207
216
  ```ruby
208
217
  class ApplicationController < ActionController::Base
@@ -216,6 +225,15 @@ class ApplicationController < ActionController::Base
216
225
  end
217
226
  ```
218
227
 
228
+ `as_user` also accepts a string, which can be useful for auditing updates made in a CLI environment:
229
+
230
+ ```rb
231
+ Audited.audit_class.as_user("console-user-#{ENV['SSH_USER']}") do
232
+ post.update_attributes!(title: "Hello, world!")
233
+ end
234
+ post.audits.last.user # => 'console-user-username'
235
+ ```
236
+
219
237
  ### Associated Audits
220
238
 
221
239
  Sometimes it's useful to associate an audit with a model other than the one being changed. For instance, given the following models:
@@ -250,11 +268,16 @@ Now, when an audit is created for a user, that user's company is also saved alon
250
268
  ```ruby
251
269
  company = Company.create!(name: "Collective Idea")
252
270
  user = company.users.create!(name: "Steve")
253
- user.update_attribute!(name: "Steve Richert")
271
+ user.update!(name: "Steve Richert")
254
272
  user.audits.last.associated # => #<Company name: "Collective Idea">
255
273
  company.associated_audits.last.auditable # => #<User name: "Steve Richert">
256
274
  ```
257
275
 
276
+ You can access records' own audits and associated audits in one go:
277
+ ```ruby
278
+ company.own_and_associated_audits
279
+ ```
280
+
258
281
  ### Conditional auditing
259
282
 
260
283
  If you want to audit only under specific conditions, you can provide conditional options (similar to ActiveModel callbacks) that will ensure your model is only audited for these conditions.
@@ -312,6 +335,29 @@ To disable auditing on an entire model:
312
335
  User.auditing_enabled = false
313
336
  ```
314
337
 
338
+ To disable auditing on all models:
339
+
340
+ ```ruby
341
+ Audited.auditing_enabled = false
342
+ ```
343
+
344
+ If you have auditing disabled by default on your model you can enable auditing
345
+ temporarily.
346
+
347
+ ```ruby
348
+ User.auditing_enabled = false
349
+ @user.save_with_auditing
350
+ ```
351
+
352
+ or:
353
+
354
+ ```ruby
355
+ User.auditing_enabled = false
356
+ @user.with_auditing do
357
+ @user.save
358
+ end
359
+ ```
360
+
315
361
  ### Custom `Audit` model
316
362
 
317
363
  If you want to extend or modify the audit model, create a new class that
@@ -4,5 +4,8 @@ source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 4.2.0"
6
6
  gem "protected_attributes"
7
+ gem "mysql2", ">= 0.3.13", "< 0.6.0"
8
+ gem "pg", "~> 0.15"
9
+ gem "sqlite3", "~> 1.3.6"
7
10
 
8
11
  gemspec name: "audited", path: "../"
@@ -3,5 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.0.0"
6
+ gem "mysql2", ">= 0.3.18", "< 0.6.0"
7
+ gem "pg", ">= 0.18", "< 2.0"
8
+ gem "sqlite3", "~> 1.3.6"
6
9
 
7
10
  gemspec name: "audited", path: "../"
@@ -3,5 +3,8 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "rails", "~> 5.1.4"
6
+ gem "mysql2", ">= 0.3.18", "< 0.6.0"
7
+ gem "pg", ">= 0.18", "< 2.0"
8
+ gem "sqlite3", "~> 1.3.6"
6
9
 
7
10
  gemspec name: "audited", path: "../"
@@ -2,7 +2,9 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", ">= 5.2.0.rc1", "< 5.3"
6
- gem "mysql2", "~> 0.4.4"
5
+ gem "rails", ">= 5.2.0", "< 5.3"
6
+ gem "mysql2", ">= 0.4.4", "< 0.6.0"
7
+ gem "pg", ">= 0.18", "< 2.0"
8
+ gem "sqlite3", "~> 1.3.6"
7
9
 
8
10
  gemspec name: "audited", path: "../"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", ">= 6.0.0.rc1", "< 6.1"
6
+ gem "mysql2", ">= 0.4.4"
7
+ gem "pg", ">= 0.18", "< 2.0"
8
+ gem "sqlite3", "~> 1.4"
9
+
10
+ gemspec name: "audited", path: "../"
data/lib/audited/audit.rb CHANGED
@@ -65,7 +65,7 @@ module Audited
65
65
  def revision
66
66
  clazz = auditable_type.constantize
67
67
  (clazz.find_by_id(auditable_id) || clazz.new).tap do |m|
68
- self.class.assign_revision_attributes(m, self.class.reconstruct_attributes(ancestors).merge(version: version))
68
+ self.class.assign_revision_attributes(m, self.class.reconstruct_attributes(ancestors).merge(audit_version: version))
69
69
  end
70
70
  end
71
71
 
@@ -88,20 +88,18 @@ module Audited
88
88
 
89
89
  # Allows user to undo changes
90
90
  def undo
91
- model = self.auditable_type.constantize
92
- if action == 'create'
91
+ case action
92
+ when 'create'
93
93
  # destroys a newly created record
94
- model.find(auditable_id).destroy!
95
- elsif action == 'destroy'
94
+ auditable.destroy!
95
+ when 'destroy'
96
96
  # creates a new record with the destroyed record attributes
97
- model.create(audited_changes)
98
- else
97
+ auditable_type.constantize.create!(audited_changes)
98
+ when 'update'
99
99
  # changes back attributes
100
- audited_object = model.find(auditable_id)
101
- self.audited_changes.each do |k, v|
102
- audited_object[k] = v[0]
103
- end
104
- audited_object.save
100
+ auditable.update!(audited_changes.transform_values(&:first))
101
+ else
102
+ raise StandardError, "invalid action given #{action}"
105
103
  end
106
104
  end
107
105
 
@@ -132,21 +130,20 @@ module Audited
132
130
  # All audits made during the block called will be recorded as made
133
131
  # by +user+. This method is hopefully threadsafe, making it ideal
134
132
  # for background operations that require audit information.
135
- def self.as_user(user, &block)
133
+ def self.as_user(user)
134
+ last_audited_user = ::Audited.store[:audited_user]
136
135
  ::Audited.store[:audited_user] = user
137
136
  yield
138
137
  ensure
139
- ::Audited.store[:audited_user] = nil
138
+ ::Audited.store[:audited_user] = last_audited_user
140
139
  end
141
140
 
142
141
  # @private
143
142
  def self.reconstruct_attributes(audits)
144
- attributes = {}
145
- result = audits.collect do |audit|
146
- attributes.merge!(audit.new_attributes)[:version] = audit.version
147
- yield attributes if block_given?
148
- end
149
- block_given? ? result : attributes
143
+ audits.each_with_object({}) do |audit, all|
144
+ all.merge!(audit.new_attributes)
145
+ all[:audit_version] = audit.version
146
+ end
150
147
  end
151
148
 
152
149
  # @private
@@ -164,14 +161,14 @@ module Audited
164
161
  end
165
162
 
166
163
  # use created_at as timestamp cache key
167
- def self.collection_cache_key(collection = all, timestamp_column = :created_at)
164
+ def self.collection_cache_key(collection = all, *)
168
165
  super(collection, :created_at)
169
166
  end
170
167
 
171
168
  private
172
169
 
173
170
  def set_version_number
174
- max = self.class.auditable_finder(auditable_id, auditable_type).descending.first.try(:version) || 0
171
+ max = self.class.auditable_finder(auditable_id, auditable_type).maximum(:version) || 0
175
172
  self.version = max + 1
176
173
  end
177
174