audited 4.10.0 → 5.2.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 (67) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/buildlight.yml +15 -0
  3. data/.github/workflows/ci.yml +128 -0
  4. data/.standard.yml +5 -0
  5. data/Appraisals +20 -18
  6. data/CHANGELOG.md +90 -1
  7. data/Gemfile +1 -1
  8. data/README.md +52 -14
  9. data/Rakefile +6 -6
  10. data/gemfiles/rails50.gemfile +1 -0
  11. data/gemfiles/rails51.gemfile +1 -0
  12. data/gemfiles/rails52.gemfile +2 -1
  13. data/gemfiles/rails70.gemfile +10 -0
  14. data/lib/audited/audit.rb +24 -25
  15. data/lib/audited/auditor.rb +91 -56
  16. data/lib/audited/railtie.rb +16 -0
  17. data/lib/audited/rspec_matchers.rb +5 -3
  18. data/lib/audited/sweeper.rb +3 -10
  19. data/lib/audited/version.rb +3 -1
  20. data/lib/audited-rspec.rb +3 -1
  21. data/lib/audited.rb +33 -9
  22. data/lib/generators/audited/install_generator.rb +9 -7
  23. data/lib/generators/audited/migration.rb +12 -2
  24. data/lib/generators/audited/migration_helper.rb +3 -1
  25. data/lib/generators/audited/templates/add_association_to_audits.rb +2 -0
  26. data/lib/generators/audited/templates/add_comment_to_audits.rb +2 -0
  27. data/lib/generators/audited/templates/add_remote_address_to_audits.rb +2 -0
  28. data/lib/generators/audited/templates/add_request_uuid_to_audits.rb +2 -0
  29. data/lib/generators/audited/templates/add_version_to_auditable_index.rb +2 -0
  30. data/lib/generators/audited/templates/install.rb +2 -0
  31. data/lib/generators/audited/templates/rename_association_to_associated.rb +2 -0
  32. data/lib/generators/audited/templates/rename_changes_to_audited_changes.rb +2 -0
  33. data/lib/generators/audited/templates/rename_parent_to_association.rb +2 -0
  34. data/lib/generators/audited/templates/revert_polymorphic_indexes_order.rb +2 -0
  35. data/lib/generators/audited/upgrade_generator.rb +16 -14
  36. data/spec/audited/audit_spec.rb +68 -46
  37. data/spec/audited/auditor_spec.rb +310 -253
  38. data/spec/audited/sweeper_spec.rb +19 -19
  39. data/spec/audited_spec.rb +18 -0
  40. data/spec/audited_spec_helpers.rb +5 -7
  41. data/spec/rails_app/app/assets/config/manifest.js +2 -1
  42. data/spec/rails_app/config/application.rb +9 -3
  43. data/spec/rails_app/config/database.yml +3 -2
  44. data/spec/rails_app/config/environment.rb +1 -1
  45. data/spec/rails_app/config/environments/test.rb +10 -5
  46. data/spec/rails_app/config/initializers/secret_token.rb +2 -2
  47. data/spec/spec_helper.rb +14 -14
  48. data/spec/support/active_record/models.rb +24 -12
  49. data/spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb +1 -2
  50. data/spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb +1 -2
  51. data/spec/support/active_record/schema.rb +25 -19
  52. data/test/db/version_1.rb +2 -2
  53. data/test/db/version_2.rb +2 -2
  54. data/test/db/version_3.rb +2 -3
  55. data/test/db/version_4.rb +2 -3
  56. data/test/db/version_5.rb +0 -1
  57. data/test/db/version_6.rb +1 -1
  58. data/test/install_generator_test.rb +18 -19
  59. data/test/test_helper.rb +5 -5
  60. data/test/upgrade_generator_test.rb +13 -18
  61. metadata +31 -31
  62. data/.rubocop.yml +0 -25
  63. data/.travis.yml +0 -63
  64. data/gemfiles/rails42.gemfile +0 -11
  65. data/spec/rails_app/app/controllers/application_controller.rb +0 -2
  66. data/spec/rails_app/config/environments/development.rb +0 -21
  67. data/spec/rails_app/config/environments/production.rb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e774f1f27e84aaa6f3ad9160eaba9b0e5eda0df9202cb5acaf405de13071c4d3
