acts_as_audited 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/acts_as_audited.gemspec +6 -5
- data/lib/acts_as_audited.rb +6 -5
- data/lib/acts_as_audited/audit.rb +0 -3
- data/test/acts_as_audited_test.rb +21 -3
- data/test/db/schema.rb +1 -1
- data/test/test_helper.rb +21 -0
- metadata +31 -17
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.1
|
data/acts_as_audited.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{acts_as_audited}
|
8
|
-
s.version = "1.1.
|
8
|
+
s.version = "1.1.1"
|
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{
|
12
|
+
s.date = %q{2010-04-03}
|
13
13
|
s.email = %q{brandon@opensoul.org}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
s.homepage = %q{http://github.com/collectiveidea/acts_as_audited}
|
42
42
|
s.rdoc_options = ["--charset=UTF-8"]
|
43
43
|
s.require_paths = ["lib"]
|
44
|
-
s.rubygems_version = %q{1.3.
|
44
|
+
s.rubygems_version = %q{1.3.6}
|
45
45
|
s.summary = %q{ActiveRecord extension that logs all changes to your models in an audits table}
|
46
46
|
s.test_files = [
|
47
47
|
"test/acts_as_audited_test.rb",
|
@@ -70,3 +70,4 @@ Gem::Specification.new do |s|
|
|
70
70
|
s.add_dependency(%q<jnunemaker-matchy>, [">= 0"])
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
data/lib/acts_as_audited.rb
CHANGED
@@ -69,11 +69,12 @@ module CollectiveIdea #:nodoc:
|
|
69
69
|
|
70
70
|
class_inheritable_reader :non_audited_columns
|
71
71
|
class_inheritable_reader :auditing_enabled
|
72
|
-
|
72
|
+
|
73
73
|
if options[:only]
|
74
74
|
except = self.column_names - options[:only].flatten.map(&:to_s)
|
75
75
|
else
|
76
|
-
except = [self.primary_key, inheritance_column, 'lock_version',
|
76
|
+
except = [self.primary_key, inheritance_column, 'lock_version',
|
77
|
+
'created_at', 'updated_at', 'created_on', 'updated_on']
|
77
78
|
except |= Array(options[:except]).collect(&:to_s) if options[:except]
|
78
79
|
end
|
79
80
|
write_inheritable_attribute :non_audited_columns, except
|
@@ -82,9 +83,9 @@ module CollectiveIdea #:nodoc:
|
|
82
83
|
attr_protected :audit_ids if options[:protect]
|
83
84
|
Audit.audited_class_names << self.to_s
|
84
85
|
|
85
|
-
after_create :audit_create
|
86
|
-
before_update :audit_update
|
87
|
-
after_destroy :audit_destroy
|
86
|
+
after_create :audit_create if !options[:on] || (options[:on] && options[:on].include?(:create))
|
87
|
+
before_update :audit_update if !options[:on] || (options[:on] && options[:on].include?(:update))
|
88
|
+
after_destroy :audit_destroy if !options[:on] || (options[:on] && options[:on].include?(:destroy))
|
88
89
|
|
89
90
|
attr_accessor :version
|
90
91
|
|
@@ -23,9 +23,6 @@ class Audit < ActiveRecord::Base
|
|
23
23
|
self.audited_class_names.map(&:constantize)
|
24
24
|
end
|
25
25
|
|
26
|
-
cattr_accessor :audit_as_user
|
27
|
-
self.audit_as_user = nil
|
28
|
-
|
29
26
|
# All audits made during the block called will be recorded as made
|
30
27
|
# by +user+. This method is hopefully threadsafe, making it ideal
|
31
28
|
# for background operations that require audit information.
|
@@ -11,7 +11,7 @@ module CollectiveIdea
|
|
11
11
|
User.should be_kind_of(CollectiveIdea::Acts::Audited::SingletonMethods)
|
12
12
|
end
|
13
13
|
|
14
|
-
['created_at', 'updated_at', 'lock_version', 'id', 'password'].each do |column|
|
14
|
+
['created_at', 'updated_at', 'created_on', 'updated_on', 'lock_version', 'id', 'password'].each do |column|
|
15
15
|
should "not audit #{column}" do
|
16
16
|
User.non_audited_columns.should include(column)
|
17
17
|
end
|
@@ -20,7 +20,7 @@ module CollectiveIdea
|
|
20
20
|
should "not save non-audited columns" do
|
21
21
|
create_user.audits.first.changes.keys.any?{|col| ['created_at', 'updated_at', 'password'].include? col}.should be(false)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
context "on create" do
|
25
25
|
setup { @user = create_user }
|
26
26
|
|
@@ -37,8 +37,17 @@ module CollectiveIdea
|
|
37
37
|
should "store all the audited attributes" do
|
38
38
|
@user.audits.first.changes.should == @user.audited_attributes
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
|
+
should "not audit an attribute which is excepted if specified on create and on destroy" do
|
42
|
+
on_create_destroy_except_name = OnCreateDestroyExceptName.create(:name => 'Bart')
|
43
|
+
on_create_destroy_except_name.audits.first.changes.keys.any?{|col| ['name'].include? col}.should be(false)
|
44
|
+
end
|
41
45
|
|
46
|
+
should "not save an audit if only specified on update and on destroy" do
|
47
|
+
lambda { on_update_destroy = OnUpdateDestroy.create(:name => 'Bart') }.should_not change { Audit.count }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
42
51
|
context "on update" do
|
43
52
|
setup do
|
44
53
|
@user = create_user(:name => 'Brandon')
|
@@ -73,6 +82,10 @@ module CollectiveIdea
|
|
73
82
|
end
|
74
83
|
end
|
75
84
|
|
85
|
+
should "not save an audit if only specified on create and on destroy" do
|
86
|
+
on_create_destroy = OnCreateDestroy.create(:name => 'Bart')
|
87
|
+
lambda { on_create_destroy.update_attributes :name => 'Changed' }.should_not change { Audit.count }
|
88
|
+
end
|
76
89
|
end
|
77
90
|
|
78
91
|
context "on destroy" do
|
@@ -101,6 +114,11 @@ module CollectiveIdea
|
|
101
114
|
revision = @user.audits.first.revision
|
102
115
|
revision.name.should == @user.name
|
103
116
|
end
|
117
|
+
|
118
|
+
should "not save an audit if only specified on create and on update" do
|
119
|
+
on_create_update = OnCreateUpdate.create(:name => 'Bart')
|
120
|
+
lambda { on_create_update.destroy }.should_not change { Audit.count }
|
121
|
+
end
|
104
122
|
end
|
105
123
|
|
106
124
|
context "dirty tracking" do
|
data/test/db/schema.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -30,10 +30,31 @@ class User < ActiveRecord::Base
|
|
30
30
|
write_attribute(:name, CGI.escapeHTML(val))
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
33
34
|
class Company < ActiveRecord::Base
|
34
35
|
acts_as_audited
|
35
36
|
end
|
36
37
|
|
38
|
+
class OnUpdateDestroy < ActiveRecord::Base
|
39
|
+
set_table_name 'companies'
|
40
|
+
acts_as_audited :on => [:update, :destroy]
|
41
|
+
end
|
42
|
+
|
43
|
+
class OnCreateDestroy < ActiveRecord::Base
|
44
|
+
set_table_name 'companies'
|
45
|
+
acts_as_audited :on => [:create, :destroy]
|
46
|
+
end
|
47
|
+
|
48
|
+
class OnCreateDestroyExceptName < ActiveRecord::Base
|
49
|
+
set_table_name 'companies'
|
50
|
+
acts_as_audited :except => :name, :on => [:create, :destroy]
|
51
|
+
end
|
52
|
+
|
53
|
+
class OnCreateUpdate < ActiveRecord::Base
|
54
|
+
set_table_name 'companies'
|
55
|
+
acts_as_audited :on => [:create, :update]
|
56
|
+
end
|
57
|
+
|
37
58
|
class Test::Unit::TestCase
|
38
59
|
# def change(receiver=nil, message=nil, &block)
|
39
60
|
# ChangeExpectation.new(self, receiver, message, &block)
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_audited
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 1.1.1
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Brandon Keepers
|
@@ -9,39 +14,46 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-04-03 00:00:00 -04:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: activerecord
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 1
|
23
30
|
version: "2.1"
|
24
|
-
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
25
33
|
- !ruby/object:Gem::Dependency
|
26
34
|
name: thoughtbot-shoulda
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
37
|
requirements:
|
31
38
|
- - ">="
|
32
39
|
- !ruby/object:Gem::Version
|
40
|
+
segments:
|
41
|
+
- 0
|
33
42
|
version: "0"
|
34
|
-
|
43
|
+
type: :development
|
44
|
+
version_requirements: *id002
|
35
45
|
- !ruby/object:Gem::Dependency
|
36
46
|
name: jnunemaker-matchy
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
prerelease: false
|
48
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
49
|
requirements:
|
41
50
|
- - ">="
|
42
51
|
- !ruby/object:Gem::Version
|
52
|
+
segments:
|
53
|
+
- 0
|
43
54
|
version: "0"
|
44
|
-
|
55
|
+
type: :development
|
56
|
+
version_requirements: *id003
|
45
57
|
description:
|
46
58
|
email: brandon@opensoul.org
|
47
59
|
executables: []
|
@@ -86,18 +98,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
86
98
|
requirements:
|
87
99
|
- - ">="
|
88
100
|
- !ruby/object:Gem::Version
|
101
|
+
segments:
|
102
|
+
- 0
|
89
103
|
version: "0"
|
90
|
-
version:
|
91
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
105
|
requirements:
|
93
106
|
- - ">="
|
94
107
|
- !ruby/object:Gem::Version
|
108
|
+
segments:
|
109
|
+
- 0
|
95
110
|
version: "0"
|
96
|
-
version:
|
97
111
|
requirements: []
|
98
112
|
|
99
113
|
rubyforge_project:
|
100
|
-
rubygems_version: 1.3.
|
114
|
+
rubygems_version: 1.3.6
|
101
115
|
signing_key:
|
102
116
|
specification_version: 3
|
103
117
|
summary: ActiveRecord extension that logs all changes to your models in an audits table
|