audited 4.10.0 → 5.0.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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +5 -0
  3. data/.travis.yml +25 -21
  4. data/Appraisals +10 -18
  5. data/CHANGELOG.md +29 -1
  6. data/Gemfile +1 -1
  7. data/README.md +16 -3
  8. data/Rakefile +6 -6
  9. data/lib/audited-rspec.rb +3 -1
  10. data/lib/audited.rb +25 -8
  11. data/lib/audited/audit.rb +24 -25
  12. data/lib/audited/auditor.rb +45 -39
  13. data/lib/audited/railtie.rb +16 -0
  14. data/lib/audited/rspec_matchers.rb +5 -3
  15. data/lib/audited/sweeper.rb +3 -10
  16. data/lib/audited/version.rb +3 -1
  17. data/lib/generators/audited/install_generator.rb +9 -7
  18. data/lib/generators/audited/migration.rb +2 -0
  19. data/lib/generators/audited/migration_helper.rb +3 -1
  20. data/lib/generators/audited/templates/add_association_to_audits.rb +2 -0
  21. data/lib/generators/audited/templates/add_comment_to_audits.rb +2 -0
  22. data/lib/generators/audited/templates/add_remote_address_to_audits.rb +2 -0
  23. data/lib/generators/audited/templates/add_request_uuid_to_audits.rb +2 -0
  24. data/lib/generators/audited/templates/add_version_to_auditable_index.rb +2 -0
  25. data/lib/generators/audited/templates/install.rb +2 -0
  26. data/lib/generators/audited/templates/rename_association_to_associated.rb +2 -0
  27. data/lib/generators/audited/templates/rename_changes_to_audited_changes.rb +2 -0
  28. data/lib/generators/audited/templates/rename_parent_to_association.rb +2 -0
  29. data/lib/generators/audited/templates/revert_polymorphic_indexes_order.rb +2 -0
  30. data/lib/generators/audited/upgrade_generator.rb +16 -14
  31. data/spec/audited/audit_spec.rb +67 -45
  32. data/spec/audited/auditor_spec.rb +284 -253
  33. data/spec/audited/sweeper_spec.rb +19 -19
  34. data/spec/audited_spec.rb +18 -0
  35. data/spec/audited_spec_helpers.rb +5 -7
  36. data/spec/rails_app/app/assets/config/manifest.js +2 -1
  37. data/spec/rails_app/config/application.rb +3 -3
  38. data/spec/rails_app/config/environment.rb +1 -1
  39. data/spec/rails_app/config/environments/test.rb +5 -5
  40. data/spec/rails_app/config/initializers/secret_token.rb +2 -2
  41. data/spec/spec_helper.rb +14 -14
  42. data/spec/support/active_record/models.rb +16 -12
  43. data/spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb +1 -2
  44. data/spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb +1 -2
  45. data/spec/support/active_record/schema.rb +25 -19
  46. data/test/db/version_1.rb +2 -2
  47. data/test/db/version_2.rb +2 -2
  48. data/test/db/version_3.rb +2 -3
  49. data/test/db/version_4.rb +2 -3
  50. data/test/db/version_5.rb +0 -1
  51. data/test/db/version_6.rb +1 -1
  52. data/test/install_generator_test.rb +18 -19
  53. data/test/test_helper.rb +5 -5
  54. data/test/upgrade_generator_test.rb +13 -18
  55. metadata +20 -22
  56. data/.rubocop.yml +0 -25
  57. data/gemfiles/rails42.gemfile +0 -11
  58. data/spec/rails_app/app/controllers/application_controller.rb +0 -2
  59. data/spec/rails_app/config/environments/development.rb +0 -21
  60. data/spec/rails_app/config/environments/production.rb +0 -35
data/test/db/version_1.rb CHANGED
@@ -11,7 +11,7 @@ ActiveRecord::Schema.define do
11
11
  t.column :created_at, :datetime
12
12
  end
13
13
 
14
- add_index :audits, [:auditable_id, :auditable_type], name: 'auditable_index'
15
- add_index :audits, [:user_id, :user_type], name: 'user_index'
14
+ add_index :audits, [:auditable_id, :auditable_type], name: "auditable_index"
15
+ add_index :audits, [:user_id, :user_type], name: "user_index"
16
16
  add_index :audits, :created_at