4
- data.tar.gz: affeec219575b7032c73f03d69d839aeb7ad81ab7c53e2e636bea0243d66ac8f
3
+ metadata.gz: 86131fd51439ffb0e1e16fd0b3bdd770c0cdf6de5bc8df5f234377d9ef0aeddb
4
+ data.tar.gz: 4729941ef95dc9e6e542eb705ac12ff4876999c61f210a50d8ef460a02d71078
5
5
  SHA512:
6
- metadata.gz: df852876685671788eeec0cd604a5771ed5bd096d466c10f1b9798774681c03749b2280bf4794d0cef707080c4f2e22464adbb90ac39f077132a0d3630c85c8c
7
- data.tar.gz: bf555f179f6c33d4493aa984c1163e1ae2bcf7985b1ff7fecbe52012b3d2140c364098478aca57817c8991747a4009e4b184e63227621dc752cd8fe5ccf8a516
6
+ metadata.gz: 27d6c2bd685eaca06093e7b8352aa942b83163a09be96fade16cc39ac46502697ca264a54f7a99a4390afe6cc07fbca0d345cb4ad35d7a11d98fa8da9aa262dd
7
+ data.tar.gz: 615ffae5d0fe3a44ffde034ddd60a2074cdff6679b1a8d59b23adfa2fed557023ffd786516997627aaf3de7916c39666d85abd24b38b1562976678472bbc85a9
@@ -0,0 +1,15 @@
1
+ name: Buildlight
2
+
3
+ on:
4
+ workflow_run:
5
+ workflows:
6
+ - CI
7
+ branches:
8
+ - main
9
+
10
+ jobs:
11
+ webhook:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - name: Webhook
15
+ uses: collectiveidea/buildlight@main
@@ -0,0 +1,128 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - main
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1]
16
+ appraisal:
17
+ - rails50
18
+ - rails51
19
+ - rails52
20
+ - rails60
21
+ - rails61
22
+ - rails70
23
+ db: [POSTGRES, MYSQL, SQLITE]
24
+ exclude:
25
+ # MySQL has issues on Ruby 2.3
26
+ # https://github.com/ruby/setup-ruby/issues/150
27
+ - ruby: 2.3
28
+ db: MYSQL
29
+
30
+ # PostgreSQL is segfaulting on 2.3
31
+ # Doesn't seem worth solving.
32
+ - ruby: 2.3
33
+ db: POSTGRES
34
+
35
+ # Rails 5.0 supports Ruby 2.2-2.4
36
+ - appraisal: rails50
37
+ ruby: 2.5
38
+ - appraisal: rails50
39
+ ruby: 2.6
40
+ - appraisal: rails50
41
+ ruby: 2.7
42
+ - appraisal: rails50
43
+ ruby: 3.0
44
+ - appraisal: rails50
45
+ ruby: 3.1
46
+
47
+ # Rails 5.1 supports Ruby 2.2-2.5
48
+ - appraisal: rails51
49
+ ruby: 2.6
50
+ - appraisal: rails51
51
+ ruby: 2.7
52
+ - appraisal: rails51
53
+ ruby: 3.0
54
+ - appraisal: rails51
55
+ ruby: 3.1
56
+
57
+ # Rails 5.2 supports Ruby 2.2-2.5
58
+ - appraisal: rails52
59
+ ruby: 2.6
60
+ - appraisal: rails52
61
+ ruby: 2.7
62
+ - appraisal: rails52
63
+ ruby: 3.0
64
+ - appraisal: rails52
65
+ ruby: 3.1
66
+
67
+ # Rails 6.0 supports Ruby 2.5-2.7
68
+ - appraisal: rails60
69
+ ruby: 2.3
70
+ - appraisal: rails60
71
+ ruby: 2.4
72
+ - appraisal: rails60
73
+ ruby: 3.0
74
+ - appraisal: rails60
75
+ ruby: 3.1
76
+
77
+ # Rails 6.1 supports Ruby 2.5+
78
+ - appraisal: rails61
79
+ ruby: 2.3
80
+ - appraisal: rails61
81
+ ruby: 2.4
82
+
83
+ # Rails 7 supports Ruby 2.7+
84
+ - appraisal: rails70
85
+ ruby: 2.3
86
+ - appraisal: rails70
87
+ ruby: 2.4
88
+ - appraisal: rails70
89
+ ruby: 2.5
90
+ - appraisal: rails70
91
+ ruby: 2.6
92
+
93
+ services:
94
+ postgres:
95
+ image: postgres
96
+ env:
97
+ POSTGRES_USER: postgres
98
+ POSTGRES_PASSWORD: postgres
99
+ POSTGRES_DB: audited_test
100
+ ports:
101
+ - 5432:5432
102
+ # needed because the postgres container does not provide a healthcheck
103
+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
104
+
105
+ env:
106
+ DB_DATABASE: audited_test
107
+ DB_USER: root
108
+ DB_PASSWORD: 'root'
109
+ DB_HOST: localhost
110
+
111
+ steps:
112
+ - name: Setup MySQL
113
+ run: |
114
+ sudo /etc/init.d/mysql start
115
+ mysql -e 'CREATE DATABASE audited_test;' -uroot -proot
116
+ mysql -e 'SHOW DATABASES;' -uroot -proot
117
+ - uses: actions/checkout@v3
118
+ - name: Copy Gemfile
119
+ run: sed 's/\.\././' gemfiles/${{ matrix.appraisal }}.gemfile > Gemfile
120
+ - name: Set up Ruby ${{ matrix.ruby }}
121
+ uses: ruby/setup-ruby@v1
122
+ with:
123
+ ruby-version: ${{ matrix.ruby }}
124
+ bundler-cache: true
125
+ - name: Run tests
126
+ env:
127
+ DB: ${{ matrix.db }}
128
+ run: bundle exec rake
data/.standard.yml ADDED
@@ -0,0 +1,5 @@
1
+ ruby_version: 2.3
2
+ ignore:
3
+ - lib/generators/audited/templates/**/*
4
+ - vendor/bundle/**/*
5
+ - gemfiles/vendor/bundle/**/*
data/Appraisals CHANGED
@@ -1,45 +1,47 @@
1
1
  # Include DB adapters matching the version requirements in
