audited 4.9.0 → 5.4.3
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/.github/workflows/buildlight.yml +15 -0
- data/.github/workflows/ci.yml +145 -0
- data/.github/workflows/publish_gem.yml +28 -0
- data/.standard.yml +5 -0
- data/Appraisals +35 -16
- data/CHANGELOG.md +162 -1
- data/Gemfile +1 -1
- data/README.md +73 -18
- data/Rakefile +5 -7
- data/gemfiles/rails50.gemfile +2 -0
- data/gemfiles/rails51.gemfile +2 -0
- data/gemfiles/rails52.gemfile +3 -1
- data/gemfiles/rails60.gemfile +1 -1
- data/gemfiles/rails61.gemfile +10 -0
- data/gemfiles/rails70.gemfile +10 -0
- data/gemfiles/rails71.gemfile +10 -0
- data/lib/audited/audit.rb +41 -29
- data/lib/audited/auditor.rb +134 -56
- data/lib/audited/railtie.rb +16 -0
- data/lib/audited/rspec_matchers.rb +5 -3
- data/lib/audited/sweeper.rb +3 -10
- data/lib/audited/version.rb +3 -1
- data/lib/audited-rspec.rb +3 -1
- data/lib/audited.rb +31 -9
- data/lib/generators/audited/install_generator.rb +9 -7
- data/lib/generators/audited/migration.rb +12 -2
- data/lib/generators/audited/migration_helper.rb +3 -1
- data/lib/generators/audited/templates/add_association_to_audits.rb +2 -0
- data/lib/generators/audited/templates/add_comment_to_audits.rb +2 -0
- data/lib/generators/audited/templates/add_remote_address_to_audits.rb +2 -0
- data/lib/generators/audited/templates/add_request_uuid_to_audits.rb +2 -0
- data/lib/generators/audited/templates/add_version_to_auditable_index.rb +2 -0
- data/lib/generators/audited/templates/install.rb +2 -0
- data/lib/generators/audited/templates/rename_association_to_associated.rb +2 -0
- data/lib/generators/audited/templates/rename_changes_to_audited_changes.rb +2 -0
- data/lib/generators/audited/templates/rename_parent_to_association.rb +2 -0
- data/lib/generators/audited/templates/revert_polymorphic_indexes_order.rb +2 -0
- data/lib/generators/audited/upgrade_generator.rb +16 -14
- data/spec/audited/audit_spec.rb +70 -48
- data/spec/audited/auditor_spec.rb +477 -246
- data/spec/audited/sweeper_spec.rb +19 -18
- data/spec/audited_spec.rb +14 -0
- data/spec/audited_spec_helpers.rb +11 -7
- data/spec/rails_app/app/assets/config/manifest.js +2 -0
- data/spec/rails_app/config/application.rb +32 -3
- data/spec/rails_app/config/database.yml +3 -2
- data/spec/rails_app/config/environment.rb +1 -1
- data/spec/rails_app/config/environments/test.rb +10 -5
- data/spec/rails_app/config/initializers/secret_token.rb +2 -2
- data/spec/spec_helper.rb +14 -14
- data/spec/support/active_record/models.rb +62 -13
- data/spec/support/active_record/postgres/1_change_audited_changes_type_to_json.rb +1 -2
- data/spec/support/active_record/postgres/2_change_audited_changes_type_to_jsonb.rb +1 -2
- data/spec/support/active_record/schema.rb +26 -19
- data/test/db/version_1.rb +2 -2
- data/test/db/version_2.rb +2 -2
- data/test/db/version_3.rb +2 -3
- data/test/db/version_4.rb +2 -3
- data/test/db/version_5.rb +0 -1
- data/test/db/version_6.rb +1 -1
- data/test/install_generator_test.rb +18 -19
- data/test/test_helper.rb +5 -5
- data/test/upgrade_generator_test.rb +13 -18
- metadata +49 -31
- data/.rubocop.yml +0 -25
- data/.travis.yml +0 -58
- data/gemfiles/rails42.gemfile +0 -11
- data/spec/rails_app/app/controllers/application_controller.rb +0 -2
- data/spec/rails_app/config/environments/development.rb +0 -21
- data/spec/rails_app/config/environments/production.rb +0 -35
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
SingleCov.covered!
|
3
|
+
SingleCov.covered!
|
4
4
|
|
5
5
|
class AuditsController < ActionController::Base
|
6
6
|
before_action :populate_user
|
@@ -13,7 +13,7 @@ class AuditsController < ActionController::Base
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def update
|
16
|
-
current_user.update!(password:
|
16
|
+
current_user.update!(password: "foo")
|
17
17
|
head :ok
|
18
18
|
end
|
19
19
|
|
@@ -22,7 +22,8 @@ class AuditsController < ActionController::Base
|
|
22
22
|
attr_accessor :current_user
|
23
23
|
attr_accessor :custom_user
|
24
24
|
|
25
|
-
def populate_user
|
25
|
+
def populate_user
|
26
|
+
end
|
26
27
|
end
|
27
28
|
|
28
29
|
describe AuditsController do
|
@@ -30,6 +31,7 @@ describe AuditsController do
|
|
30
31
|
render_views
|
31
32
|
|
32
33
|
before do
|
34
|
+
Audited::Railtie.initializers.each(&:run)
|
33
35
|
Audited.current_user_method = :current_user
|
34
36
|
end
|
35
37
|
|
@@ -40,7 +42,7 @@ describe AuditsController do
|
|
40
42
|
controller.send(:current_user=, user)
|
41
43
|
expect {
|
42
44
|
post :create
|
43
|
-
}.to change(
|
45
|
+
}.to change(Audited::Audit, :count)
|
44
46
|
|
45
47
|
expect(controller.company.audits.last.user).to eq(user)
|
46
48
|
end
|
@@ -50,7 +52,7 @@ describe AuditsController do
|
|
50
52
|
Audited.current_user_method = :nope
|
51
53
|
expect {
|
52
54
|
post :create
|
53
|
-
}.to change(
|
55
|
+
}.to change(Audited::Audit, :count)
|
54
56
|
expect(controller.company.audits.last.user).to eq(nil)
|
55
57
|
end
|
56
58
|
|
@@ -60,18 +62,18 @@ describe AuditsController do
|
|
60
62
|
|
61
63
|
expect {
|
62
64
|
post :create
|
63
|
-
}.to change(
|
65
|
+
}.to change(Audited::Audit, :count)
|
64
66
|
|
65
67
|
expect(controller.company.audits.last.user).to eq(user)
|
66
68
|
end
|
67
69
|
|
68
70
|
it "should record the remote address responsible for the change" do
|
69
|
-
request.env[
|
71
|
+
request.env["REMOTE_ADDR"] = "1.2.3.4"
|
70
72
|
controller.send(:current_user=, user)
|
71
73
|
|
72
74
|
post :create
|
73
75
|
|
74
|
-
expect(controller.company.audits.last.remote_address).to eq(
|
76
|
+
expect(controller.company.audits.last.remote_address).to eq("1.2.3.4")
|
75
77
|
end
|
76
78
|
|
77
79
|
it "should record a UUID for the web request responsible for the change" do
|
@@ -90,7 +92,7 @@ describe AuditsController do
|
|
90
92
|
|
91
93
|
expect {
|
92
94
|
post :create
|
93
|
-
}.to change(
|
95
|
+
}.to change(Audited::Audit, :count)
|
94
96
|
|
95
97
|
expect(controller.company.audits.last.user).to eq(user)
|
96
98
|
end
|
@@ -101,32 +103,31 @@ describe AuditsController do
|
|
101
103
|
controller.send(:current_user=, user)
|
102
104
|
|
103
105
|
expect {
|
104
|
-
put :update,
|
105
|
-
}.to_not change(
|
106
|
+
put :update, params: {id: 123}
|
107
|
+
}.to_not change(Audited::Audit, :count)
|
106
108
|
end
|
107
109
|
end
|
108
110
|
end
|
109
111
|
|
110
112
|
describe Audited::Sweeper do
|
111
|
-
|
112
113
|
it "should be thread-safe" do
|
113
114
|
instance = Audited::Sweeper.new
|
114
115
|
|
115
116
|
t1 = Thread.new do
|
116
117
|
sleep 0.5
|
117
|
-
instance.controller =
|
118
|
-
expect(instance.controller).to eq(
|
118
|
+
instance.controller = "thread1 controller instance"
|
119
|
+
expect(instance.controller).to eq("thread1 controller instance")
|
119
120
|
end
|
120
121
|
|
121
122
|
t2 = Thread.new do
|
122
|
-
instance.controller =
|
123
|
+
instance.controller = "thread2 controller instance"
|
123
124
|
sleep 1
|
124
|
-
expect(instance.controller).to eq(
|
125
|
+
expect(instance.controller).to eq("thread2 controller instance")
|
125
126
|
end
|
126
127
|
|
127
|
-
t1.join
|
128
|
+
t1.join
|
129
|
+
t2.join
|
128
130
|
|
129
131
|
expect(instance.controller).to be_nil
|
130
132
|
end
|
131
|
-
|
132
133
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Audited do
|
4
|
+
describe "#store" do
|
5
|
+
describe "maintains state of store" do
|
6
|
+
let(:current_user) { RequestStore.store[:audited_store] }
|
7
|
+
before { Audited.store[:current_user] = current_user }
|
8
|
+
|
9
|
+
it "checks store is not nil" do
|
10
|
+
expect(Audited.store[:current_user]).to eq(current_user)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,15 +1,18 @@
|
|
1
1
|
module AuditedSpecHelpers
|
2
|
-
|
3
2
|
def create_user(attrs = {})
|
4
|
-
Models::ActiveRecord::User.create({name:
|
3
|
+
Models::ActiveRecord::User.create({name: "Brandon", username: "brandon", password: "password", favourite_device: "Android Phone"}.merge(attrs))
|
4
|
+
end
|
5
|
+
|
6
|
+
def create_user_with_readonly_attrs(attrs = {})
|
7
|
+
Models::ActiveRecord::UserWithReadOnlyAttrs.create({name: "Brandon", username: "brandon", password: "password", favourite_device: "Android Phone"}.merge(attrs))
|
5
8
|
end
|
6
9
|
|
7
10
|
def build_user(attrs = {})
|
8
|
-
Models::ActiveRecord::User.new({name:
|
11
|
+
Models::ActiveRecord::User.new({name: "darth", username: "darth", password: "noooooooo"}.merge(attrs))
|
9
12
|
end
|
10
13
|
|
11
14
|
def create_versions(n = 2, attrs = {})
|
12
|
-
Models::ActiveRecord::User.create(name:
|
15
|
+
Models::ActiveRecord::User.create(name: "Foobar 1", **attrs).tap do |u|
|
13
16
|
(n - 1).times do |i|
|
14
17
|
u.update_attribute :name, "Foobar #{i + 2}"
|
15
18
|
end
|
@@ -18,15 +21,16 @@ module AuditedSpecHelpers
|
|
18
21
|
end
|
19
22
|
|
20
23
|
def run_migrations(direction, migrations_paths, target_version = nil)
|
21
|
-
if rails_below?(
|
24
|
+
if rails_below?("5.2.0.rc1")
|
22
25
|
ActiveRecord::Migrator.send(direction, migrations_paths, target_version)
|
23
|
-
|
26
|
+
elsif rails_below?("6.0.0.rc1")
|
24
27
|
ActiveRecord::MigrationContext.new(migrations_paths).send(direction, target_version)
|
28
|
+
else
|
29
|
+
ActiveRecord::MigrationContext.new(migrations_paths, ActiveRecord::SchemaMigration).send(direction, target_version)
|
25
30
|
end
|
26
31
|
end
|
27
32
|
|
28
33
|
def rails_below?(rails_version)
|
29
34
|
Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new(rails_version)
|
30
35
|
end
|
31
|
-
|
32
36
|
end
|
@@ -1,13 +1,42 @@
|
|
1
|
-
require
|
1
|
+
require "active_record/railtie"
|
2
2
|
|
3
3
|
module RailsApp
|
4
4
|
class Application < Rails::Application
|
5
|
-
config.root = File.expand_path(
|
5
|
+
config.root = File.expand_path("../../", __FILE__)
|
6
6
|
config.i18n.enforce_available_locales = true
|
7
|
+
|
8
|
+
if Rails.version.start_with?("7.1") && config.active_record.respond_to?(:yaml_column_permitted_classes=)
|
9
|
+
config.active_record.yaml_column_permitted_classes = [
|
10
|
+
String,
|
11
|
+
Symbol,
|
12
|
+
Integer,
|
13
|
+
NilClass,
|
14
|
+
Float,
|
15
|
+
Time,
|
16
|
+
Date,
|
17
|
+
FalseClass,
|
18
|
+
Hash,
|
19
|
+
Array,
|
20
|
+
DateTime,
|
21
|
+
TrueClass,
|
22
|
+
BigDecimal,
|
23
|
+
ActiveSupport::TimeWithZone,
|
24
|
+
ActiveSupport::TimeZone,
|
25
|
+
ActiveSupport::HashWithIndifferentAccess
|
26
|
+
]
|
27
|
+
elsif !Rails.version.start_with?("5.0") && !Rails.version.start_with?("5.1") && config.active_record.respond_to?(:yaml_column_permitted_classes=)
|
28
|
+
config.active_record.yaml_column_permitted_classes =
|
29
|
+
%w[String Symbol Integer NilClass Float Time Date FalseClass Hash Array DateTime TrueClass BigDecimal
|
30
|
+
ActiveSupport::TimeWithZone ActiveSupport::TimeZone ActiveSupport::HashWithIndifferentAccess]
|
31
|
+
end
|
32
|
+
|
33
|
+
if Rails.gem_version >= Gem::Version.new("7.1")
|
34
|
+
config.active_support.cache_format_version = 7.1
|
35
|
+
end
|
7
36
|
end
|
8
37
|
end
|
9
38
|
|
10
|
-
require
|
39
|
+
require "active_record/connection_adapters/sqlite3_adapter"
|
11
40
|
if ActiveRecord::ConnectionAdapters::SQLite3Adapter.respond_to?(:represent_boolean_as_integer)
|
12
41
|
ActiveRecord::ConnectionAdapters::SQLite3Adapter.represent_boolean_as_integer = true
|
13
42
|
end
|
@@ -9,7 +9,8 @@ sqlite3: &SQLITE
|
|
9
9
|
postgresql: &POSTGRES
|
10
10
|
adapter: postgresql
|
11
11
|
username: postgres
|
12
|
-
password:
|
12
|
+
password: postgres
|
13
|
+
host: localhost
|
13
14
|
database: audited_test
|
14
15
|
min_messages: ERROR
|
15
16
|
|
@@ -17,7 +18,7 @@ mysql: &MYSQL
|
|
17
18
|
adapter: mysql2
|
18
19
|
host: localhost
|
19
20
|
username: root
|
20
|
-
password:
|
21
|
+
password: root
|
21
22
|
database: audited_test
|
22
23
|
charset: utf8
|
23
24
|
|
@@ -15,14 +15,14 @@ RailsApp::Application.configure do
|
|
15
15
|
# Configure static file server for tests with Cache-Control for performance.
|
16
16
|
if config.respond_to?(:public_file_server)
|
17
17
|
config.public_file_server.enabled = true
|
18
|
-
config.public_file_server.headers = {
|
18
|
+
config.public_file_server.headers = {"Cache-Control" => "public, max-age=3600"}
|
19
19
|
else
|
20
|
-
config.static_cache_control =
|
21
|
-
config.serve_static_files
|
20
|
+
config.static_cache_control = "public, max-age=3600"
|
21
|
+
config.serve_static_files = true
|
22
22
|
end
|
23
23
|
|
24
24
|
# Show full error reports and disable caching.
|
25
|
-
config.consider_all_requests_local
|
25
|
+
config.consider_all_requests_local = true
|
26
26
|
# config.action_controller.perform_caching = false
|
27
27
|
|
28
28
|
# Raise exceptions instead of rendering exception templates.
|
@@ -34,7 +34,7 @@ RailsApp::Application.configure do
|
|
34
34
|
# Tell Action Mailer not to deliver emails to the real world.
|
35
35
|
# The :test delivery method accumulates sent emails in the
|
36
36
|
# ActionMailer::Base.deliveries array.
|
37
|
-
config.action_mailer.delivery_method = :test
|
37
|
+
# config.action_mailer.delivery_method = :test
|
38
38
|
|
39
39
|
# Randomize the order test cases are executed.
|
40
40
|
config.active_support.test_order = :random
|
@@ -44,4 +44,9 @@ RailsApp::Application.configure do
|
|
44
44
|
|
45
45
|
# Raises error for missing translations
|
46
46
|
# config.action_view.raise_on_missing_translations = true
|
47
|
+
|
48
|
+
if ::ActiveRecord::VERSION::MAJOR >= 7
|
49
|
+
config.active_record.encryption.key_derivation_salt = SecureRandom.hex
|
50
|
+
config.active_record.encryption.primary_key = SecureRandom.hex
|
51
|
+
end
|
47
52
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
Rails.application.config.secret_token =
|
1
|
+
Rails.application.config.secret_token = "ea942c41850d502f2c8283e26bdc57829f471bb18224ddff0a192c4f32cdf6cb5aa0d82b3a7a7adbeb640c4b06f3aa1cd5f098162d8240f669b39d6b49680571"
|
2
2
|
Rails.application.config.session_store :cookie_store, key: "_my_app"
|
3
|
-
Rails.application.config.secret_key_base =
|
3
|
+
Rails.application.config.secret_key_base = "secret value"
|
data/spec/spec_helper.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
ENV[
|
2
|
-
require
|
3
|
-
require
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
require "bundler/setup"
|
3
|
+
require "single_cov"
|
4
4
|
SingleCov.setup :rspec
|
5
5
|
|
6
|
-
if Bundler.definition.dependencies.map(&:name).include?(
|
7
|
-
require
|
6
|
+
if Bundler.definition.dependencies.map(&:name).include?("protected_attributes")
|
7
|
+
require "protected_attributes"
|
8
8
|
end
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
require
|
13
|
-
require
|
14
|
-
require
|
9
|
+
require "rails_app/config/environment"
|
10
|
+
require "rspec/rails"
|
11
|
+
require "audited"
|
12
|
+
require "audited-rspec"
|
13
|
+
require "audited_spec_helpers"
|
14
|
+
require "support/active_record/models"
|
15
15
|
|
16
|
-
SPEC_ROOT = Pathname.new(File.expand_path(
|
16
|
+
SPEC_ROOT = Pathname.new(File.expand_path("../", __FILE__))
|
17
17
|
|
18
|
-
Dir[SPEC_ROOT.join(
|
18
|
+
Dir[SPEC_ROOT.join("support/*.rb")].sort.each { |f| require f }
|
19
19
|
|
20
20
|
RSpec.configure do |config|
|
21
21
|
config.include AuditedSpecHelpers
|
22
|
-
config.use_transactional_fixtures = false if Rails.version.start_with?(
|
22
|
+
config.use_transactional_fixtures = false if Rails.version.start_with?("4.")
|
23
23
|
config.use_transactional_tests = false if config.respond_to?(:use_transactional_tests=)
|
24
24
|
end
|
@@ -1,13 +1,19 @@
|
|
1
|
-
require
|
2
|
-
require File.expand_path(
|
1
|
+
require "cgi"
|
2
|
+
require File.expand_path("../schema", __FILE__)
|
3
3
|
|
4
4
|
module Models
|
5
5
|
module ActiveRecord
|
6
6
|
class User < ::ActiveRecord::Base
|
7
7
|
audited except: :password
|
8
|
-
attribute :non_column_attr if Rails.
|
8
|
+
attribute :non_column_attr if Rails.gem_version >= Gem::Version.new("5.1")
|
9
9
|
attr_protected :logins if respond_to?(:attr_protected)
|
10
|
-
enum status: {
|
10
|
+
enum status: {active: 0, reliable: 1, banned: 2}
|
11
|
+
|
12
|
+
if Rails.gem_version >= Gem::Version.new("7.1")
|
13
|
+
serialize :phone_numbers, type: Array
|
14
|
+
else
|
15
|
+
serialize :phone_numbers, Array
|
16
|
+
end
|
11
17
|
|
12
18
|
def name=(val)
|
13
19
|
write_attribute(:name, CGI.escapeHTML(val))
|
@@ -21,13 +27,42 @@ module Models
|
|
21
27
|
|
22
28
|
class UserOnlyPassword < ::ActiveRecord::Base
|
23
29
|
self.table_name = :users
|
24
|
-
attribute :non_column_attr if Rails.
|
30
|
+
attribute :non_column_attr if Rails.gem_version >= Gem::Version.new("5.1")
|
25
31
|
audited only: :password
|
26
32
|
end
|
27
33
|
|
34
|
+
class UserRedactedPassword < ::ActiveRecord::Base
|
35
|
+
self.table_name = :users
|
36
|
+
audited redacted: :password
|
37
|
+
end
|
38
|
+
|
39
|
+
class UserMultipleRedactedAttributes < ::ActiveRecord::Base
|
40
|
+
self.table_name = :users
|
41
|
+
audited redacted: [:password, :ssn]
|
42
|
+
end
|
43
|
+
|
44
|
+
class UserRedactedPasswordCustomRedaction < ::ActiveRecord::Base
|
45
|
+
self.table_name = :users
|
46
|
+
audited redacted: :password, redaction_value: ["My", "Custom", "Value", 7]
|
47
|
+
end
|
48
|
+
|
49
|
+
if ::ActiveRecord::VERSION::MAJOR >= 7
|
50
|
+
class UserWithEncryptedPassword < ::ActiveRecord::Base
|
51
|
+
self.table_name = :users
|
52
|
+
audited
|
53
|
+
encrypts :password
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class UserWithReadOnlyAttrs < ::ActiveRecord::Base
|
58
|
+
self.table_name = :users
|
59
|
+
audited
|
60
|
+
attr_readonly :status
|
61
|
+
end
|
62
|
+
|
28
63
|
class CommentRequiredUser < ::ActiveRecord::Base
|
29
64
|
self.table_name = :users
|
30
|
-
audited comment_required: true
|
65
|
+
audited except: :password, comment_required: true
|
31
66
|
end
|
32
67
|
|
33
68
|
class OnCreateCommentRequiredUser < ::ActiveRecord::Base
|
@@ -96,37 +131,51 @@ module Models
|
|
96
131
|
end
|
97
132
|
|
98
133
|
class Owner < ::ActiveRecord::Base
|
99
|
-
self.table_name =
|
134
|
+
self.table_name = "users"
|
100
135
|
audited
|
101
136
|
has_associated_audits
|
102
137
|
has_many :companies, class_name: "OwnedCompany", dependent: :destroy
|
138
|
+
accepts_nested_attributes_for :companies
|
103
139
|
end
|
104
140
|
|
105
141
|
class OwnedCompany < ::ActiveRecord::Base
|
106
|
-
self.table_name =
|
107
|
-
belongs_to :owner, class_name: "Owner"
|
142
|
+
self.table_name = "companies"
|
143
|
+
belongs_to :owner, class_name: "Owner", touch: true
|
108
144
|
attr_accessible :name, :owner if respond_to?(:attr_accessible) # declare attr_accessible before calling aaa
|
109
145
|
audited associated_with: :owner
|
110
146
|
end
|
111
147
|
|
148
|
+
class OwnedCompany::STICompany < OwnedCompany
|
149
|
+
end
|
150
|
+
|
112
151
|
class OnUpdateDestroy < ::ActiveRecord::Base
|
113
|
-
self.table_name =
|
152
|
+
self.table_name = "companies"
|
114
153
|
audited on: [:update, :destroy]
|
115
154
|
end
|
116
155
|
|
117
156
|
class OnCreateDestroy < ::ActiveRecord::Base
|
118
|
-
self.table_name =
|
157
|
+
self.table_name = "companies"
|
158
|
+
audited on: [:create, :destroy]
|
159
|
+
end
|
160
|
+
|
161
|
+
class OnCreateDestroyUser < ::ActiveRecord::Base
|
162
|
+
self.table_name = "users"
|
119
163
|
audited on: [:create, :destroy]
|
120
164
|
end
|
121
165
|
|
122
166
|
class OnCreateDestroyExceptName < ::ActiveRecord::Base
|
123
|
-
self.table_name =
|
167
|
+
self.table_name = "companies"
|
124
168
|
audited except: :name, on: [:create, :destroy]
|
125
169
|
end
|
126
170
|
|
127
171
|
class OnCreateUpdate < ::ActiveRecord::Base
|
128
|
-
self.table_name =
|
172
|
+
self.table_name = "companies"
|
129
173
|
audited on: [:create, :update]
|
130
174
|
end
|
175
|
+
|
176
|
+
class OnTouchOnly < ::ActiveRecord::Base
|
177
|
+
self.table_name = "users"
|
178
|
+
audited on: [:touch]
|
179
|
+
end
|
131
180
|
end
|
132
181
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
class ChangeAuditedChangesTypeToJson < parent
|
1
|
+
class ChangeAuditedChangesTypeToJson < ActiveRecord::Migration[5.0]
|
3
2
|
def self.up
|
4
3
|
remove_column :audits, :audited_changes
|
5
4
|
add_column :audits, :audited_changes, :json
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
class ChangeAuditedChangesTypeToJsonb < parent
|
1
|
+
class ChangeAuditedChangesTypeToJsonb < ActiveRecord::Migration[5.0]
|
3
2
|
def self.up
|
4
3
|
remove_column :audits, :audited_changes
|
5
4
|
add_column :audits, :audited_changes, :jsonb
|
@@ -1,28 +1,33 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "active_record"
|
2
|
+
require "logger"
|
3
3
|
|
4
4
|
begin
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
raise Exception.new('No database name specified.') if db_name.blank?
|
9
|
-
if db_type == 'sqlite3'
|
10
|
-
db_file = Pathname.new(__FILE__).dirname.join(db_name)
|
11
|
-
db_file.unlink if db_file.file?
|
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)
|
12
8
|
else
|
13
|
-
|
14
|
-
|
15
|
-
|
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!
|
16
24
|
end
|
17
|
-
adapter = ActiveRecord::Base.send("#{db_type}_connection", db_config)
|
18
|
-
adapter.recreate_database db_name, db_config.slice('charset').symbolize_keys
|
19
|
-
adapter.disconnect!
|
20
25
|
end
|
21
26
|
rescue => e
|
22
27
|
Kernel.warn e
|
23
28
|
end
|
24
29
|
|
25
|
-
logfile = Pathname.new(__FILE__).dirname.join(
|
30
|
+
logfile = Pathname.new(__FILE__).dirname.join("debug.log")
|
26
31
|
logfile.unlink if logfile.file?
|
27
32
|
ActiveRecord::Base.logger = Logger.new(logfile)
|
28
33
|
|
@@ -41,6 +46,8 @@ ActiveRecord::Schema.define do
|
|
41
46
|
t.column :created_at, :datetime
|
42
47
|
t.column :updated_at, :datetime
|
43
48
|
t.column :favourite_device, :string
|
49
|
+
t.column :ssn, :integer
|
50
|
+
t.column :phone_numbers, :string
|
44
51
|
end
|
45
52
|
|
46
53
|
create_table :companies do |t|
|
@@ -75,9 +82,9 @@ ActiveRecord::Schema.define do
|
|
75
82
|
t.column :created_at, :datetime
|
76
83
|
end
|
77
84
|
|
78
|
-
add_index :audits, [:auditable_id, :auditable_type], name:
|
79
|
-
add_index :audits, [:associated_id, :associated_type], name:
|
80
|
-
add_index :audits, [:user_id, :user_type], name:
|
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"
|
81
88
|
add_index :audits, :request_uuid
|
82
89
|
add_index :audits, :created_at
|
83
90
|
end
|
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:
|
15
|
-
add_index :audits, [:user_id, :user_type], name:
|
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:
|
16
|
-
add_index :audits, [:user_id, :user_type], name:
|
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:
|
16
|
-
add_index :audits, [:user_id, :user_type], name:
|
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:
|
17
|
-
add_index :audits, [:user_id, :user_type], name:
|
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
data/test/db/version_6.rb
CHANGED