17
17
  end
data/test/db/version_2.rb CHANGED
@@ -12,7 +12,7 @@ ActiveRecord::Schema.define do
12
12
  t.column :created_at, :datetime
13
13
  end
14
14
 
15
- add_index :audits, [:auditable_id, :auditable_type], name: 'auditable_index'
16
- add_index :audits, [:user_id, :user_type], name: 'user_index'
15
+ add_index :audits, [:auditable_id, :auditable_type], name: "auditable_index"
16
+ add_index :audits, [:user_id, :user_type], name: "user_index"
17
17
  add_index :audits, :created_at
18
18
  end
data/test/db/version_3.rb CHANGED
@@ -12,8 +12,7 @@ ActiveRecord::Schema.define do
12
12
  t.column :created_at, :datetime
13
13
  end
14
14
 
15
- add_index :audits, [:auditable_id, :auditable_type], name: 'auditable_index'
16
- add_index :audits, [:user_id, :user_type], name: 'user_index'
15
+ add_index :audits, [:auditable_id, :auditable_type], name: "auditable_index"
16
+ add_index :audits, [:user_id, :user_type], name: "user_index"
17
17
  add_index :audits, :created_at
18
18
  end
19
-
data/test/db/version_4.rb CHANGED
@@ -13,8 +13,7 @@ ActiveRecord::Schema.define do
13
13
  t.column :remote_address, :string
14
14
  end
15
15
 
16
- add_index :audits, [:auditable_id, :auditable_type], name: 'auditable_index'
17
- add_index :audits, [:user_id, :user_type], name: 'user_index'
16
+ add_index :audits, [:auditable_id, :auditable_type], name: "auditable_index"
17
+ add_index :audits, [:user_id, :user_type], name: "user_index"
18
18
  add_index :audits, :created_at
19
19
  end
20
-
data/test/db/version_5.rb CHANGED
@@ -15,4 +15,3 @@ ActiveRecord::Schema.define do
15
15
  t.column :association_type, :string
16
16
  end
17
17
  end
18
-
data/test/db/version_6.rb CHANGED
@@ -15,5 +15,5 @@ ActiveRecord::Schema.define do
15
15
  t.column :associated_type, :string
16
16
  end
17
17
 
18
- add_index :audits, [:auditable_type, :auditable_id], name: 'auditable_index'
18
+ add_index :audits, [:auditable_type, :auditable_id], name: "auditable_index"
19
19
  end
@@ -1,9 +1,9 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
- require 'generators/audited/install_generator'
3
+ require "generators/audited/install_generator"
4
4
 
5
5
  class InstallGeneratorTest < Rails::Generators::TestCase
6
- destination File.expand_path('../../tmp', __FILE__)
6
+ destination File.expand_path("../../tmp", __FILE__)
7
7
  setup :prepare_destination
8
8
  tests Audited::Generators::InstallGenerator
9
9
 
@@ -11,44 +11,44 @@ class InstallGeneratorTest < Rails::Generators::TestCase
11
11
  run_generator
12
12
 
13
13
  assert_migration "db/migrate/install_audited.rb" do |content|
14
- assert_includes(content, 'class InstallAudited')
15
- assert_includes(content, 't.column :audited_changes, :text')
14
+ assert_includes(content, "class InstallAudited")
15
+ assert_includes(content, "t.column :audited_changes, :text")
16
16
  end
17
17
  end
18
18
 
19
19
  test "generate migration with 'jsonb' type for audited_changes column" do
20
- run_generator %w(--audited-changes-column-type jsonb)
20
+ run_generator %w[--audited-changes-column-type jsonb]
21
21
 
22
22
  assert_migration "db/migrate/install_audited.rb" do |content|
23
- assert_includes(content, 'class InstallAudited')
24
- assert_includes(content, 't.column :audited_changes, :jsonb')
23
+ assert_includes(content, "class InstallAudited")
24
+ assert_includes(content, "t.column :audited_changes, :jsonb")
25
25
  end
26
26
  end
27
27
 
28
28
  test "generate migration with 'json' type for audited_changes column" do
29
- run_generator %w(--audited-changes-column-type json)
29
+ run_generator %w[--audited-changes-column-type json]
30
30
 