2
2
  # rails/activerecord/lib/active_record/connection_adapters/*adapter.rb
3
3
 
4
- appraise 'rails42' do
5
- gem 'rails', '~> 4.2.0'
6
- gem 'protected_attributes'
7
- gem "mysql2", ">= 0.3.13", "< 0.6.0"
8
- gem "pg", "~> 0.15"
9
- gem "sqlite3", "~> 1.3.6"
10
- end
11
-
12
- appraise 'rails50' do
13
- gem 'rails', '~> 5.0.0'
4
+ appraise "rails50" do
5
+ gem "rails", "~> 5.0.0"
14
6
  gem "mysql2", ">= 0.3.18", "< 0.6.0"
15
7
  gem "pg", ">= 0.18", "< 2.0"
16
8
  gem "sqlite3", "~> 1.3.6"
9
+ gem "psych", "~> 3.1"
17
10
  end
18
11
 
19
- appraise 'rails51' do
20
- gem 'rails', '~> 5.1.4'
12
+ appraise "rails51" do
13
+ gem "rails", "~> 5.1.4"
21
14
  gem "mysql2", ">= 0.3.18", "< 0.6.0"
22
15
  gem "pg", ">= 0.18", "< 2.0"
23
16
  gem "sqlite3", "~> 1.3.6"
