pg_audit_log 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -2
- data/lib/pg_audit_log/extensions/postgresql_adapter.rb +16 -2
- data/lib/pg_audit_log/version.rb +1 -1
- data/spec/pg_audit_log_spec.rb +40 -14
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b43d8eee277c9366119fc9c86605ab282492c3fa
|
4
|
+
data.tar.gz: 99a1cfc28254c4ce377a6f9aefb47179272866bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5da4365b340f209b756b75775296d7d94ec59224820f05a99099b15863892cbedef024bc2aca1ee45e95079076f02d2a7ddc48d11e79b773eec6ea4ca99f54a
|
7
|
+
data.tar.gz: aabcef8f79fbf213fbd6ceed0e6dcddd6e6ba78b78d73a93d10e6027b00b753365fa855614fe580b49fd905bc184b0596bdc75898e02db4b66896e5e4e478faa
|
data/Gemfile
CHANGED
@@ -3,5 +3,5 @@ source 'https://rubygems.org'
|
|
3
3
|
# Specify your gem's dependencies the .gemspec
|
4
4
|
gemspec
|
5
5
|
|
6
|
-
gem 'rails', :github => 'rails', :branch => ENV['
|
7
|
-
gem 'rails', ENV['RAILS_VERSION'] if ENV['
|
6
|
+
gem 'rails', :github => 'rails', :branch => ENV['ACTIVE_RECORD_BRANCH'] if ENV['ACTIVE_RECORD_BRANCH']
|
7
|
+
gem 'rails', ENV['RAILS_VERSION'] if ENV['RAILS_VERSION']
|
@@ -62,19 +62,33 @@ class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
|
|
62
62
|
alias_method_chain :reconnect!, :pg_audit_log
|
63
63
|
|
64
64
|
def execute_with_pg_audit_log(sql, name = nil)
|
65
|
-
conn = execute_without_pg_audit_log(sql, name = nil)
|
66
65
|
set_audit_user_id_and_name
|
66
|
+
conn = execute_without_pg_audit_log(sql, name = nil)
|
67
67
|
conn
|
68
68
|
end
|
69
69
|
alias_method_chain :execute, :pg_audit_log
|
70
70
|
|
71
71
|
def exec_query_with_pg_audit_log(sql, name = 'SQL', binds = [])
|
72
|
-
conn = exec_query_without_pg_audit_log(sql, name, binds)
|
73
72
|
set_audit_user_id_and_name
|
73
|
+
conn = exec_query_without_pg_audit_log(sql, name, binds)
|
74
74
|
conn
|
75
75
|
end
|
76
76
|
alias_method_chain :exec_query, :pg_audit_log
|
77
77
|
|
78
|
+
def exec_update_with_pg_audit_log(sql, name = 'SQL', binds = [])
|
79
|
+
set_audit_user_id_and_name
|
80
|
+
conn = exec_update_without_pg_audit_log(sql, name, binds)
|
81
|
+
conn
|
82
|
+
end
|
83
|
+
alias_method_chain :exec_update, :pg_audit_log
|
84
|
+
|
85
|
+
def exec_delete_with_pg_audit_log(sql, name = 'SQL', binds = [])
|
86
|
+
set_audit_user_id_and_name
|
87
|
+
conn = exec_delete_without_pg_audit_log(sql, name, binds)
|
88
|
+
conn
|
89
|
+
end
|
90
|
+
alias_method_chain :exec_delete, :pg_audit_log
|
91
|
+
|
78
92
|
private
|
79
93
|
|
80
94
|
def user_id_and_name
|
data/lib/pg_audit_log/version.rb
CHANGED
data/spec/pg_audit_log_spec.rb
CHANGED
@@ -27,6 +27,7 @@ describe PgAuditLog do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
after do
|
30
|
+
Thread.current[:current_user] = nil
|
30
31
|
PgAuditLog::Entry.connection.execute("TRUNCATE #{PgAuditLog::Entry.quoted_table_name}")
|
31
32
|
end
|
32
33
|
|
@@ -34,37 +35,42 @@ describe PgAuditLog do
|
|
34
35
|
|
35
36
|
describe "on create" do
|
36
37
|
context "the audit log record with a primary key" do
|
37
|
-
before do
|
38
|
-
AuditedModel.create!(attributes)
|
39
|
-
end
|
40
|
-
|
41
38
|
subject { PgAuditLog::Entry.where(:field_name => 'str').last }
|
42
39
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
context "recording changes" do
|
41
|
+
before do
|
42
|
+
AuditedModel.create!(attributes)
|
43
|
+
end
|
44
|
+
|
45
|
+
it { should be }
|
46
|
+
its(:occurred_at) { should be }
|
47
|
+
its(:table_name) { should == AuditedModel.table_name }
|
48
|
+
its(:field_name) { should == 'str' }
|
49
|
+
its(:primary_key) { should == AuditedModel.last.id.to_s }
|
50
|
+
its(:operation) { should == 'INSERT' }
|
51
|
+
end
|
49
52
|
|
50
|
-
context "when a user is present" do
|
53
|
+
context "when a user is present, having just been changed" do
|
51
54
|
before do
|
55
|
+
record = AuditedModel.new
|
52
56
|
Thread.current[:current_user] = double('User', :id => 1, :unique_name => 'my current user')
|
53
|
-
|
57
|
+
ActiveRecord::Persistence.instance_method(:save).bind(record).call # call save without transaction
|
54
58
|
end
|
55
59
|
|
56
|
-
after { Thread.current[:current_user] = nil }
|
57
|
-
|
58
60
|
its(:user_id) { should == 1 }
|
59
61
|
its(:user_unique_name) { should == 'my current user' }
|
60
62
|
end
|
61
63
|
|
62
64
|
context "when no user is present" do
|
65
|
+
before { AuditedModel.create!(attributes) }
|
66
|
+
|
63
67
|
its(:user_id) { should == -1 }
|
64
68
|
its(:user_unique_name) { should == 'UNKNOWN' }
|
65
69
|
end
|
66
70
|
|
67
71
|
it "captures all new values for all fields" do
|
72
|
+
AuditedModel.create!(attributes)
|
73
|
+
|
68
74
|
attributes.each do |field_name, value|
|
69
75
|
entry = PgAuditLog::Entry.where(:field_name => field_name).last
|
70
76
|
if field_name == :dt
|
@@ -96,6 +102,19 @@ describe PgAuditLog do
|
|
96
102
|
@model = AuditedModel.create!(attributes)
|
97
103
|
end
|
98
104
|
|
105
|
+
context "when a user is present, having just been changed" do
|
106
|
+
subject { PgAuditLog::Entry.where(:field_name => 'str').last }
|
107
|
+
before do
|
108
|
+
Thread.current[:current_user] = double('User', :id => 1, :unique_name => 'my current user')
|
109
|
+
@model.str = 'foobarbaz'
|
110
|
+
# @model.class.connection.execute "select * from #{AuditedModel.table_name}"
|
111
|
+
ActiveRecord::Persistence.instance_method(:save).bind(@model).call # call save without transaction
|
112
|
+
end
|
113
|
+
|
114
|
+
its(:user_id) { should == 1 }
|
115
|
+
its(:user_unique_name) { should == 'my current user' }
|
116
|
+
end
|
117
|
+
|
99
118
|
context "when going from a value to a another value" do
|
100
119
|
before { @model.update_attributes!(:str => 'bar') }
|
101
120
|
subject { PgAuditLog::Entry.where(:field_name => 'str').last }
|
@@ -207,6 +226,13 @@ describe PgAuditLog do
|
|
207
226
|
end
|
208
227
|
end
|
209
228
|
|
229
|
+
it "records with the correct user after just changing the user" do
|
230
|
+
record = AuditedModel.create!
|
231
|
+
Thread.current[:current_user] = double('User', :id => 1, :unique_name => 'my current user')
|
232
|
+
record.delete
|
233
|
+
expect(PgAuditLog::Entry.order(:occurred_at).last.user_id).to eq 1
|
234
|
+
end
|
235
|
+
|
210
236
|
context "the audit log record without a primary key" do
|
211
237
|
before do
|
212
238
|
AuditedModelWithoutPrimaryKey.create!(attributes)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg_audit_log
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Case Commons, LLC
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
requirements: []
|
146
146
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.4.
|
147
|
+
rubygems_version: 2.4.1
|
148
148
|
signing_key:
|
149
149
|
specification_version: 4
|
150
150
|
summary: PostgreSQL-only database-level audit logging of all databases changes.
|