cia 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/Readme.md +3 -0
- data/gemfiles/rails2.gemfile.lock +1 -1
- data/gemfiles/rails3.gemfile.lock +1 -1
- data/lib/cia.rb +9 -2
- data/lib/cia/version.rb +1 -1
- data/spec/cia_spec.rb +24 -19
- data/spec/spec_helper.rb +1 -11
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/Readme.md
CHANGED
@@ -49,6 +49,9 @@ end
|
|
49
49
|
User.last.cia_events
|
50
50
|
changes = User.last.cia_attribute_changes
|
51
51
|
last_passwords = changes.where(:attribute_name => "crypted_password").map(&:new_value)
|
52
|
+
|
53
|
+
# exceptions (raised by default)
|
54
|
+
CIA.exception_handler = lambda{|e| raise e unless Rails.env.production? }
|
52
55
|
```
|
53
56
|
|
54
57
|
|
data/lib/cia.rb
CHANGED
@@ -10,6 +10,10 @@ require 'cia/delete_event'
|
|
10
10
|
require 'cia/attribute_change'
|
11
11
|
|
12
12
|
module CIA
|
13
|
+
class << self
|
14
|
+
attr_accessor :exception_handler
|
15
|
+
end
|
16
|
+
|
13
17
|
def self.audit(options = {})
|
14
18
|
Thread.current[:cia_transaction] = Transaction.new(options)
|
15
19
|
yield
|
@@ -24,7 +28,10 @@ module CIA
|
|
24
28
|
def self.record_audit(event_type, object)
|
25
29
|
CIA.current_transaction.record(event_type, object)
|
26
30
|
rescue Object => e
|
27
|
-
|
28
|
-
|
31
|
+
if exception_handler
|
32
|
+
exception_handler.call e
|
33
|
+
else
|
34
|
+
raise e
|
35
|
+
end
|
29
36
|
end
|
30
37
|
end
|
data/lib/cia/version.rb
CHANGED
data/spec/cia_spec.rb
CHANGED
@@ -49,11 +49,6 @@ describe CIA do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
before do
|
53
|
-
Rails.stub(:logger).and_return(mock(:error => ""))
|
54
|
-
Rails.env.stub(:production?).and_return(true)
|
55
|
-
end
|
56
|
-
|
57
52
|
it "tracks create" do
|
58
53
|
expect{
|
59
54
|
object.save!
|
@@ -77,29 +72,39 @@ describe CIA do
|
|
77
72
|
CIA::Event.last.class.should == CIA::UpdateEvent
|
78
73
|
end
|
79
74
|
|
80
|
-
context "
|
75
|
+
context "exception_handler" do
|
81
76
|
before do
|
82
|
-
|
83
|
-
Rails.env.stub(:production?).and_return(true)
|
77
|
+
$stderr.stub(:puts)
|
84
78
|
transaction.stub(:record).and_raise(StandardError.new("foo"))
|
85
79
|
end
|
86
80
|
|
87
|
-
|
88
|
-
|
89
|
-
|
81
|
+
def capture_exception
|
82
|
+
begin
|
83
|
+
old = CIA.exception_handler
|
84
|
+
ex = nil
|
85
|
+
CIA.exception_handler = lambda{|e| ex = e }
|
86
|
+
yield
|
87
|
+
ex
|
88
|
+
rescue
|
89
|
+
CIA.exception_handler = old
|
90
|
+
end
|
90
91
|
end
|
91
92
|
|
92
|
-
it "
|
93
|
-
|
94
|
-
|
95
|
-
expect {
|
93
|
+
it "raises exceptions by the transaction" do
|
94
|
+
ex = nil
|
95
|
+
begin
|
96
96
|
object.save!
|
97
|
-
|
97
|
+
rescue Object => e
|
98
|
+
ex = e
|
99
|
+
end
|
100
|
+
ex.inspect.should == '#<StandardError: foo>'
|
98
101
|
end
|
99
102
|
|
100
|
-
it "
|
101
|
-
|
102
|
-
|
103
|
+
it "can capture exception via handler" do
|
104
|
+
ex = capture_exception do
|
105
|
+
object.save!
|
106
|
+
end
|
107
|
+
ex.inspect.should == '#<StandardError: foo>'
|
103
108
|
end
|
104
109
|
end
|
105
110
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,7 +7,7 @@ ActiveRecord::Base.establish_connection(
|
|
7
7
|
)
|
8
8
|
|
9
9
|
ActiveRecord::Schema.define(:version => 1) do
|
10
|
-
eval(File.read('MIGRATION.rb'))
|
10
|
+
eval(File.read(File.expand_path('../../MIGRATION.rb', __FILE__)))
|
11
11
|
|
12
12
|
create_table :cars do |t|
|
13
13
|
t.integer :wheels
|
@@ -59,13 +59,3 @@ def create_change
|
|
59
59
|
event = create_event
|
60
60
|
CIA::AttributeChange.create!(:event => event, :source => event.source, :attribute_name => "bar")
|
61
61
|
end
|
62
|
-
|
63
|
-
module Rails
|
64
|
-
def self.logger
|
65
|
-
raise "NOT STUBBED"
|
66
|
-
end
|
67
|
-
|
68
|
-
def self.env
|
69
|
-
@@env ||= "NOT STUBBED"
|
70
|
-
end
|
71
|
-
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -59,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
59
|
version: '0'
|
60
60
|
segments:
|
61
61
|
- 0
|
62
|
-
hash:
|
62
|
+
hash: 562244213003532092
|
63
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
64
|
none: false
|
65
65
|
requirements:
|
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
68
68
|
version: '0'
|
69
69
|
segments:
|
70
70
|
- 0
|
71
|
-
hash:
|
71
|
+
hash: 562244213003532092
|
72
72
|
requirements: []
|
73
73
|
rubyforge_project:
|
74
74
|
rubygems_version: 1.8.24
|