17
+ gem "psych", "~> 3.1"
24
18
  end
25
19
 
26
- appraise 'rails52' do
27
- gem 'rails', '>= 5.2.0', '< 5.3'
20
+ appraise "rails52" do
21
+ gem "rails", ">= 5.2.8.1", "< 5.3"
28
22
  gem "mysql2", ">= 0.4.4", "< 0.6.0"
29
23
  gem "pg", ">= 0.18", "< 2.0"
30
24
  gem "sqlite3", "~> 1.3.6"
25
+ gem "psych", "~> 3.1"
31
26
  end
32
27
 
33
- appraise 'rails60' do
34
- gem 'rails', '>= 6.0.0', '< 6.1'
28
+ appraise "rails60" do
29
+ gem "rails", ">= 6.0.0", "< 6.1"
35
30
  gem "mysql2", ">= 0.4.4"
36
31
  gem "pg", ">= 0.18", "< 2.0"
37
32
  gem "sqlite3", "~> 1.4"
38
33
  end
39
34
 
40
- appraise 'rails61' do
41
- gem 'rails', '>= 6.1.0', '< 6.2'
35
+ appraise "rails61" do
36
+ gem "rails", ">= 6.1.0", "< 6.2"
42
37
  gem "mysql2", ">= 0.4.4"
43
38
  gem "pg", ">= 1.1", "< 2.0"
44
39
  gem "sqlite3", "~> 1.4"
45
40
  end
41
+
42
+ appraise "rails70" do
43
+ gem "rails", ">= 7.0.0", "< 7.1"
44
+ gem "mysql2", ">= 0.4.4"
45
+ gem "pg", ">= 1.1"
46
+ gem "sqlite3", ">= 1.4"
47
+ end
data/CHANGELOG.md CHANGED
@@ -1,6 +1,95 @@
1
1
  # Audited ChangeLog
2
2
 
