audited 4.9.0 → 5.0.2

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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +115 -0
  3. data/.standard.yml +5 -0
  4. data/Appraisals +22 -16
  5. data/CHANGELOG.md +68 -1
  6. data/Gemfile +1 -1
  7. data/README.md +49 -11
  8. data/Rakefile +6 -6
  9. data/gemfiles/rails60.gemfile +1 -1
  10. data/gemfiles/rails61.gemfile +10 -0
  11. data/gemfiles/rails70.gemfile +10 -0
  12. data/lib/audited/audit.rb +36 -28
  13. data/lib/audited/auditor.rb +69 -43
  14. data/lib/audited/railtie.rb +16 -0
  15. data/lib/audited/rspec_matchers.rb +5 -3
  16. data/lib/audited/sweeper.rb +3 -10
  17. data/lib/audited/version.rb +3 -1
  18. data/lib/audited-rspec.rb +3 -1
  19. data/lib/audited.rb +25 -8
  20. data/lib/generators/audited/install_generator.rb +9 -7
  21. data/lib/generators/audited/migration.rb +2 -0
  22. data/lib/generators/audited/migration_helper.rb +3 -1
  23. data/lib/generators/audited/templates/add_association_to_audits.rb +2 -0
  24. data/lib/generators/audited/templates/add_comment_to_audits.rb +2 -0
  25. data/lib/generators/audited/templates/add_remote_address_to_audits.rb +2 -0
  26. data/lib/generators/audited/templates/add_request_uuid_to_audits.rb +2 -0
  27. data/lib/generators/audited/templates/add_version_to_auditable_index.rb +2 -0
  28. data/lib/generators/audited/templates/install.rb +2 -0
  29. data/lib/generators/audited/templates/rename_association_to_associated.rb +2 -0
  30. data/lib/generators/audited/templates/rename_changes_to_audited_changes.rb +2 -0
  31. data/lib/generators/audited/templates/rename_parent_to_association.rb +2 -0
  32. data/lib/generators/audited/templates/revert_polymorphic_indexes_order.rb +2 -0
  33. data/lib/generators/audited/upgrade_generator.rb +16 -14
  34. data/spec/audited/audit_spec.rb +69 -47
  35. data/spec/audited/auditor_spec.rb +310 -246
  36. data/spec/audited/sweeper_spec.rb +19 -18
  37. data/spec/audited_spec.rb +18 -0
  38. data/spec/audited_spec_helpers.rb +7 -7
  39. data/spec/rails_app/app/assets/config/manifest.js +2 -0
  40. data/spec/rails_app/config/application.rb +3 -3
  41. data/spec/rails_app/config/database.yml +3 -2
  42. data/spec/rails_app/config/environment.rb +1 -1
  43. data/spec/rails_app/config/environments/test.rb +5 -5
  44. data/spec/rails_app/config/initializers/secret_token.rb +2 -2
  45. data/spec/spec_helper.rb +14 -14
  46. data/spec/support/active_record/models.rb +31 -12
  47. data/spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb +1 -2
  48. data/spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb +1 -2
  49. data/spec/support/active_record/schema.rb +26 -19
  50. data/test/db/version_1.rb +2 -2
  51. data/test/db/version_2.rb +2 -2
  52. data/test/db/version_3.rb +2 -3
  53. data/test/db/version_4.rb +2 -3
  54. data/test/db/version_5.rb +0 -1
  55. data/test/db/version_6.rb +1 -1
  56. data/test/install_generator_test.rb +18 -19
  57. data/test/test_helper.rb +5 -5
  58. data/test/upgrade_generator_test.rb +13 -18
  59. metadata +31 -30
  60. data/.rubocop.yml +0 -25
  61. data/.travis.yml +0 -58
  62. data/gemfiles/rails42.gemfile +0 -11
  63. data/spec/rails_app/app/controllers/application_controller.rb +0 -2
  64. data/spec/rails_app/config/environments/development.rb +0 -21
  65. 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: 91cd155edfaec5e9cbe81994bdc5e12e8fd91b58886d8397a6f310ddade5ae03
4
- data.tar.gz: 5d7b4f209cf8d8803dff66e4f19b8f85c586373ea757f1e84c1422d56feee1c0
3
+ metadata.gz: 5bb58e8eb5b0de02a18ac5d089ccade2913c399ec66bcbf97551fd9a9f4afb6b
4
+ data.tar.gz: 905621826a752e1796e0b81a7b448eec483e0ef27ce5de9f02845e0f5fd8be87
5
5
  SHA512:
6
- metadata.gz: 48bab7914ba66c2e7e82bf1bb6936b113b4536ab1297e9d8cdad80036788506bc825594daf37d308b8acbff3321e7ea1936fe6bdb3481f48f311a8caaec9e4ec
7
- data.tar.gz: f30cdcce78fd2c9202d3147af5d6e6844fb77f5e81300b79261d29f0d931580e67dd3bb04799d0247d3a8b4893314996a05d3ff25d477c43dbc3cf713ecd59fd
6
+ metadata.gz: 62448f486877e8a6c86505a7e5f53b805bf4f3a14cad907f83e69cd5175f43a4c3083a08ab4342bad18f5b8b1b104aa20d2d3c375ff86b7e60d48db9cbe00346
7
+ data.tar.gz: 4bf37e3891074e6f329961c796db27191ead60d225860d3150f310a3888ed3ab52eab1564398ce2f26ad470ba2872979dd14ee48cddf0baaa8f7cbfb63c19091
@@ -0,0 +1,115 @@
1
+ name: CI
2
+
3
+ on:
4
+ pull_request:
5
+ push:
6
+ branches:
7
+ - master
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]
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
+ # Rails 5.0 supports Ruby 2.2-2.4
31
+ - appraisal: rails50
32
+ ruby: 2.5
33
+ - appraisal: rails50
34
+ ruby: 2.6
35
+ - appraisal: rails50
36
+ ruby: 2.7
37
+ - appraisal: rails50
38
+ ruby: 3.0
39
+
40
+ # Rails 5.1 supports Ruby 2.2-2.5
41
+ - appraisal: rails51
42
+ ruby: 2.6
43
+ - appraisal: rails51
44
+ ruby: 2.7
45
+ - appraisal: rails51
46
+ ruby: 3.0
47
+
48
+ # Rails 5.2 supports Ruby 2.2-2.5
49
+ - appraisal: rails52
50
+ ruby: 2.6
51
+ - appraisal: rails52
52
+ ruby: 2.7
53
+ - appraisal: rails52
54
+ ruby: 3.0
55
+
56
+ # Rails 6.0 supports Ruby 2.5-2.7
57
+ - appraisal: rails60
58
+ ruby: 2.3
59
+ - appraisal: rails60
60
+ ruby: 2.4
61
+ - appraisal: rails60
62
+ ruby: 3.0
63
+
64
+ # Rails 6.1 supports Ruby 2.5+
65
+ - appraisal: rails61
66
+ ruby: 2.3
67
+ - appraisal: rails61
68
+ ruby: 2.4
69
+
70
+ # Rails 7 supports Ruby 2.7+
71
+ - appraisal: rails70
72
+ ruby: 2.3
73
+ - appraisal: rails70
74
+ ruby: 2.4
75
+ - appraisal: rails70
76
+ ruby: 2.5
77
+ - appraisal: rails70
78
+ ruby: 2.6
79
+
80
+ services:
81
+ postgres:
82
+ image: postgres
83
+ env:
84
+ POSTGRES_USER: postgres
85
+ POSTGRES_PASSWORD: postgres
86
+ POSTGRES_DB: audited_test
87
+ ports:
88
+ - 5432:5432
89
+ # needed because the postgres container does not provide a healthcheck
90
+ options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
91
+
92
+ env:
93
+ DB_DATABASE: audited_test
94
+ DB_USER: root
95
+ DB_PASSWORD: 'root'
96
+ DB_HOST: localhost
97
+
98
+ steps:
99
+ - name: Setup MySQL
100
+ run: |
101
+ sudo /etc/init.d/mysql start
102
+ mysql -e 'CREATE DATABASE audited_test;' -uroot -proot
103
+ mysql -e 'SHOW DATABASES;' -uroot -proot
104
+ - uses: actions/checkout@v2
105
+ - name: Copy Gemfile
106
+ run: sed 's/\.\././' gemfiles/${{ matrix.appraisal }}.gemfile > Gemfile
107
+ - name: Set up Ruby ${{ matrix.ruby }}
108
+ uses: ruby/setup-ruby@v1
109
+ with:
110
+ ruby-version: ${{ matrix.ruby }}
111
+ bundler-cache: true
112
+ - name: Run tests
113
+ env:
114
+ DB: ${{ matrix.db }}
115
+ 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,38 +1,44 @@
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"
17
9
  end
