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 CHANGED
@@ -1,6 +1,6 @@
1
1
  source :gemcutter
2
2
 
3
- gem "cassandra", "~> 0.8.2"
3
+ gem "cassandra", "~> 0.9.0"
4
4
  gem "activemodel", "~> 3.0.0"
5
5
  gem "yajl-ruby", "~> 0.7.7"
6
6
 
data/Rakefile CHANGED
@@ -37,7 +37,6 @@ task :default => :test
37
37
 
38
38
  Rake::TestTask.new do |t|
39
39
  t.libs << "test"
40
- t.test_files = FileList['test/*_test.rb']
41
40
  end
42
41
 
43
42
  desc "Run tests against all supported Ruby versions"
@@ -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.5.0'
17
- s.date = '2010-11-17'
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.8.2"])
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/changeset_test.rb
70
- test/log_test.rb
68
+ test/helper.rb
71
69
  test/storage-conf.xml
72
- test/test_helper.rb
73
- test/tracking_test.rb
70
+ test/test_changeset.rb
71
+ test/test_log.rb
72
+ test/test_tracking.rb
74
73
  ]
75
74
  # = MANIFEST =
76
75
 
@@ -3,7 +3,7 @@
3
3
  module Audit
4
4
 
5
5
  # Everything needs a version.
6
- VERSION = '0.5.0'
6
+ VERSION = '0.6.0'
7
7
 
8
8
  autoload :Log, "audit/log"
9
9
  autoload :Changeset, "audit/changeset"
@@ -1,4 +1,4 @@
1
- require 'cassandra'
1
+ require 'cassandra/0.7'
2
2
  require 'active_support/core_ext/module'
3
3
  require 'simple_uuid'
4
4
  require 'yajl'
@@ -34,7 +34,8 @@ module Audit::Tracking
34
34
  end
35
35
 
36
36
  data = {"changes" => changes, "metadata" => audit_metadata}
37
- Audit::Tracking.log.record(audit_bucket, self.id, Time.now.utc.iso8601, data)
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
@@ -5,7 +5,7 @@ Bundler.setup
5
5
  require 'test/unit'
6
6
  require 'shoulda'
7
7
  require 'flexmock/test_unit'
8
- require 'cassandra'
8
+ require 'cassandra/0.6'
9
9
  require 'cassandra/mock'
10
10
  require 'active_record'
11
11
  require 'audit'
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require 'helper'
2
2
 
3
3
  class ChangesetTest < Test::Unit::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require 'test_helper'
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 "test_helper"
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
- should_eventually "add audit-related methods" do
43
- assert_equal %w{audit audit_bucket audit_metadata audits skip_audit},
44
- @model.methods.map { |s| s.to_s }.grep(/audit/).sort
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
- - 5
7
+ - 6
8
8
  - 0
9
- version: 0.5.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: 2010-11-17 00:00:00 -06:00
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
- - 8
30
- - 2
31
- version: 0.8.2
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/changeset_test.rb
88
- - test/log_test.rb
86
+ - test/helper.rb
89
87
  - test/storage-conf.xml
90
- - test/test_helper.rb
91
- - test/tracking_test.rb
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
- - test/changeset_test.rb
124
- - test/log_test.rb
125
- - test/tracking_test.rb
121
+ test_files: []
122
+
@@ -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