31
31
  assert_migration "db/migrate/install_audited.rb" do |content|
32
- assert_includes(content, 'class InstallAudited')
33
- assert_includes(content, 't.column :audited_changes, :json')
32
+ assert_includes(content, "class InstallAudited")
33
+ assert_includes(content, "t.column :audited_changes, :json")
34
34
  end
35
35
  end
36
36
 
37
37
  test "generate migration with 'string' type for user_id column" do
38
- run_generator %w(--audited-user-id-column-type string)
38
+ run_generator %w[--audited-user-id-column-type string]
39
39
 
40
40
  assert_migration "db/migrate/install_audited.rb" do |content|
41
- assert_includes(content, 'class InstallAudited')
42
- assert_includes(content, 't.column :user_id, :string')
41
+ assert_includes(content, "class InstallAudited")
42
+ assert_includes(content, "t.column :user_id, :string")
43
43
  end
44
44
  end
45
45
 
46
46
  test "generate migration with 'uuid' type for user_id column" do
47
- run_generator %w(--audited-user-id-column-type uuid)
47
+ run_generator %w[--audited-user-id-column-type uuid]
48
48
 
49
49
  assert_migration "db/migrate/install_audited.rb" do |content|
50
- assert_includes(content, 'class InstallAudited')
51
- assert_includes(content, 't.column :user_id, :uuid')
50
+ assert_includes(content, "class InstallAudited")
51
+ assert_includes(content, "t.column :user_id, :uuid")
52
52
  end
53
53
  end
54
54
 
@@ -56,8 +56,7 @@ class InstallGeneratorTest < Rails::Generators::TestCase
56
56
  run_generator
57
57
 
58
58
  assert_migration "db/migrate/install_audited.rb" do |content|
59
- parent = Rails::VERSION::MAJOR == 4 ? 'ActiveRecord::Migration' : "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
60
- assert_includes(content, "class InstallAudited < #{parent}\n")
59
+ assert_includes(content, "class InstallAudited < ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]\n")
61
60
  end
62
61
  end
63
62
  end
data/test/test_helper.rb CHANGED
@@ -1,18 +1,18 @@
1
- ENV['RAILS_ENV'] = 'test'
1
+ ENV["RAILS_ENV"] = "test"
2
2
 
3
3
  $LOAD_PATH.unshift File.dirname(__FILE__)
4
4
 
5
- require File.expand_path('../../spec/rails_app/config/environment', __FILE__)
6
- require 'rails/test_help'
5
+ require File.expand_path("../../spec/rails_app/config/environment", __FILE__)
6
+ require "rails/test_help"
7
7
 
8
- require 'audited'
8
+ require "audited"
9
9
 
10
10
  class ActiveSupport::TestCase
11
11
  setup do
12
12
  ActiveRecord::Migration.verbose = false
13
13
  end
14
14
 
15
- def load_schema( version )
15
+ def load_schema(version)
16
16
  load File.dirname(__FILE__) + "/db/version_#{version}.rb"
17
17
  end
18
18
  end
@@ -1,21 +1,17 @@
1
- require 'test_helper'
1
+ require "test_helper"
2
2
 
3
- require 'generators/audited/upgrade_generator'
3
+ require "generators/audited/upgrade_generator"
4
4
 
5
5
  class UpgradeGeneratorTest < Rails::Generators::TestCase
6
- destination File.expand_path('../../tmp', __FILE__)
6
+ destination File.expand_path("../../tmp", __FILE__)
7
7
  setup :prepare_destination
8
8
  tests Audited::Generators::UpgradeGenerator
9
- if Rails::VERSION::MAJOR == 4
10
- self.use_transactional_fixtures = false
11
- else
12
- self.use_transactional_tests = false
13
- end
9
+ self.use_transactional_tests = false
14
10
 
15
11
  test "should add 'comment' to audits table" do
16
12
  load_schema 1
17
13
 
18
- run_generator %w(upgrade)
14
+ run_generator %w[upgrade]
19
15
 
20
16
  assert_migration "db/migrate/add_comment_to_audits.rb" do |content|
21
17
  assert_match(/add_column :audits, :comment, :string/, content)
@@ -27,7 +23,7 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
27
23
  test "should rename 'changes' to 'audited_changes'" do
28
24
  load_schema 2
29
25
 
30
- run_generator %w(upgrade)
26
+ run_generator %w[upgrade]
31
27
 
32
28
  assert_no_migration "db/migrate/add_comment_to_audits.rb"
33
29
 
@@ -39,7 +35,7 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
39
35
  test "should add a 'remote_address' to audits table" do
40
36
  load_schema 3
41
37
 
42
- run_generator %w(upgrade)
38
+ run_generator %w[upgrade]
43
39
 
44
40
  assert_migration "db/migrate/add_remote_address_to_audits.rb" do |content|
45
41
  assert_match(/add_column :audits, :remote_address, :string/, content)
@@ -49,7 +45,7 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
49
45
  test "should add 'association_id' and 'association_type' to audits table" do
50
46
  load_schema 4
51
47
 
52
- run_generator %w(upgrade)
48
+ run_generator %w[upgrade]
53
49
 
54
50
  assert_migration "db/migrate/add_association_to_audits.rb" do |content|
55
51
  assert_match(/add_column :audits, :association_id, :integer/, content)
@@ -60,7 +56,7 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
60
56
  test "should rename 'association_id' to 'associated_id' and 'association_type' to 'associated_type'" do
61
57
  load_schema 5
62
58
 
63
- run_generator %w(upgrade)
59
+ run_generator %w[upgrade]
64
60
 
65
61
  assert_migration "db/migrate/rename_association_to_associated.rb" do |content|
66
62
  assert_match(/rename_column :audits, :association_id, :associated_id/, content)
@@ -71,7 +67,7 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
71
67
  test "should add 'request_uuid' to audits table" do
72
68
  load_schema 6
73
69
 
74
- run_generator %w(upgrade)
70
+ run_generator %w[upgrade]
75
71
 
76
72
  assert_migration "db/migrate/add_request_uuid_to_audits.rb" do |content|
77
73
  assert_match(/add_column :audits, :request_uuid, :string/, content)
@@ -82,7 +78,7 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
82
78
  test "should add 'version' to auditable_index" do
83
79
  load_schema 6
84
80
 
85
- run_generator %w(upgrade)
81
+ run_generator %w[upgrade]
86
82
 
87
83
  assert_migration "db/migrate/add_version_to_auditable_index.rb" do |content|
88
84
  assert_match(/add_index :audits, \[:auditable_type, :auditable_id, :version\]/, content)
@@ -92,11 +88,10 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
92
88
  test "generate migration with correct AR migration parent" do
93
89
  load_schema 1
94
90
 
95
- run_generator %w(upgrade)
91
+ run_generator %w[upgrade]
96
92
 
97
93
  assert_migration "db/migrate/add_comment_to_audits.rb" do |content|
98
- parent = Rails::VERSION::MAJOR == 4 ? 'ActiveRecord::Migration' : "ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]"
99
- assert_includes(content, "class AddCommentToAudits < #{parent}\n")
94
+ assert_includes(content, "class AddCommentToAudits < ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]\n")
100
95
  end
101
96
  end
102
97
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: audited
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.10.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2021-01-08 00:00:00.000000000 Z
16
+ date: 2021-06-10 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: activerecord
@@ -21,7 +21,7 @@ dependencies:
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: '4.2'
24
+ version: '5.0'
25
25
  - - "<"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '6.2'
@@ -31,7 +31,7 @@ dependencies:
31
31
  requirements:
32
32
  - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '4.2'
34
+ version: '5.0'
35
35
  - - "<"
36
36
  - !ruby/object:Gem::Version
37
37
  version: '6.2'
@@ -55,7 +55,7 @@ dependencies:
55
55
  requirements:
56
56
  - - ">="
57
57
  - !ruby/object:Gem::Version
58
- version: '4.2'
58
+ version: '5.0'
59
59
  - - "<"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '6.2'
@@ -65,38 +65,38 @@ dependencies:
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '4.2'
68
+ version: '5.0'
69
69
  - - "<"
70
70
  - !ruby/object:Gem::Version
71
71
  version: '6.2'
72
72
  - !ruby/object:Gem::Dependency
73
- name: rubocop
73
+ name: rspec-rails
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
- - - "~>"
76
+ - - ">="
77
77
  - !ruby/object:Gem::Version
