cia 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cia (0.3.0)
4
+ cia (0.3.1)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/lib/cia.rb CHANGED
@@ -10,10 +10,11 @@ module CIA
10
10
  end
11
11
 
12
12
  def self.audit(options = {})
13
+ old = Thread.current[:cia_transaction]
13
14
  Thread.current[:cia_transaction] = options
14
15
  yield
15
16
  ensure
16
- Thread.current[:cia_transaction] = nil
17
+ Thread.current[:cia_transaction] = old
17
18
  end
18
19
 
19
20
  def self.current_transaction
@@ -28,11 +29,11 @@ module CIA
28
29
 
29
30
  return if not message and changes.empty? and action.to_s == "update"
30
31
 
31
- event = CIA::Event.create!(
32
+ event = CIA::Event.create!(current_transaction.merge(
32
33
  :action => action.to_s,
33
34
  :source => source,
34
35
  :message => message
35
- )
36
+ ))
36
37
  event.record_attribute_changes!(changes)
37
38
  event
38
39
  rescue Object => e
@@ -1,3 +1,3 @@
1
1
  module CIA
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -37,6 +37,19 @@ describe CIA do
37
37
  CIA.current_transaction.should == nil
38
38
  sleep 0.04 # so next tests dont fail
39
39
  end
40
+
41
+ it "can stack" do
42
+ states = []
43
+ CIA.audit(:a => 1) do
44
+ states << CIA.current_transaction
45
+ CIA.audit(:b => 1) do
46
+ states << CIA.current_transaction
47
+ end
48
+ states << CIA.current_transaction
49
+ end
50
+ states << CIA.current_transaction
51
+ states.should == [{:a => 1}, {:b => 1}, {:a => 1}, nil]
52
+ end
40
53
  end
41
54
 
42
55
  describe ".record" do
@@ -76,6 +89,14 @@ describe CIA do
76
89
  event.attribute_changes.map { |c| [c.attribute_name, c.old_value, c.new_value] }
77
90
  end
78
91
 
92
+ it "records attributes in transaction" do
93
+ event = nil
94
+ CIA.audit :actor => User.create!, :ip_address => "1.2.3.4" do
95
+ event = CIA.record(:destroy, Car.create!)
96
+ end
97
+ event.ip_address.should == "1.2.3.4"
98
+ end
99
+
79
100
  it "records attribute creations" do
80
101
  source = Car.create!
81
102
  source.wheels = 4
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.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -53,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
53
53
  version: '0'
54
54
  segments:
55
55
  - 0
56
- hash: -1846204307001126824
56
+ hash: -507458673584956374
57
57
  required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  none: false
59
59
  requirements:
@@ -62,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
62
  version: '0'
63
63
  segments:
64
64
  - 0
65
- hash: -1846204307001126824
65
+ hash: -507458673584956374
66
66
  requirements: []
67
67
  rubyforge_project:
68
68
  rubygems_version: 1.8.24