audit 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Rakefile +0 -1
- data/audit.gemspec +7 -8
- data/lib/audit.rb +1 -1
- data/lib/audit/log.rb +1 -1
- data/lib/audit/tracking.rb +27 -1
- data/test/{test_helper.rb → helper.rb} +1 -1
- data/test/{changeset_test.rb → test_changeset.rb} +1 -1
- data/test/{log_test.rb → test_log.rb} +1 -6
- data/test/{tracking_test.rb → test_tracking.rb} +26 -4
- metadata +12 -15
- data/Gemfile.lock +0 -50
data/Gemfile
CHANGED
data/Rakefile
CHANGED
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.
|
17
|
-
s.date = '
|
16
|
+
s.version = '0.6.0'
|
17
|
+
s.date = '2011-03-22'
|
18
18
|
s.rubyforge_project = 'audit'
|
19
19
|
|
20
20
|
## Make sure your summary is short. The description may be as long
|
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
|
|
40
40
|
|
41
41
|
## List your runtime dependencies here. Runtime dependencies are those
|
42
42
|
## that are needed for an end user to actually USE your code.
|
43
|
-
s.add_dependency('cassandra', ["~> 0.
|
43
|
+
s.add_dependency('cassandra', ["~> 0.9.0"])
|
44
44
|
|
45
45
|
## List your development dependencies here. Development dependencies are
|
46
46
|
## those that are only needed during development
|
@@ -53,7 +53,6 @@ Gem::Specification.new do |s|
|
|
53
53
|
# = MANIFEST =
|
54
54
|
s.files = %w[
|
55
55
|
Gemfile
|
56
|
-
Gemfile.lock
|
57
56
|
LICENSE
|
58
57
|
README.md
|
59
58
|
Rakefile
|
@@ -66,11 +65,11 @@ Gem::Specification.new do |s|
|
|
66
65
|
lib/audit/changeset.rb
|
67
66
|
lib/audit/log.rb
|
68
67
|
lib/audit/tracking.rb
|
69
|
-
test/
|
70
|
-
test/log_test.rb
|
68
|
+
test/helper.rb
|
71
69
|
test/storage-conf.xml
|
72
|
-
test/
|
73
|
-
test/
|
70
|
+
test/test_changeset.rb
|
71
|
+
test/test_log.rb
|
72
|
+
test/test_tracking.rb
|
74
73
|
]
|
75
74
|
# = MANIFEST =
|
76
75
|
|
data/lib/audit.rb
CHANGED
data/lib/audit/log.rb
CHANGED
data/lib/audit/tracking.rb
CHANGED
@@ -34,7 +34,8 @@ module Audit::Tracking
|
|
34
34
|
end
|
35
35
|
|
36
36
|
data = {"changes" => changes, "metadata" => audit_metadata}
|
37
|
-
|
37
|
+
timestamp = Time.now.utc.iso8601(3)
|
38
|
+
Audit::Tracking.log.record(audit_bucket, self.id, timestamp, data)
|
38
39
|
@audit_metadata = {}
|
39
40
|
end
|
40
41
|
|
@@ -75,4 +76,29 @@ module Audit::Tracking
|
|
75
76
|
@skip ||= false
|
76
77
|
end
|
77
78
|
|
79
|
+
# Public: Restore the model's attributes to the state recorded by
|
80
|
+
# a changeset.
|
81
|
+
#
|
82
|
+
# changeset - the changes to undo
|
83
|
+
#
|
84
|
+
# Returns nothing.
|
85
|
+
def revert_to(changeset)
|
86
|
+
changeset.changes.each do |change|
|
87
|
+
write_attribute(change.attribute, change.old_value)
|
88
|
+
end
|
89
|
+
nil
|
90
|
+
end
|
91
|
+
|
92
|
+
# Public: Restore a model's attributes by reversing a series of changesets.
|
93
|
+
#
|
94
|
+
# changesets - the changesets to undo
|
95
|
+
#
|
96
|
+
# Returns nothing.
|
97
|
+
def revert(changesets)
|
98
|
+
changesets.each do |changeset|
|
99
|
+
revert_to(changeset)
|
100
|
+
end
|
101
|
+
nil
|
102
|
+
end
|
103
|
+
|
78
104
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
class LogTest < Test::Unit::TestCase
|
4
4
|
|
@@ -29,11 +29,6 @@ class LogTest < Test::Unit::TestCase
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
-
def teardown
|
33
|
-
# FIXME: figure out how to properly clear a keyspace or CF
|
34
|
-
Audit::Log.connection.remove(:Audits, "Users:1")
|
35
|
-
end
|
36
|
-
|
37
32
|
def timestamp
|
38
33
|
Time.now.utc.iso8601
|
39
34
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "
|
1
|
+
require "helper"
|
2
2
|
|
3
3
|
ActiveRecord::Base.establish_connection(
|
4
4
|
:adapter => 'sqlite3',
|
@@ -39,9 +39,10 @@ class TrackingTest < Test::Unit::TestCase
|
|
39
39
|
assert_equal({}, user.audit_metadata) # Should clear audit after write
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
should "add audit-related methods" do
|
43
|
+
methods = %w{audit audit_bucket audit_metadata audits
|
44
|
+
skip_audit skip_audit?}
|
45
|
+
assert_equal methods, @model.methods.map { |s| s.to_s }.grep(/audit/).sort
|
45
46
|
end
|
46
47
|
|
47
48
|
should "set the log object to an arbitrary object" do
|
@@ -65,4 +66,25 @@ class TrackingTest < Test::Unit::TestCase
|
|
65
66
|
assert !user.skip_audit?
|
66
67
|
end
|
67
68
|
|
69
|
+
should "revert the model to the state recorded by an audit" do
|
70
|
+
user = User.create(:username => "adam", :age => 31)
|
71
|
+
user.update_attributes(:username => "therealadam")
|
72
|
+
|
73
|
+
user.revert_to(user.audits.first)
|
74
|
+
|
75
|
+
assert_equal "adam", user.username
|
76
|
+
end
|
77
|
+
|
78
|
+
should "revert the model to the state represented by a series of changes" do
|
79
|
+
user = User.create(:username => "adam", :age => 31)
|
80
|
+
user.update_attributes(:username => "therealadam")
|
81
|
+
user.update_attributes(:age => 32)
|
82
|
+
user.update_attributes(:username => "akk")
|
83
|
+
user.update_attributes(:age => 33)
|
84
|
+
|
85
|
+
user.revert(user.audits[0, 4])
|
86
|
+
assert_equal 31, user.age
|
87
|
+
assert_equal "adam", user.username
|
88
|
+
end
|
89
|
+
|
68
90
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 6
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.6.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:
|
17
|
+
date: 2011-03-22 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,9 +26,9 @@ dependencies:
|
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
segments:
|
28
28
|
- 0
|
29
|
-
-
|
30
|
-
-
|
31
|
-
version: 0.
|
29
|
+
- 9
|
30
|
+
- 0
|
31
|
+
version: 0.9.0
|
32
32
|
type: :runtime
|
33
33
|
version_requirements: *id001
|
34
34
|
- !ruby/object:Gem::Dependency
|
@@ -71,7 +71,6 @@ extra_rdoc_files:
|
|
71
71
|
- LICENSE
|
72
72
|
files:
|
73
73
|
- Gemfile
|
74
|
-
- Gemfile.lock
|
75
74
|
- LICENSE
|
76
75
|
- README.md
|
77
76
|
- Rakefile
|
@@ -84,11 +83,11 @@ files:
|
|
84
83
|
- lib/audit/changeset.rb
|
85
84
|
- lib/audit/log.rb
|
86
85
|
- lib/audit/tracking.rb
|
87
|
-
- test/
|
88
|
-
- test/log_test.rb
|
86
|
+
- test/helper.rb
|
89
87
|
- test/storage-conf.xml
|
90
|
-
- test/
|
91
|
-
- test/
|
88
|
+
- test/test_changeset.rb
|
89
|
+
- test/test_log.rb
|
90
|
+
- test/test_tracking.rb
|
92
91
|
has_rdoc: true
|
93
92
|
homepage: http://github.com/therealadam/audit
|
94
93
|
licenses: []
|
@@ -119,7 +118,5 @@ rubygems_version: 1.3.6
|
|
119
118
|
signing_key:
|
120
119
|
specification_version: 2
|
121
120
|
summary: Audit logs changes to model objects to Cassandra.
|
122
|
-
test_files:
|
123
|
-
|
124
|
-
- test/log_test.rb
|
125
|
-
- test/tracking_test.rb
|
121
|
+
test_files: []
|
122
|
+
|
data/Gemfile.lock
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
activemodel (3.0.0)
|
5
|
-
activesupport (= 3.0.0)
|
6
|
-
builder (~> 2.1.2)
|
7
|
-
i18n (~> 0.4.1)
|
8
|
-
activerecord (3.0.0)
|
9
|
-
activemodel (= 3.0.0)
|
10
|
-
activesupport (= 3.0.0)
|
11
|
-
arel (~> 1.0.0)
|
12
|
-
tzinfo (~> 0.3.23)
|
13
|
-
activesupport (3.0.0)
|
14
|
-
arel (1.0.1)
|
15
|
-
activesupport (~> 3.0.0)
|
16
|
-
builder (2.1.2)
|
17
|
-
cassandra (0.8.2)
|
18
|
-
json
|
19
|
-
rake
|
20
|
-
simple_uuid (>= 0.1.0)
|
21
|
-
thrift_client (>= 0.4.0)
|
22
|
-
flexmock (0.8.7)
|
23
|
-
i18n (0.4.1)
|
24
|
-
json (1.4.6)
|
25
|
-
nokogiri (1.4.3.1)
|
26
|
-
rake (0.8.7)
|
27
|
-
shoulda (2.11.3)
|
28
|
-
simple_uuid (0.1.1)
|
29
|
-
sqlite3-ruby (1.3.1)
|
30
|
-
thrift (0.2.0.4)
|
31
|
-
thrift_client (0.4.6)
|
32
|
-
thrift
|
33
|
-
tzinfo (0.3.23)
|
34
|
-
yajl-ruby (0.7.7)
|
35
|
-
|
36
|
-
PLATFORMS
|
37
|
-
ruby
|
38
|
-
|
39
|
-
DEPENDENCIES
|
40
|
-
activemodel (~> 3.0.0)
|
41
|
-
activerecord (~> 3.0.0)
|
42
|
-
cassandra (~> 0.8.2)
|
43
|
-
flexmock (~> 0.8.7)
|
44
|
-
nokogiri (~> 1.4.3.1)
|
45
|
-
shoulda (~> 2.11.3)
|
46
|
-
sqlite3-ruby
|
47
|
-
yajl-ruby (~> 0.7.7)
|
48
|
-
|
49
|
-
METADATA
|
50
|
-
version: 1.0.6
|