pg_audit_log 0.1.0 → 0.1.1

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.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.9.2-p136@pg_audit_log
1
+ rvm 1.9.2-p136@pg_audit_log --create
@@ -1,5 +1,5 @@
1
1
  module PgAuditLog
2
- class Function < ActiveRecord
2
+ class Function < PgAuditLog::ActiveRecord
3
3
  class << self
4
4
  def install
5
5
  execute <<-SQL
@@ -1,5 +1,5 @@
1
1
  module PgAuditLog
2
- class Triggers < ActiveRecord
2
+ class Triggers < PgAuditLog::ActiveRecord
3
3
  class << self
4
4
  def tables
5
5
  connection.tables - (PgAuditLog::IGNORED_TABLES + [PgAuditLog::Entry.table_name])
@@ -17,6 +17,27 @@ module PgAuditLog
17
17
  end
18
18
  end
19
19
 
20
+ def enable
21
+ tables.each do |table|
22
+ enable_for_table(table)
23
+ end
24
+ end
25
+
26
+ def disable
27
+ tables.each do |table|
28
+ disable_for_table(table)
29
+ end
30
+ end
31
+
32
+ def without_triggers
33
+ begin
34
+ disable
35
+ yield
36
+ ensure
37
+ enable
38
+ end
39
+ end
40
+
20
41
  def create_for_table(table_name)
21
42
  execute <<-SQL
22
43
  CREATE TRIGGER audit_#{table_name}
@@ -28,9 +49,20 @@ module PgAuditLog
28
49
  end
29
50
 
30
51
  def drop_for_table(table_name)
31
- execute "DROP TRIGGER audit_#{table_name} ON #{table_name};"
52
+ execute "DROP TRIGGER #{trigger_name_for_table(table_name)} ON #{table_name}"
53
+ end
54
+
55
+ def enable_for_table(table_name)
56
+ execute "ALTER TABLE #{table_name} DISABLE TRIGGER #{trigger_name_for_table(table_name)}"
57
+ end
58
+
59
+ def disable_for_table(table_name)
60
+ execute "ALTER TABLE #{table_name} ENABLE TRIGGER #{trigger_name_for_table(table_name)}"
32
61
  end
33
62
 
63
+ def trigger_name_for_table(table_name)
64
+ "audit_#{table_name}"
65
+ end
34
66
  end
35
67
  end
36
68
  end
@@ -1,3 +1,3 @@
1
1
  module PgAuditLog
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe PgAuditLog::Triggers do
4
+ before :each do
5
+ PgAuditLog::Triggers.uninstall rescue nil
6
+ end
7
+
8
+ with_model :table_with_triggers do
9
+ table {}
10
+ end
11
+
12
+ describe ".install" do
13
+ it "should work" do
14
+ ->{
15
+ PgAuditLog::Triggers.install
16
+ }.should_not raise_error
17
+ end
18
+ end
19
+
20
+ context "when triggers are installed" do
21
+ before do
22
+ PgAuditLog::Triggers.install
23
+ end
24
+
25
+ describe ".uninstall" do
26
+ it "should work" do
27
+ ->{
28
+ PgAuditLog::Triggers.uninstall
29
+ }.should_not raise_error
30
+ end
31
+ end
32
+
33
+ describe ".enable" do
34
+ it "should work" do
35
+ ->{
36
+ PgAuditLog::Triggers.enable
37
+ }.should_not raise_error
38
+ end
39
+ end
40
+
41
+ describe ".disable" do
42
+ it "should work" do
43
+ ->{
44
+ PgAuditLog::Triggers.disable
45
+ }.should_not raise_error
46
+ end
47
+ end
48
+
49
+ end
50
+
51
+
52
+ end
53
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: pg_audit_log
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Case Commons, LLC
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-29 00:00:00 -04:00
13
+ date: 2011-04-15 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -93,6 +93,7 @@ files:
93
93
  - spec/model_spec.rb
94
94
  - spec/pg_audit_log_spec.rb
95
95
  - spec/spec_helper.rb
96
+ - spec/triggers_spec.rb
96
97
  has_rdoc: true
97
98
  homepage: https://github.com/Casecommons/pg_audit_log
98
99
  licenses: []
@@ -127,3 +128,4 @@ test_files:
127
128
  - spec/model_spec.rb
128
129
  - spec/pg_audit_log_spec.rb
129
130
  - spec/spec_helper.rb
131
+ - spec/triggers_spec.rb