audited 5.0.2 → 5.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +15 -2
- data/CHANGELOG.md +105 -1
- data/README.md +29 -11
- data/Rakefile +1 -3
- data/audited.gemspec +38 -0
- data/lib/audited/audit.rb +8 -4
- data/lib/audited/auditor.rb +81 -28
- data/lib/audited/version.rb +1 -1
- data/lib/audited.rb +18 -9
- data/lib/generators/audited/migration.rb +10 -2
- metadata +39 -57
- data/.github/workflows/ci.yml +0 -115
- data/.gitignore +0 -17
- data/.standard.yml +0 -5
- data/.yardopts +0 -3
- data/gemfiles/rails50.gemfile +0 -10
- data/gemfiles/rails51.gemfile +0 -10
- data/gemfiles/rails52.gemfile +0 -10
- data/gemfiles/rails60.gemfile +0 -10
- data/gemfiles/rails61.gemfile +0 -10
- data/gemfiles/rails70.gemfile +0 -10
- data/spec/audited/audit_spec.rb +0 -357
- data/spec/audited/auditor_spec.rb +0 -1097
- data/spec/audited/rspec_matchers_spec.rb +0 -69
- data/spec/audited/sweeper_spec.rb +0 -133
- data/spec/audited_spec.rb +0 -18
- data/spec/audited_spec_helpers.rb +0 -32
- data/spec/rails_app/app/assets/config/manifest.js +0 -2
- data/spec/rails_app/config/application.rb +0 -13
- data/spec/rails_app/config/database.yml +0 -26
- data/spec/rails_app/config/environment.rb +0 -5
- data/spec/rails_app/config/environments/test.rb +0 -47
- data/spec/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/rails_app/config/initializers/inflections.rb +0 -2
- data/spec/rails_app/config/initializers/secret_token.rb +0 -3
- data/spec/rails_app/config/routes.rb +0 -3
- data/spec/spec_helper.rb +0 -24
- data/spec/support/active_record/models.rb +0 -151
- data/spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb +0 -11
- data/spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb +0 -11
- data/spec/support/active_record/schema.rb +0 -90
- data/test/db/version_1.rb +0 -17
- data/test/db/version_2.rb +0 -18
- data/test/db/version_3.rb +0 -18
- data/test/db/version_4.rb +0 -19
- data/test/db/version_5.rb +0 -17
- data/test/db/version_6.rb +0 -19
- data/test/install_generator_test.rb +0 -62
- data/test/test_helper.rb +0 -18
- data/test/upgrade_generator_test.rb +0 -97
data/test/db/version_2.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define do
|
2
|
-
create_table :audits, force: true do |t|
|
3
|
-
t.column :auditable_id, :integer
|
4
|
-
t.column :auditable_type, :string
|
5
|
-
t.column :user_id, :integer
|
6
|
-
t.column :user_type, :string
|
7
|
-
t.column :username, :string
|
8
|
-
t.column :action, :string
|
9
|
-
t.column :changes, :text
|
10
|
-
t.column :version, :integer, default: 0
|
11
|
-
t.column :comment, :string
|
12
|
-
t.column :created_at, :datetime
|
13
|
-
end
|
14
|
-
|
15
|
-
add_index :audits, [:auditable_id, :auditable_type], name: "auditable_index"
|
16
|
-
add_index :audits, [:user_id, :user_type], name: "user_index"
|
17
|
-
add_index :audits, :created_at
|
18
|
-
end
|
data/test/db/version_3.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define do
|
2
|
-
create_table :audits, force: true do |t|
|
3
|
-
t.column :auditable_id, :integer
|
4
|
-
t.column :auditable_type, :string
|
5
|
-
t.column :user_id, :integer
|
6
|
-
t.column :user_type, :string
|
7
|
-
t.column :username, :string
|
8
|
-
t.column :action, :string
|
9
|
-
t.column :audited_changes, :text
|
10
|
-
t.column :version, :integer, default: 0
|
11
|
-
t.column :comment, :string
|
12
|
-
t.column :created_at, :datetime
|
13
|
-
end
|
14
|
-
|
15
|
-
add_index :audits, [:auditable_id, :auditable_type], name: "auditable_index"
|
16
|
-
add_index :audits, [:user_id, :user_type], name: "user_index"
|
17
|
-
add_index :audits, :created_at
|
18
|
-
end
|
data/test/db/version_4.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define do
|
2
|
-
create_table :audits, force: true do |t|
|
3
|
-
t.column :auditable_id, :integer
|
4
|
-
t.column :auditable_type, :string
|
5
|
-
t.column :user_id, :integer
|
6
|
-
t.column :user_type, :string
|
7
|
-
t.column :username, :string
|
8
|
-
t.column :action, :string
|
9
|
-
t.column :audited_changes, :text
|
10
|
-
t.column :version, :integer, default: 0
|
11
|
-
t.column :comment, :string
|
12
|
-
t.column :created_at, :datetime
|
13
|
-
t.column :remote_address, :string
|
14
|
-
end
|
15
|
-
|
16
|
-
add_index :audits, [:auditable_id, :auditable_type], name: "auditable_index"
|
17
|
-
add_index :audits, [:user_id, :user_type], name: "user_index"
|
18
|
-
add_index :audits, :created_at
|
19
|
-
end
|
data/test/db/version_5.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define do
|
2
|
-
create_table :audits, force: true do |t|
|
3
|
-
t.column :auditable_id, :integer
|
4
|
-
t.column :auditable_type, :string
|
5
|
-
t.column :user_id, :integer
|
6
|
-
t.column :user_type, :string
|
7
|
-
t.column :username, :string
|
8
|
-
t.column :action, :string
|
9
|
-
t.column :audited_changes, :text
|
10
|
-
t.column :version, :integer, default: 0
|
11
|
-
t.column :comment, :string
|
12
|
-
t.column :created_at, :datetime
|
13
|
-
t.column :remote_address, :string
|
14
|
-
t.column :association_id, :integer
|
15
|
-
t.column :association_type, :string
|
16
|
-
end
|
17
|
-
end
|
data/test/db/version_6.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
ActiveRecord::Schema.define do
|
2
|
-
create_table :audits, force: true do |t|
|
3
|
-
t.column :auditable_id, :integer
|
4
|
-
t.column :auditable_type, :string
|
5
|
-
t.column :user_id, :integer
|
6
|
-
t.column :user_type, :string
|
7
|
-
t.column :username, :string
|
8
|
-
t.column :action, :string
|
9
|
-
t.column :audited_changes, :text
|
10
|
-
t.column :version, :integer, default: 0
|
11
|
-
t.column :comment, :string
|
12
|
-
t.column :created_at, :datetime
|
13
|
-
t.column :remote_address, :string
|
14
|
-
t.column :associated_id, :integer
|
15
|
-
t.column :associated_type, :string
|
16
|
-
end
|
17
|
-
|
18
|
-
add_index :audits, [:auditable_type, :auditable_id], name: "auditable_index"
|
19
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
require "generators/audited/install_generator"
|
4
|
-
|
5
|
-
class InstallGeneratorTest < Rails::Generators::TestCase
|
6
|
-
destination File.expand_path("../../tmp", __FILE__)
|
7
|
-
setup :prepare_destination
|
8
|
-
tests Audited::Generators::InstallGenerator
|
9
|
-
|
10
|
-
test "generate migration with 'text' type for audited_changes column" do
|
11
|
-
run_generator
|
12
|
-
|
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")
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
test "generate migration with 'jsonb' type for audited_changes column" do
|
20
|
-
run_generator %w[--audited-changes-column-type jsonb]
|
21
|
-
|
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")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
test "generate migration with 'json' type for audited_changes column" do
|
29
|
-
run_generator %w[--audited-changes-column-type json]
|
30
|
-
|
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")
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
test "generate migration with 'string' type for user_id column" do
|
38
|
-
run_generator %w[--audited-user-id-column-type string]
|
39
|
-
|
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")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
test "generate migration with 'uuid' type for user_id column" do
|
47
|
-
run_generator %w[--audited-user-id-column-type uuid]
|
48
|
-
|
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")
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
test "generate migration with correct AR migration parent" do
|
56
|
-
run_generator
|
57
|
-
|
58
|
-
assert_migration "db/migrate/install_audited.rb" do |content|
|
59
|
-
assert_includes(content, "class InstallAudited < ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]\n")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/test/test_helper.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
|
3
|
-
$LOAD_PATH.unshift File.dirname(__FILE__)
|
4
|
-
|
5
|
-
require File.expand_path("../../spec/rails_app/config/environment", __FILE__)
|
6
|
-
require "rails/test_help"
|
7
|
-
|
8
|
-
require "audited"
|
9
|
-
|
10
|
-
class ActiveSupport::TestCase
|
11
|
-
setup do
|
12
|
-
ActiveRecord::Migration.verbose = false
|
13
|
-
end
|
14
|
-
|
15
|
-
def load_schema(version)
|
16
|
-
load File.dirname(__FILE__) + "/db/version_#{version}.rb"
|
17
|
-
end
|
18
|
-
end
|
@@ -1,97 +0,0 @@
|
|
1
|
-
require "test_helper"
|
2
|
-
|
3
|
-
require "generators/audited/upgrade_generator"
|
4
|
-
|
5
|
-
class UpgradeGeneratorTest < Rails::Generators::TestCase
|
6
|
-
destination File.expand_path("../../tmp", __FILE__)
|
7
|
-
setup :prepare_destination
|
8
|
-
tests Audited::Generators::UpgradeGenerator
|
9
|
-
self.use_transactional_tests = false
|
10
|
-
|
11
|
-
test "should add 'comment' to audits table" do
|
12
|
-
load_schema 1
|
13
|
-
|
14
|
-
run_generator %w[upgrade]
|
15
|
-
|
16
|
-
assert_migration "db/migrate/add_comment_to_audits.rb" do |content|
|
17
|
-
assert_match(/add_column :audits, :comment, :string/, content)
|
18
|
-
end
|
19
|
-
|
20
|
-
assert_migration "db/migrate/rename_changes_to_audited_changes.rb"
|
21
|
-
end
|
22
|
-
|
23
|
-
test "should rename 'changes' to 'audited_changes'" do
|
24
|
-
load_schema 2
|
25
|
-
|
26
|
-
run_generator %w[upgrade]
|
27
|
-
|
28
|
-
assert_no_migration "db/migrate/add_comment_to_audits.rb"
|
29
|
-
|
30
|
-
assert_migration "db/migrate/rename_changes_to_audited_changes.rb" do |content|
|
31
|
-
assert_match(/rename_column :audits, :changes, :audited_changes/, content)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
test "should add a 'remote_address' to audits table" do
|
36
|
-
load_schema 3
|
37
|
-
|
38
|
-
run_generator %w[upgrade]
|
39
|
-
|
40
|
-
assert_migration "db/migrate/add_remote_address_to_audits.rb" do |content|
|
41
|
-
assert_match(/add_column :audits, :remote_address, :string/, content)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
test "should add 'association_id' and 'association_type' to audits table" do
|
46
|
-
load_schema 4
|
47
|
-
|
48
|
-
run_generator %w[upgrade]
|
49
|
-
|
50
|
-
assert_migration "db/migrate/add_association_to_audits.rb" do |content|
|
51
|
-
assert_match(/add_column :audits, :association_id, :integer/, content)
|
52
|
-
assert_match(/add_column :audits, :association_type, :string/, content)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
test "should rename 'association_id' to 'associated_id' and 'association_type' to 'associated_type'" do
|
57
|
-
load_schema 5
|
58
|
-
|
59
|
-
run_generator %w[upgrade]
|
60
|
-
|
61
|
-
assert_migration "db/migrate/rename_association_to_associated.rb" do |content|
|
62
|
-
assert_match(/rename_column :audits, :association_id, :associated_id/, content)
|
63
|
-
assert_match(/rename_column :audits, :association_type, :associated_type/, content)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
test "should add 'request_uuid' to audits table" do
|
68
|
-
load_schema 6
|
69
|
-
|
70
|
-
run_generator %w[upgrade]
|
71
|
-
|
72
|
-
assert_migration "db/migrate/add_request_uuid_to_audits.rb" do |content|
|
73
|
-
assert_match(/add_column :audits, :request_uuid, :string/, content)
|
74
|
-
assert_match(/add_index :audits, :request_uuid/, content)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
test "should add 'version' to auditable_index" do
|
79
|
-
load_schema 6
|
80
|
-
|
81
|
-
run_generator %w[upgrade]
|
82
|
-
|
83
|
-
assert_migration "db/migrate/add_version_to_auditable_index.rb" do |content|
|
84
|
-
assert_match(/add_index :audits, \[:auditable_type, :auditable_id, :version\]/, content)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
test "generate migration with correct AR migration parent" do
|
89
|
-
load_schema 1
|
90
|
-
|
91
|
-
run_generator %w[upgrade]
|
92
|
-
|
93
|
-
assert_migration "db/migrate/add_comment_to_audits.rb" do |content|
|
94
|
-
assert_includes(content, "class AddCommentToAudits < ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]\n")
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|