audited 5.3.3 → 5.8.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 +4 -4
- data/Appraisals +33 -20
- data/CHANGELOG.md +52 -1
- data/README.md +11 -3
- data/Rakefile +1 -3
- data/audited.gemspec +38 -0
- data/lib/audited/audit.rb +5 -1
- data/lib/audited/auditor.rb +49 -14
- data/lib/audited/version.rb +1 -1
- data/lib/audited.rb +11 -4
- data/lib/generators/audited/migration.rb +1 -1
- metadata +26 -59
- data/.github/workflows/buildlight.yml +0 -15
- data/.github/workflows/ci.yml +0 -134
- data/.gitignore +0 -17
- data/.standard.yml +0 -5
- data/.yardopts +0 -3
- data/gemfiles/rails50.gemfile +0 -11
- data/gemfiles/rails51.gemfile +0 -11
- data/gemfiles/rails52.gemfile +0 -11
- 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 -1227
- data/spec/audited/rspec_matchers_spec.rb +0 -69
- data/spec/audited/sweeper_spec.rb +0 -133
- data/spec/audited_spec.rb +0 -14
- 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 -19
- 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 -52
- 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 -170
- 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
@@ -1,90 +0,0 @@
|
|
1
|
-
require "active_record"
|
2
|
-
require "logger"
|
3
|
-
|
4
|
-
begin
|
5
|
-
if ActiveRecord.version >= Gem::Version.new("6.1.0")
|
6
|
-
db_config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first
|
7
|
-
ActiveRecord::Tasks::DatabaseTasks.create(db_config)
|
8
|
-
else
|
9
|
-
db_config = ActiveRecord::Base.configurations[Rails.env].clone
|
10
|
-
db_type = db_config["adapter"]
|
11
|
-
db_name = db_config.delete("database")
|
12
|
-
raise StandardError.new("No database name specified.") if db_name.blank?
|
13
|
-
if db_type == "sqlite3"
|
14
|
-
db_file = Pathname.new(__FILE__).dirname.join(db_name)
|
15
|
-
db_file.unlink if db_file.file?
|
16
|
-
else
|
17
|
-
if defined?(JRUBY_VERSION)
|
18
|
-
db_config.symbolize_keys!
|
19
|
-
db_config[:configure_connection] = false
|
20
|
-
end
|
21
|
-
adapter = ActiveRecord::Base.send("#{db_type}_connection", db_config)
|
22
|
-
adapter.recreate_database db_name, db_config.slice("charset").symbolize_keys
|
23
|
-
adapter.disconnect!
|
24
|
-
end
|
25
|
-
end
|
26
|
-
rescue => e
|
27
|
-
Kernel.warn e
|
28
|
-
end
|
29
|
-
|
30
|
-
logfile = Pathname.new(__FILE__).dirname.join("debug.log")
|
31
|
-
logfile.unlink if logfile.file?
|
32
|
-
ActiveRecord::Base.logger = Logger.new(logfile)
|
33
|
-
|
34
|
-
ActiveRecord::Migration.verbose = false
|
35
|
-
ActiveRecord::Base.establish_connection
|
36
|
-
|
37
|
-
ActiveRecord::Schema.define do
|
38
|
-
create_table :users do |t|
|
39
|
-
t.column :name, :string
|
40
|
-
t.column :username, :string
|
41
|
-
t.column :password, :string
|
42
|
-
t.column :activated, :boolean
|
43
|
-
t.column :status, :integer, default: 0
|
44
|
-
t.column :suspended_at, :datetime
|
45
|
-
t.column :logins, :integer, default: 0
|
46
|
-
t.column :created_at, :datetime
|
47
|
-
t.column :updated_at, :datetime
|
48
|
-
t.column :favourite_device, :string
|
49
|
-
t.column :ssn, :integer
|
50
|
-
t.column :phone_numbers, :string
|
51
|
-
end
|
52
|
-
|
53
|
-
create_table :companies do |t|
|
54
|
-
t.column :name, :string
|
55
|
-
t.column :owner_id, :integer
|
56
|
-
t.column :type, :string
|
57
|
-
end
|
58
|
-
|
59
|
-
create_table :authors do |t|
|
60
|
-
t.column :name, :string
|
61
|
-
end
|
62
|
-
|
63
|
-
create_table :books do |t|
|
64
|
-
t.column :authord_id, :integer
|
65
|
-
t.column :title, :string
|
66
|
-
end
|
67
|
-
|
68
|
-
create_table :audits do |t|
|
69
|
-
t.column :auditable_id, :integer
|
70
|
-
t.column :auditable_type, :string
|
71
|
-
t.column :associated_id, :integer
|
72
|
-
t.column :associated_type, :string
|
73
|
-
t.column :user_id, :integer
|
74
|
-
t.column :user_type, :string
|
75
|
-
t.column :username, :string
|
76
|
-
t.column :action, :string
|
77
|
-
t.column :audited_changes, :text
|
78
|
-
t.column :version, :integer, default: 0
|
79
|
-
t.column :comment, :string
|
80
|
-
t.column :remote_address, :string
|
81
|
-
t.column :request_uuid, :string
|
82
|
-
t.column :created_at, :datetime
|
83
|
-
end
|
84
|
-
|
85
|
-
add_index :audits, [:auditable_id, :auditable_type], name: "auditable_index"
|
86
|
-
add_index :audits, [:associated_id, :associated_type], name: "associated_index"
|
87
|
-
add_index :audits, [:user_id, :user_type], name: "user_index"
|
88
|
-
add_index :audits, :request_uuid
|
89
|
-
add_index :audits, :created_at
|
90
|
-
end
|
data/test/db/version_1.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 :changes, :text
|
10
|
-
t.column :version, :integer, default: 0
|
11
|
-
t.column :created_at, :datetime
|
12
|
-
end
|
13
|
-
|
14
|
-
add_index :audits, [:auditable_id, :auditable_type], name: "auditable_index"
|
15
|
-
add_index :audits, [:user_id, :user_type], name: "user_index"
|
16
|
-
add_index :audits, :created_at
|
17
|
-
end
|
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
|