3
- ## Unreleased
3
+ ## 5.2.0 (2023-01-23)
4
+
5
+ Improved
6
+
7
+ - config.audit_class can take a string or constant - @rocket-turtle
8
+ Fixes overzealous change in 5.1.0 where it only took a string.
9
+ [#648](https://github.com/collectiveidea/audited/pull/648)
10
+ - README link fix - @jeremiahlukus
11
+ [#646](https://github.com/collectiveidea/audited/pull/646)
12
+ - Typo fix in GitHub Actions - @jdufresne
13
+ [#644](https://github.com/collectiveidea/audited/pull/644)
14
+
15
+ ## 5.1.0 (2022-12-23)
16
+
17
+ Changed
18
+
19
+ - config.audit_class takes a string - @simmerz
20
+ [#609](https://github.com/collectiveidea/audited/pull/609)
21
+ - Filter encrypted attributes automatically - @vlad-psh
22
+ [#630](https://github.com/collectiveidea/audited/pull/630)
23
+
24
+ Improved
25
+
26
+ - README improvements - @jess, @mstroming
27
+ [#605](https://github.com/collectiveidea/audited/pull/605)
28
+ [#640](https://github.com/collectiveidea/audited/issues/640)
29
+ - Ignore deadlocks in concurrent audit combinations - @Crammaman
30
+ [#621](https://github.com/collectiveidea/audited/pull/621)
31
+ - Fix timestamped_migrations deprecation warning - @shouichi
32
+ [#624](https://github.com/collectiveidea/audited/pull/624)
33
+ - Ensure audits are re-enabled after blocks - @dcorlett
34
+ [#632](https://github.com/collectiveidea/audited/pull/632)
35
+ - Replace raw string where clause with query methods - @macowie
36
+ [#642](https://github.com/collectiveidea/audited/pull/642)
37
+ - Test against more Ruby/Rails Versions - @enomotodev, @danielmorrison
38
+ [#610](https://github.com/collectiveidea/audited/pull/610)
39
+ [#643](https://github.com/collectiveidea/audited/pull/643)
40
+
41
+ ## 5.0.2 (2021-09-16)
42
+
43
+ Added
44
+
45
+ - Relax ActiveRecord version constraint to support Rails 7
46
+ [#597](https://github.com/collectiveidea/audited/pull/597)
47
+
48
+ Improved
49
+
50
+ - Improve loading - @mvastola
51
+ [#592](https://github.com/collectiveidea/audited/pull/592)
52
+ - Update README - @danirod, @clement1234
53
+ [#596](https://github.com/collectiveidea/audited/pull/596)
54
+ [#594](https://github.com/collectiveidea/audited/pull/594)
55
+
56
+
57
+ ## 5.0.1 (2021-06-11)
58
+
59
+ Improved
60
+
61
+ - Don't load associated model when auditing is disabled - @nut4k1
62
+ [#584](https://github.com/collectiveidea/audited/pull/584)
63
+
64
+ ## 5.0.0 (2021-06-10)
65
+
66
+ Improved
67
+
68
+ - Fixes an issue where array attributes were not deserialized properly - @cfeckardt, @yuki24
69
+ [#448](https://github.com/collectiveidea/audited/pull/448)
70
+ [#576](https://github.com/collectiveidea/audited/pull/576)
71
+ - Improve error message on audit_comment and allow for i18n override - @james
72
+ [#523](https://github.com/collectiveidea/audited/pull/523/)
73
+ - Don't require a comment if only non-audited fields are changed - @james
74
+ [#522](https://github.com/collectiveidea/audited/pull/522/)
75
+ - Readme updates - @gourshete
76
+ [#525](https://github.com/collectiveidea/audited/pull/525)
77
+ - Allow restoring previous enum behavior with flag - @travisofthenorth
78
+ [#526](https://github.com/collectiveidea/audited/pull/526)
79
+ - Follow Rails Autoloading conventions - @duncanjbrown
80
+ [#532](https://github.com/collectiveidea/audited/pull/532)
81
+ - Fix own_and_associated_audits for STI Models - @eric-hemasystems
82
+ [#533](https://github.com/collectiveidea/audited/pull/533)
83
+ - Rails 6.1 Improvements - @okuramasafumi, @marcrohloff
84
+ [#563](https://github.com/collectiveidea/audited/pull/563)
85
+ [#544](https://github.com/collectiveidea/audited/pull/544)
86
+ - Use Thread local variables instead of Fibers - @arathunku
87
+ [#568](https://github.com/collectiveidea/audited/pull/568)
88
+
89
+ Changed
90
+
91
+ - Drop support for Rails 4 - @travisofthenorth
92
+ [#527](https://github.com/collectiveidea/audited/pull/527)
4
93
 
5
94
  ## 4.10.0 (2021-01-07)
6
95
 
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  gemspec name: "audited"
data/README.md CHANGED
@@ -1,20 +1,29 @@
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)
1
+ Audited
2
+ [![Gem Version](https://img.shields.io/gem/v/audited.svg)](http://rubygems.org/gems/audited)
3
+ ![Build Status](https://github.com/collectiveidea/audited/actions/workflows/ci.yml/badge.svg)
4
+ [![Code Climate](https://codeclimate.com/github/collectiveidea/audited.svg)](https://codeclimate.com/github/collectiveidea/audited)
5
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
2
6
  =======
3
7
 
4
8
  **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
9
 
6
- Audited currently (4.x) works with Rails 6.1, Rails 6.0, 5.2, 5.1, 5.0 and 4.2.
7
10
 
11
+ Audited currently (5.x) works with Rails 7.0, 6.1, 6.0, 5.2, 5.1, and 5.0.
12
+
13
+ For Rails 4, use gem version 4.x
8
14
  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
15
 
10
16
  ## Supported Rubies
11
17
 
12
- Audited supports and is [tested against](http://travis-ci.org/collectiveidea/audited) the following Ruby versions:
18
+ Audited supports and is [tested against](https://github.com/collectiveidea/audited/actions/workflows/ci.yml) the following Ruby versions:
13
19
 
14
- * 2.3.7
15
- * 2.4.4
16
- * 2.5.1
17
- * 2.6.3
20
+ * 2.3 (only tested on Sqlite due to testing issues with other DBs)
21
+ * 2.4
22
+ * 2.5
23
+ * 2.6
24
+ * 2.7
25
+ * 3.0
26
+ * 3.1
18
27
 
19
28
  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).
20
29
 
@@ -27,7 +36,16 @@ Audited is currently ActiveRecord-only. In a previous life, Audited worked with
27
36
  Add the gem to your Gemfile:
28
37
 
29
38
  ```ruby
30
- gem "audited", "~> 4.9"
39
+ gem "audited", "~> 5.0"
40
+ ```
41
+
42
+ And if you're using ```require: false``` you must add initializers like this:
43
+
44
+ ```ruby
45
+ #./config/initializers/audited.rb
46
+ require "audited"
47
+
48
+ Audited::Railtie.initializers.each(&:run)
31
49
  ```
32
50
 
33
51
  Then, from your Rails app directory, create the `audits` table:
@@ -153,7 +171,7 @@ end
153
171
 
154
172
  ### Limiting stored audits
155
173
 
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:
174
+ You can limit the number of audits stored for your model. To configure limiting for all audited models, put the following in an initializer file (`config/initializers/audited.rb`):
157
175
 
158
176
  ```ruby
159
177
  Audited.max_audits = 10 # keep only 10 latest audits
@@ -192,7 +210,7 @@ class PostsController < ApplicationController
192
210
  end
193
211
  ```
194
212
 
195
- To use a method other than `current_user`, put the following in an initializer:
213
+ To use a method other than `current_user`, put the following in an initializer file (`config/initializers/audited.rb`):
196
214
 
197
215
  ```ruby
198
216
  Audited.current_user_method = :authenticated_user
@@ -268,6 +286,7 @@ class User < ActiveRecord::Base
268
286
  end
269
287
 
270
288
  class Company < ActiveRecord::Base
289
+ audited
271
290
  has_many :users
272
291
  has_associated_audits
273
292
  end
@@ -296,8 +315,6 @@ If you want to audit only under specific conditions, you can provide conditional
296
315
  class User < ActiveRecord::Base
297
316
  audited if: :active?
298
317
 
299
- private
300
-
301
318
  def active?
302
319
  last_login > 6.months.ago
303
320
  end
@@ -368,6 +385,17 @@ User.auditing_enabled = false
368
385
  end
369
386
  ```
370
387
 
388
+ ### Encrypted attributes
389
+
390
+ If you're using ActiveRecord's encryption (available from Rails 7) to encrypt some attributes, Audited will automatically filter values of these attributes. No additional configuration is required. Changes to encrypted attributes will be logged as `[FILTERED]`.
391
+
392
+ ```ruby
393
+ class User < ActiveRecord::Base
394
+ audited
395
+ encrypts :password
396
+ end
397
+ ```
398
+
371
399
  ### Custom `Audit` model
372
400
 
373
401
  If you want to extend or modify the audit model, create a new class that
@@ -384,13 +412,23 @@ Then set it in an initializer:
384
412
  # config/initializers/audited.rb
385
413
 
386
414
  Audited.config do |config|
387
- config.audit_class = CustomAudit
415
+ config.audit_class = "CustomAudit"
388
416
  end
389
417
  ```
390
418
 
419
+ ### Enum Storage
420
+
421
+ In 4.10, the default behavior for enums changed from storing the value synthesized by Rails to the value stored in the DB. You can restore the previous behavior by setting the store_synthesized_enums configuration value:
422
+
423
+ ```ruby
424
+ # config/initializers/audited.rb
425
+
426
+ Audited.store_synthesized_enums = true
427
+ ```
428
+
391
429
  ## Support
392
430
 
393
- You can find documentation at: http://rdoc.info/github/collectiveidea/audited
431
+ You can find documentation at: https://www.rubydoc.info/gems/audited
394
432
 
395
433
  Or join the [mailing list](http://groups.google.com/group/audited) to get help or offer suggestions.
396
434
 
data/Rakefile CHANGED
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env rake
2
2
 
3
- require 'bundler/gem_helper'
4
- require 'rspec/core/rake_task'
5
- require 'rake/testtask'
6
- require 'appraisal'
3
+ require "bundler/gem_helper"
4
+ require "rspec/core/rake_task"
5
+ require "rake/testtask"
6
+ require "appraisal"
7
7
 
8
- Bundler::GemHelper.install_tasks(name: 'audited')
8
+ Bundler::GemHelper.install_tasks(name: "audited")
9
9
 
10
10
  RSpec::Core::RakeTask.new(:spec)
11
11
 
12
12
  Rake::TestTask.new do |t|
13
13
  t.libs << "test"
14
- t.test_files = FileList['test/**/*_test.rb']
14
+ t.test_files = FileList["test/**/*_test.rb"]
15
15
  t.verbose = true
16
16
  end
17
17
 
@@ -6,5 +6,6 @@ gem "rails", "~> 5.0.0"
6
6
  gem "mysql2", ">= 0.3.18", "< 0.6.0"
7
7
  gem "pg", ">= 0.18", "< 2.0"
8
8
  gem "sqlite3", "~> 1.3.6"
9
+ gem "psych", "~> 3.1"
9
10
 
10
11
  gemspec name: "audited", path: "../"
@@ -6,5 +6,6 @@ gem "rails", "~> 5.1.4"
6
6
  gem "mysql2", ">= 0.3.18", "< 0.6.0"
7
7
  gem "pg", ">= 0.18", "< 2.0"
8
8
  gem "sqlite3", "~> 1.3.6"
9
+ gem "psych", "~> 3.1"
9
10
 
10
11
  gemspec name: "audited", path: "../"
@@ -2,9 +2,10 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", ">= 5.2.0", "< 5.3"
5
+ gem "rails", ">= 5.2.8.1", "< 5.3"
6
6
  gem "mysql2", ">= 0.4.4", "< 0.6.0"
7
7
  gem "pg", ">= 0.18", "< 2.0"
8
8
  gem "sqlite3", "~> 1.3.6"
9
+ gem "psych", "~> 3.1"
9
10
 
10
11
  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", ">= 7.0.0", "< 7.1"
6
+ gem "mysql2", ">= 0.4.4"
7
+ gem "pg", ">= 1.1"
8
+ gem "sqlite3", ">= 1.4"
9
+
10
+ gemspec name: "audited", path: "../"
data/lib/audited/audit.rb CHANGED
@@ -1,4 +1,6 @@
1
- require 'set'
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
2
4
 
3
5
  module Audited
4
6
  # Audit saves the changes to ActiveRecord models. It has the following attributes:
@@ -38,8 +40,8 @@ module Audited
38
40
  end
39
41
 
40
42
  class Audit < ::ActiveRecord::Base
41
- belongs_to :auditable, polymorphic: true
42
- belongs_to :user, polymorphic: true
43
+ belongs_to :auditable, polymorphic: true
44
+ belongs_to :user, polymorphic: true
43
45
  belongs_to :associated, polymorphic: true
44
46
 
45
47
  before_create :set_version_number, :set_audit_user, :set_request_uuid, :set_remote_address
@@ -49,16 +51,16 @@ module Audited
49
51
 
50
52
  serialize :audited_changes, YAMLIfTextColumnType
51
53
 
52
- scope :ascending, ->{ reorder(version: :asc) }
53
- scope :descending, ->{ reorder(version: :desc)}
54
- scope :creates, ->{ where(action: 'create')}
55
- scope :updates, ->{ where(action: 'update')}
56
- scope :destroys, ->{ where(action: 'destroy')}
54
+ scope :ascending, -> { reorder(version: :asc) }
55
+ scope :descending, -> { reorder(version: :desc) }
56
+ scope :creates, -> { where(action: "create") }
57
+ scope :updates, -> { where(action: "update") }
58
+ scope :destroys, -> { where(action: "destroy") }
57
59
 
58
- scope :up_until, ->(date_or_time){ where("created_at <= ?", date_or_time) }
59
- scope :from_version, ->(version){ where('version >= ?', version) }
60
- scope :to_version, ->(version){ where('version <= ?', version) }
61
- scope :auditable_finder, ->(auditable_id, auditable_type){ where(auditable_id: auditable_id, auditable_type: auditable_type)}
60
+ scope :up_until, ->(date_or_time) { where("created_at <= ?", date_or_time) }
61
+ scope :from_version, ->(version) { where("version >= ?", version) }
62
+ scope :to_version, ->(version) { where("version <= ?", version) }
63
+ scope :auditable_finder, ->(auditable_id, auditable_type) { where(auditable_id: auditable_id, auditable_type: auditable_type) }
62
64
  # Return all audits older than the current one.
63
65
  def ancestors
64
66
  self.class.ascending.auditable_finder(auditable_id, auditable_type).to_version(version)
@@ -75,31 +77,28 @@ module Audited
75
77
 
76
78
  # Returns a hash of the changed attributes with the new values
77
79
  def new_attributes
78
- (audited_changes || {}).inject({}.with_indifferent_access) do |attrs, (attr, values)|
79
- attrs[attr] = values.is_a?(Array) ? values.last : values
80
- attrs
80
+ (audited_changes || {}).each_with_object({}.with_indifferent_access) do |(attr, values), attrs|
81
+ attrs[attr] = (action == "update") ? values.last : values
81
82
  end
82
83
  end
83
84
 
84
85
  # Returns a hash of the changed attributes with the old values
85
86
  def old_attributes
86
- (audited_changes || {}).inject({}.with_indifferent_access) do |attrs, (attr, values)|
87
- attrs[attr] = Array(values).first
88
-
89
- attrs
87
+ (audited_changes || {}).each_with_object({}.with_indifferent_access) do |(attr, values), attrs|
88
+ attrs[attr] = (action == "update") ? values.first : values
90
89
  end
91
90
  end
92
91
 
93
92
  # Allows user to undo changes
94
93
  def undo
95
94
  case action
96
- when 'create'
95
+ when "create"
97
96
  # destroys a newly created record
98
97
  auditable.destroy!
99
- when 'destroy'
98
+ when "destroy"
100
99
  # creates a new record with the destroyed record attributes
101
100
  auditable_type.constantize.create!(audited_changes)
102
- when 'update'
101
+ when "update"
103
102
  # changes back attributes
104
103
  auditable.update!(audited_changes.transform_values(&:first))
105
104
  else
@@ -147,7 +146,7 @@ module Audited
147
146
  audits.each_with_object({}) do |audit, all|
148
147
  all.merge!(audit.new_attributes)
149
148
  all[:audit_version] = audit.version
150
- end
149
+ end
151
150
  end
152
151
 
153
152
  # @private
@@ -172,10 +171,10 @@ module Audited
172
171
  private
173
172
 
174
173
  def set_version_number
175
- if action == 'create'
174
+ if action == "create"
176
175
  self.version = 1
177
176
  else
178
- collection = Rails::VERSION::MAJOR == 6 ? self.class.unscoped : self.class
177
+ collection = (Rails::VERSION::MAJOR >= 6) ? self.class.unscoped : self.class
179
178
  max = collection.auditable_finder(auditable_id, auditable_type).maximum(:version) || 0
180
179
  self.version = max + 1
181
180
  end