18
10
 
19
- appraise 'rails51' do
20
- gem 'rails', '~> 5.1.4'
11
+ appraise "rails51" do
12
+ gem "rails", "~> 5.1.4"
21
13
  gem "mysql2", ">= 0.3.18", "< 0.6.0"
22
14
  gem "pg", ">= 0.18", "< 2.0"
23
15
  gem "sqlite3", "~> 1.3.6"
24
16
  end
25
17
 
26
- appraise 'rails52' do
27
- gem 'rails', '>= 5.2.0', '< 5.3'
18
+ appraise "rails52" do
19
+ gem "rails", ">= 5.2.0", "< 5.3"
28
20
  gem "mysql2", ">= 0.4.4", "< 0.6.0"
29
21
  gem "pg", ">= 0.18", "< 2.0"
30
22
  gem "sqlite3", "~> 1.3.6"
31
23
  end
32
24
 
33
- appraise 'rails60' do
34
- gem 'rails', '>= 6.0.0.rc1', '< 6.1'
25
+ appraise "rails60" do
26
+ gem "rails", ">= 6.0.0", "< 6.1"
35
27
  gem "mysql2", ">= 0.4.4"
36
28
  gem "pg", ">= 0.18", "< 2.0"
37
29
  gem "sqlite3", "~> 1.4"
38
30
  end
31
+
32
+ appraise "rails61" do
33
+ gem "rails", ">= 6.1.0", "< 6.2"
34
+ gem "mysql2", ">= 0.4.4"
35
+ gem "pg", ">= 1.1", "< 2.0"
36
+ gem "sqlite3", "~> 1.4"
37
+ end
38
+
39
+ appraise "rails70" do
40
+ gem "rails", ">= 7.0.0.alpha2", "< 7.1"
41
+ gem "mysql2", ">= 0.4.4"
42
+ gem "pg", ">= 1.1"
43
+ gem "sqlite3", ">= 1.4"
44
+ end
data/CHANGELOG.md CHANGED
@@ -1,6 +1,73 @@
1
1
  # Audited ChangeLog
2
2
 
