audit 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/audit.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'audit'
16
- s.version = '0.1.0'
17
- s.date = '2010-09-29'
16
+ s.version = '0.2.0'
17
+ s.date = '2010-10-05'
18
18
  s.rubyforge_project = 'audit'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
data/lib/audit.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  module Audit
4
4
 
5
5
  # Everything needs a version.
6
- VERSION = '0.1.0'
6
+ VERSION = '0.2.0'
7
7
 
8
8
  autoload :Log, "audit/log"
9
9
  autoload :Changeset, "audit/changeset"
@@ -28,6 +28,11 @@ module Audit::Tracking
28
28
  #
29
29
  # Returns nothing.
30
30
  def audit
31
+ if @skip_audit
32
+ @skip_audit = false
33
+ return
34
+ end
35
+
31
36
  data = {"changes" => changes, "metadata" => audit_metadata}
32
37
  Audit::Tracking.log.record(audit_bucket, self.id, data)
33
38
  @audit_metadata = {}
@@ -48,5 +53,13 @@ module Audit::Tracking
48
53
  def audit_metadata(metadata={})
49
54
  @audit_metadata = @audit_metadata.try(:update, metadata) || metadata
50
55
  end
56
+
57
+ # Public: skip writing audit meatadata for the next write.
58
+ #
59
+ # Returns: nothing
60
+ def skip_audit
61
+ @skip_audit = true
62
+ nil
63
+ end
51
64
 
52
65
  end
@@ -20,13 +20,9 @@ class TrackingTest < Test::Unit::TestCase
20
20
  super
21
21
  @model = User.new
22
22
  end
23
-
24
- context "generate an audit bucket name" do
25
-
26
- should "based on the model name" do
27
- assert_equal :Users, @model.audit_bucket
28
- end
29
-
23
+
24
+ should "generate an audit bucket name based on the model name" do
25
+ assert_equal :Users, @model.audit_bucket
30
26
  end
31
27
 
32
28
  should "track audit metadata for the next save" do
@@ -44,7 +40,7 @@ class TrackingTest < Test::Unit::TestCase
44
40
  end
45
41
 
46
42
  should "add audit-related methods" do
47
- assert_equal %w{audit audit_bucket audit_metadata audits},
43
+ assert_equal %w{audit audit_bucket audit_metadata audits skip_audit},
48
44
  @model.methods.map { |s| s.to_s }.grep(/audit/).sort
49
45
  end
50
46
 
@@ -58,5 +54,14 @@ class TrackingTest < Test::Unit::TestCase
58
54
 
59
55
  Audit::Tracking.log = Audit::Log
60
56
  end
57
+
58
+ should "disable audits for the next write" do
59
+ user = User.create(:username => "adam", :age => 31)
60
+ user.skip_audit
61
+
62
+ user.save!
63
+
64
+ assert_equal 0, user.audits.length
65
+ end
61
66
 
62
67
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 2
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.2.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Adam Keys
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-29 00:00:00 -05:00
17
+ date: 2010-10-05 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency