cia 0.4.2 → 0.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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cia (0.4.2)
4
+ cia (0.4.3)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/cia
3
3
  specs:
4
- cia (0.4.1)
4
+ cia (0.4.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/mgrosser/code/tools/cia
3
3
  specs:
4
- cia (0.4.1)
4
+ cia (0.4.2)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/lib/cia.rb CHANGED
@@ -36,7 +36,7 @@ module CIA
36
36
  return if options and options[:if] and not source.send(options[:if])
37
37
  return if options and options[:unless] and source.send(options[:unless])
38
38
 
39
- changes = source.cia_changes.slice(*source.class.audited_attributes)
39
+ changes = (source.stored_cia_changes || source.cia_changes).slice(*source.class.audited_attributes)
40
40
  message = source.audit_message if source.respond_to?(:audit_message)
41
41
 
42
42
  return if not message and changes.empty? and action.to_s == "update"
@@ -9,6 +9,15 @@ module CIA
9
9
  changes
10
10
  end
11
11
 
12
+ def stored_cia_changes(changes=nil)
13
+ if changes
14
+ @stored_cia_changes = changes
15
+ else
16
+ old, @stored_cia_changes = @stored_cia_changes, nil
17
+ old
18
+ end
19
+ end
20
+
12
21
  module ClassMethods
13
22
  def audit_attribute(*attributes)
14
23
  options = (attributes.last.is_a?(Hash) ? attributes.pop : {})
@@ -28,11 +37,12 @@ module CIA
28
37
  self.audited_attributes_callbacks_added = true
29
38
 
30
39
  [:create, :update, :destroy].each do |callback|
31
- method, args = if options[:callback]
32
- if ActiveRecord::VERSION::MAJOR == 2 && options[:callback] == :after_commit
40
+ method, args = if options[:callback] == :after_commit
41
+ send("after_#{callback}"){ |record| record.stored_cia_changes(record.cia_changes) }
42
+ if ActiveRecord::VERSION::MAJOR == 2
33
43
  ["after_commit_on_#{callback}", []]
34
44
  else # rails 3+
35
- [options[:callback], [{:on => callback}]]
45
+ [:after_commit, [{:on => callback}]]
36
46
  end
37
47
  else
38
48
  ["after_#{callback}", []]
@@ -1,3 +1,3 @@
1
1
  module CIA
2
- VERSION = '0.4.2'
2
+ VERSION = '0.4.3'
3
3
  end
@@ -315,12 +315,28 @@ describe CIA do
315
315
  end
316
316
 
317
317
  context "with after_commit" do
318
- let(:object){ CarWithTransactions.new }
318
+ let(:object){ CarWithTransactions.new(:wheels => 1) }
319
319
 
320
320
  it "still tracks" do
321
321
  expect{
322
322
  CIA.audit{ object.save! }
323
323
  }.to change{ CIA::Event.count }.by(+1)
324
+ CIA::Event.last.attribute_change_hash.should == {"wheels" => [nil, "1"]}
325
+ end
326
+
327
+ it "unsets temp-changes after the save" do
328
+ object.save!
329
+
330
+ # does not re-track old changes
331
+ expect{
332
+ CIA.audit{ object.update_attributes(:drivers => 2) }
333
+ }.to change{ CIA::Event.count }.by(+1)
334
+ CIA::Event.last.attribute_change_hash.should == {"drivers" => [nil, "2"]}
335
+
336
+ # empty changes
337
+ expect{
338
+ CIA.audit{ object.update_attributes(:drivers => 2) }
339
+ }.to_not change{ CIA::Event.count }
324
340
  end
325
341
 
326
342
  it "is not rolled back if auditing fails" do
@@ -89,7 +89,7 @@ end
89
89
  class CarWithTransactions < ActiveRecord::Base
90
90
  self.table_name = "cars"
91
91
  include CIA::Auditable
92
- audit_attribute :wheels, :callback => :after_commit
92
+ audit_attribute :wheels, :drivers, :callback => :after_commit
93
93
  end
94
94
 
95
95
  class NestedCar < Car
metadata CHANGED
@@ -1,22 +1,32 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cia
3
- version: !ruby/object:Gem::Version
4
- version: 0.4.2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 4
9
+ - 3
10
+ version: 0.4.3
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Michael Grosser
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2013-01-10 00:00:00.000000000 Z
17
+
18
+ date: 2013-01-10 00:00:00 Z
13
19
  dependencies: []
20
+
14
21
  description:
15
22
  email: michael@grosser.it
16
23
  executables: []
24
+
17
25
  extensions: []
26
+
18
27
  extra_rdoc_files: []
19
- files:
28
+
29
+ files:
20
30
  - .travis.yml
21
31
  - Appraisals
22
32
  - Gemfile
@@ -39,35 +49,37 @@ files:
39
49
  - spec/cia_spec.rb
40
50
  - spec/spec_helper.rb
41
51
  homepage: http://github.com/grosser/cia
42
- licenses:
52
+ licenses:
43
53
  - MIT
44
54
  post_install_message:
45
55
  rdoc_options: []
46
- require_paths:
56
+
57
+ require_paths:
47
58
  - lib
48
- required_ruby_version: !ruby/object:Gem::Requirement
59
+ required_ruby_version: !ruby/object:Gem::Requirement
49
60
  none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- segments:
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
55
66
  - 0
56
- hash: -3726638630951878810
57
- required_rubygems_version: !ruby/object:Gem::Requirement
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
69
  none: false
59
- requirements:
60
- - - ! '>='
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- segments:
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
64
75
  - 0
65
- hash: -3726638630951878810
76
+ version: "0"
66
77
  requirements: []
78
+
67
79
  rubyforge_project:
68
80
  rubygems_version: 1.8.24
69
81
  signing_key:
70
82
  specification_version: 3
71
- summary: Audit model events like update/create/delete + attribute changes + group
72
- them by transaction, in normalized table layout for easy query access.
83
+ summary: Audit model events like update/create/delete + attribute changes + group them by transaction, in normalized table layout for easy query access.
73
84
  test_files: []
85
+