78
- version: 0.54.0
78
+ version: '0'
79
79
  type: :development
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
- - - "~>"
83
+ - - ">="
84
84
  - !ruby/object:Gem::Version
85
- version: 0.54.0
85
+ version: '0'
86
86
  - !ruby/object:Gem::Dependency
87
- name: rspec-rails
87
+ name: standard
88
88
  requirement: !ruby/object:Gem::Requirement
89
89
  requirements:
90
- - - "~>"
90
+ - - ">="
91
91
  - !ruby/object:Gem::Version
92
- version: '3.5'
92
+ version: '0'
93
93
  type: :development
94
94
  prerelease: false
95
95
  version_requirements: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - "~>"
97
+ - - ">="
98
98
  - !ruby/object:Gem::Version
99
- version: '3.5'
99
+ version: '0'
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: single_cov
102
102
  requirement: !ruby/object:Gem::Requirement
@@ -166,7 +166,7 @@ extensions: []
166
166
  extra_rdoc_files: []
167
167
  files:
168
168
  - ".gitignore"
169
- - ".rubocop.yml"
169
+ - ".standard.yml"
170
170
  - ".travis.yml"
171
171
  - ".yardopts"
172
172
  - Appraisals
@@ -175,7 +175,6 @@ files:
175
175
  - LICENSE
176
176
  - README.md
177
177
  - Rakefile
178
- - gemfiles/rails42.gemfile
179
178
  - gemfiles/rails50.gemfile
180
179
  - gemfiles/rails51.gemfile
181
180
  - gemfiles/rails52.gemfile
@@ -185,6 +184,7 @@ files:
185
184
  - lib/audited.rb
186
185
  - lib/audited/audit.rb
187
186
  - lib/audited/auditor.rb
187
+ - lib/audited/railtie.rb
188
188
  - lib/audited/rspec_matchers.rb
189
189
  - lib/audited/sweeper.rb
190
190
  - lib/audited/version.rb
@@ -206,14 +206,12 @@ files:
206
206
  - spec/audited/auditor_spec.rb
207
207
  - spec/audited/rspec_matchers_spec.rb
208
208
  - spec/audited/sweeper_spec.rb
209
+ - spec/audited_spec.rb
209
210
  - spec/audited_spec_helpers.rb
210
211
  - spec/rails_app/app/assets/config/manifest.js
211
- - spec/rails_app/app/controllers/application_controller.rb
212
212
  - spec/rails_app/config/application.rb
213
213
  - spec/rails_app/config/database.yml
214
214
  - spec/rails_app/config/environment.rb
215
- - spec/rails_app/config/environments/development.rb
216
- - spec/rails_app/config/environments/production.rb
217
215
  - spec/rails_app/config/environments/test.rb
218
216
  - spec/rails_app/config/initializers/backtrace_silencers.rb
219
217
  - spec/rails_app/config/initializers/inflections.rb
@@ -252,7 +250,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
250
  - !ruby/object:Gem::Version
253
251
  version: '0'
254
252
  requirements: []
255
- rubygems_version: 3.1.4
253
+ rubygems_version: 3.1.6
256
254
  signing_key:
257
255
  specification_version: 4
258
256
  summary: Log all changes to your models
data/.rubocop.yml DELETED
@@ -1,25 +0,0 @@
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
@@ -1,11 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
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
-
11
- gemspec name: "audited", path: "../"
@@ -1,2 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- end
@@ -1,21 +0,0 @@
1
- RailsApp::Application.configure do
2
- # Settings specified here will take precedence over those in config/environment.rb
3
-
4
- # In the development environment your application's code is reloaded on
5
- # every request. This slows down response time but is perfect for development
6
- # since you don't have to restart the webserver when you make code changes.
7
- config.cache_classes = false
8
-
9
- # Log error messages when you accidentally call methods on nil.
10
- # config.whiny_nils = true
11
-
12
- # Show full error reports and disable caching
13
- config.consider_all_requests_local = true
14
- config.action_view.debug_rjs = true
15
- config.action_controller.perform_caching = false
16
-
17
- # Don't care if the mailer can't send
18
- config.action_mailer.raise_delivery_errors = false
19
-
20
- config.eager_load = false
21
- end