3
- ## Unreleased
3
+ ## 5.0.2 (2021-09-16)
4
+
5
+ Added
6
+
7
+ - Relax ActiveRecord version constraint to support Rails 7
8
+ [#597](https://github.com/collectiveidea/audited/pull/597)
9
+
10
+ Improved
11
+
12
+ - Improve loading - @mvastola
13
+ [#592](https://github.com/collectiveidea/audited/pull/592)
14
+ - Update README - @danirod, clement1234
15
+ [#596](https://github.com/collectiveidea/audited/pull/596)
16
+ [#594](https://github.com/collectiveidea/audited/pull/594)
17
+
18
+
19
+ ## 5.0.1 (2021-06-11)
20
+
21
+ Improved
22
+
23
+ - Don't load associated model when auditing is disabled - @nut4k1
24
+ [#584](https://github.com/collectiveidea/audited/pull/584)
25
+
26
+ ## 5.0.0 (2021-06-10)
27
+
28
+ Improved
29
+
30
+ - Fixes an issue where array attributes were not deserialized properly - @cfeckardt, @yuki24
31
+ [#448](https://github.com/collectiveidea/audited/pull/448)
32
+ [#576](https://github.com/collectiveidea/audited/pull/576)
33
+ - Improve error message on audit_comment and allow for i18n override - @james
34
+ [#523](https://github.com/collectiveidea/audited/pull/523/)
35
+ - Don't require a comment if only non-audited fields are changed - @james
36
+ [#522](https://github.com/collectiveidea/audited/pull/522/)
37
+ - Readme updates - @gourshete
38
+ [#525](https://github.com/collectiveidea/audited/pull/525)
39
+ - Allow restoring previous enum behavior with flag - @travisofthenorth
40
+ [#526](https://github.com/collectiveidea/audited/pull/526)
41
+ - Follow Rails Autoloading conventions - @duncanjbrown
42
+ [#532](https://github.com/collectiveidea/audited/pull/532)
43
+ - Fix own_and_associated_audits for STI Models - @eric-hemasystems
44
+ [#533](https://github.com/collectiveidea/audited/pull/533)
45
+ - Rails 6.1 Improvements - @okuramasafumi, @marcrohloff
46
+ [#563](https://github.com/collectiveidea/audited/pull/563)
47
+ [#544](https://github.com/collectiveidea/audited/pull/544)
48
+ - Use Thread local variables instead of Fibers - @arathunku
49
+ [#568](https://github.com/collectiveidea/audited/pull/568)
50
+
51
+ Changed
52
+
53
+ - Drop support for Rails 4 - @travisofthenorth
54
+ [#527](https://github.com/collectiveidea/audited/pull/527)
55
+
56
+ ## 4.10.0 (2021-01-07)
57
+
58
+ Added
59
+
60
+ - Add redacted option
61
+ [#485](https://github.com/collectiveidea/audited/pull/485)
62
+ - Rails 6.1. support
63
+ [#554](https://github.com/collectiveidea/audited/pull/554)
64
+ [#559](https://github.com/collectiveidea/audited/pull/559)
65
+
66
+ Improved
67
+
68
+ - Avoid extra query on first audit version
69
+ [#513](https://github.com/collectiveidea/audited/pull/513)
70
+
4
71
 
5
72
  ## 4.9.0 (2019-07-17)
6
73
 
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
+ [![Security](https://hakiri.io/github/collectiveidea/audited/master.svg)](https://hakiri.io/github/collectiveidea/audited/master)
6
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
2
7
  =======
3
8
 
4
9
  **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
10
 
6
- Audited currently (4.x) works with Rails 6.0, 5.2, 5.1, 5.0 and 4.2.
7
11
 
12
+ Audited currently (5.x) works with Rails 7.0, 6.1, 6.0, 5.2, 5.1, and 5.0.
13
+
14
+ For Rails 4, use gem version 4.x
8
15
  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
16
 
10
17
  ## Supported Rubies
11
18
 
12
- Audited supports and is [tested against](http://travis-ci.org/collectiveidea/audited) the following Ruby versions:
19
+ Audited supports and is [tested against](https://github.com/collectiveidea/audited/actions/workflows/ci.yml) the following Ruby versions:
13
20
 
14
- * 2.3.7
15
- * 2.4.4
16
- * 2.5.1
17
- * 2.6.3
21
+ * 2.3
22
+ * 2.4
23
+ * 2.5
24
+ * 2.6
25
+ * 2.7
26
+ * 3.0
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:
@@ -143,7 +161,7 @@ class User < ActiveRecord::Base
143
161
  end
144
162
  ```
145
163
 
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.
164
+ You can update an audit only if 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
165
 
148
166
  ```ruby
149
167
  class User < ActiveRecord::Base
@@ -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
@@ -234,6 +252,16 @@ end
234
252
  post.audits.last.user # => 'console-user-username'
235
253
  ```
236
254
 
255
+ If you want to set a specific user as the auditor of the commands in a CLI environment, whether that is a string or an ActiveRecord object, you can use the following command:
256
+
257
+ ```rb
258
+ Audited.store[:audited_user] = "username"
259
+
260
+ # or
261
+
262
+ Audited.store[:audited_user] = User.find(1)
263
+ ```
264
+
237
265
  ### Associated Audits
238
266
 
239
267
  Sometimes it's useful to associate an audit with a model other than the one being changed. For instance, given the following models:
@@ -378,6 +406,16 @@ Audited.config do |config|
378
406
  end
379
407
  ```
380
408
 
409
+ ### Enum Storage
410
+
411
+ 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:
412
+
413
+ ```ruby
414
+ # config/initializers/audited.rb
415
+
416
+ Audited.store_synthesized_enums = true
417
+ ```
418
+
381
419
  ## Support
382
420
 
383
421
  You can find documentation at: http://rdoc.info/github/collectiveidea/audited
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
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "rails", ">= 6.0.0.rc1", "< 6.1"
5
+ gem "rails", ">= 6.0.0", "< 6.1"
6
6
  gem "mysql2", ">= 0.4.4"
7
7
  gem "pg", ">= 0.18", "< 2.0"
8
8
  gem "sqlite3", "~> 1.4"
@@ -0,0 +1,10 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rails", ">= 6.1.0", "< 6.2"
6
+ gem "mysql2", ">= 0.4.4"
7
+ gem "pg", ">= 1.1", "< 2.0"
8
+ gem "sqlite3", "~> 1.4"
9
+
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", ">= 7.0.0.alpha2", "< 7.1"
6
+ gem "mysql2", ">= 0.4.4"
7
+ gem "pg", ">= 1.1"
8
+ gem "sqlite3", ">= 1.4"
9
+
10
+ gemspec name: "audited", path: "../"