acts_as_audited 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -9,8 +9,7 @@ The purpose of this fork is to store both the previous values and the changed va
9
9
  * acts_as_audited can be installed as a gem:
10
10
 
11
11
  # config/environment.rb
12
- config.gem 'collectiveidea-acts_as_audited', :lib => false,
13
- :source => 'http://gems.github.com'
12
+ config.gem 'acts_as_audited', :lib => false, :source => 'http://gemcutter.org'
14
13
 
15
14
  or a plugin:
16
15
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.0.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_audited}
8
- s.version = "1.0.1"
8
+ s.version = "1.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brandon Keepers"]
12
- s.date = %q{2009-09-28}
12
+ s.date = %q{2009-10-29}
13
13
  s.email = %q{brandon@opensoul.org}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
@@ -27,7 +27,7 @@ module CollectiveIdea #:nodoc:
27
27
  # You can also specify an options hash which will be passed on to
28
28
  # Rails' cache_sweeper call:
29
29
  #
30
- # audit User, :only => [:create, :edit, :destroy]
30
+ # audit User, :only => [:create, :edit, :destroy],
31
31
  #
32
32
  def audit(*models)
33
33
  options = models.extract_options!
@@ -39,16 +39,12 @@ module CollectiveIdea #:nodoc:
39
39
 
40
40
  models.each do |(model, model_options)|
41
41
  model.send :acts_as_audited, model_options || {}
42
-
43
- # disable ActiveRecord callbacks, which are replaced by the AuditSweeper
44
- model.send :disable_auditing_callbacks
45
-
46
- # prevent observer from being registered multiple times
47
- model.delete_observer(AuditSweeper.instance)
48
- model.add_observer(AuditSweeper.instance)
49
42
  end
50
43
 
51
44
  class_eval do
45
+ # prevent observer from being registered multiple times
46
+ Audit.delete_observer(AuditSweeper.instance)
47
+ Audit.add_observer(AuditSweeper.instance)
52
48
  cache_sweeper :audit_sweeper, options
53
49
  end
54
50
  end
@@ -59,21 +55,11 @@ module CollectiveIdea #:nodoc:
59
55
  end
60
56
 
61
57
  class AuditSweeper < ActionController::Caching::Sweeper #:nodoc:
62
-
63
- def after_create(record)
64
- record.send(:audit_create, current_user)
65
- end
66
-
67
- def after_destroy(record)
68
- record.send(:audit_destroy, current_user)
69
- end
70
-
71
- def before_update(record)
72
- record.send(:audit_update, current_user)
58
+ def before_create(record)
59
+ record.user ||= current_user
73
60
  end
74
61
 
75
62
  def current_user
76
63
  controller.send :current_user if controller.respond_to?(:current_user, true)
77
64
  end
78
-
79
65
  end
@@ -183,18 +183,18 @@ module CollectiveIdea #:nodoc:
183
183
  audits.find(:all, :conditions => ['version <= ?', version])
184
184
  end
185
185
 
186
- def audit_create(user = nil)
187
- write_audit(:action => 'create', :changes => audited_attributes, :user => user)
186
+ def audit_create
187
+ write_audit(:action => 'create', :changes => audited_attributes)
188
188
  end
189
189
 
190
- def audit_update(user = nil)
190
+ def audit_update
191
191
  unless (changes = audited_changes).empty?
192
- write_audit(:action => 'update', :changes => changes, :user => user)
192
+ write_audit(:action => 'update', :changes => changes)
193
193
  end
194
194
  end
195
195
 
196
- def audit_destroy(user = nil)
197
- write_audit(:action => 'destroy', :user => user, :changes => audited_attributes)
196
+ def audit_destroy
197
+ write_audit(:action => 'destroy', :changes => audited_attributes)
198
198
  end
199
199
 
200
200
  def write_audit(attrs)
@@ -1,13 +1,18 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/test_helper')
2
2
 
3
3
  class AuditsController < ActionController::Base
4
- audit Company
4
+ audit Company, User
5
5
 
6
6
  def audit
7
7
  @company = Company.create
8
8
  render :nothing => true
9
9
  end
10
10
 
11
+ def update_user
12
+ current_user.update_attributes({:password => 'foo'})
13
+ render :nothing => true
14
+ end
15
+
11
16
  private
12
17
  attr_accessor :current_user
13
18
  end
@@ -26,4 +31,9 @@ class AuditsControllerTest < ActionController::TestCase
26
31
  assigns(:company).audits.last.user.should == user
27
32
  end
28
33
 
34
+ should "not save blank audits" do
35
+ user = @controller.send(:current_user=, create_user)
36
+ lambda { post :update_user }.should_not change { Audit.count }
37
+ end
38
+
29
39
  end
data/test/test_helper.rb CHANGED
@@ -31,6 +31,7 @@ class User < ActiveRecord::Base
31
31
  end
32
32
  end
33
33
  class Company < ActiveRecord::Base
34
+ acts_as_audited
34
35
  end
35
36
 
36
37
  class Test::Unit::TestCase
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_audited
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-28 00:00:00 -04:00
12
+ date: 2009-10-29 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency