acts_as_audited 2.0.0.rc4 → 2.0.0.rc5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +11 -2
- data/README.rdoc +25 -3
- data/Rakefile +1 -1
- data/acts_as_audited.gemspec +93 -72
- data/lib/acts_as_audited.rb +1 -1
- data/lib/acts_as_audited/audit.rb +2 -1
- data/lib/acts_as_audited/auditor.rb +8 -0
- data/lib/generators/acts_as_audited/templates/add_association_to_audits.rb +11 -0
- data/lib/generators/acts_as_audited/templates/install.rb +3 -0
- data/lib/generators/acts_as_audited/templates/rename_parent_to_association.rb +11 -0
- data/lib/generators/acts_as_audited/upgrade_generator.rb +8 -0
- data/spec/acts_as_audited_spec.rb +29 -0
- data/spec/db/schema.rb +13 -0
- data/spec/spec_models.rb +12 -0
- data/test/db/version_4.rb +20 -0
- data/test/upgrade_generator_test.rb +11 -0
- metadata +7 -2
data/CHANGELOG
CHANGED
@@ -1,8 +1,17 @@
|
|
1
|
-
|
1
|
+
acts_as_audited ChangeLog
|
2
2
|
-------------------------------------------------------------------------------
|
3
|
+
|
4
|
+
Not released - 2.0.0
|
5
|
+
Rails 3 support
|
6
|
+
Support for associated audits
|
7
|
+
Support for remote IP address storage
|
8
|
+
Plenty of bug fixes and refactoring
|
9
|
+
|
3
10
|
* 2009-01-27 - Store old and new values for updates, and store all attributes on destroy.
|
4
11
|
Refactored revisioning methods to work as expected
|
5
12
|
* 2008-10-10 - changed to make it work in development mode
|
13
|
+
* 2008-09-24 - Add ability to record parent record of the record being audited
|
14
|
+
[Kenneth Kalmer]
|
6
15
|
* 2008-04-19 - refactored to make compatible with dirty tracking in edge rails
|
7
16
|
and to stop storing both old and new values in a single audit
|
8
17
|
* 2008-04-18 - Fix NoMethodError when trying to access the :previous revision
|
@@ -22,4 +31,4 @@
|
|
22
31
|
that saves the new value after every change and not just the
|
23
32
|
first, and performs proper type-casting before doing comparisons
|
24
33
|
* 2006-08-14 - The "changes" are now saved as a serialized hash
|
25
|
-
* 2006-07-21 - initial version
|
34
|
+
* 2006-07-21 - initial version
|
data/README.rdoc
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
+acts_as_audited+ is an ActiveRecord extension that logs all changes to your
|
4
4
|
models in an audits table, with optional revision comments. +acts_as_audited+
|
5
5
|
has been updated to work with Rails 3, to use it with older version of Rails,
|
6
|
-
please see the <tt>
|
6
|
+
please see the <tt>1.1-stable</tt> branch.
|
7
7
|
|
8
8
|
== Installation
|
9
9
|
|
10
10
|
In <tt>Gemfile</tt>:
|
11
11
|
|
12
|
-
gem "acts_as_audited", "2.0.0.
|
12
|
+
gem "acts_as_audited", "2.0.0.rc5"
|
13
13
|
|
14
14
|
In your application root, run:
|
15
15
|
|
@@ -50,6 +50,19 @@ before create/update/destroy. If the <tt>:comment_required</tt> option is given
|
|
50
50
|
the save/update/destroy action will fail with add an error on <tt>model.audit_comment</tt> and triggering a
|
51
51
|
transaction rollback if <tt>model.audit_comment</tt> is nil.
|
52
52
|
|
53
|
+
To record an audit for an associated model, use the <tt>:associated_with</tt> option.
|
54
|
+
|
55
|
+
class User < ActiveRecord::Base
|
56
|
+
acts_as_audited :associated_with => :company
|
57
|
+
end
|
58
|
+
|
59
|
+
If desired, the associated model can access its audits using <tt>has_associated_audits</tt>.
|
60
|
+
|
61
|
+
class Company < ActiveRecord::Base
|
62
|
+
has_many :users
|
63
|
+
has_associated_audits
|
64
|
+
end
|
65
|
+
|
53
66
|
To record a user in the audits outside of a web request, you can use +as_user+:
|
54
67
|
|
55
68
|
Audit.as_user(user) do
|
@@ -65,9 +78,11 @@ If your model declares +attr_accessible+ after +acts_as_audited+, you need to se
|
|
65
78
|
attr_accessible :name
|
66
79
|
end
|
67
80
|
|
81
|
+
Another caveat is documented in issue 26[https://github.com/collectiveidea/acts_as_audited/issues#issue/26], where an audit created on the first request to the server does not have a user. Please review the Github issue for more details on how to fix this. It does not appear to affect Rails 3.
|
82
|
+
|
68
83
|
== Compatability
|
69
84
|
|
70
|
-
+acts_as_audited+ works with Rails 3.0.
|
85
|
+
+acts_as_audited+ works with Rails 3.0.3. For older versions of Rails, please see the <tt>1.1-stable</tt> branch.
|
71
86
|
|
72
87
|
== Getting Help
|
73
88
|
|
@@ -75,10 +90,16 @@ Review the documentation at http://rdoc.info/github/collectiveidea/acts_as_audit
|
|
75
90
|
|
76
91
|
Join the mailing list for getting help or offering suggestions - http://groups.google.com/group/acts_as_audited
|
77
92
|
|
93
|
+
== Branches
|
94
|
+
|
95
|
+
The <tt>master</tt> branch is considered stable, and you should be able to use it at any time. The <tt>development</tt> branch will contain all active development and might be a moving target from time to time.
|
96
|
+
|
78
97
|
== Contributing
|
79
98
|
|
80
99
|
Contributions are always welcome. Checkout the latest code on GitHub - http://github.com/collectiveidea/acts_as_audited
|
81
100
|
|
101
|
+
When contributing a bug-fix, please use a topic branch created off our <tt>master</tt> branch. When developing a new feature, please create a topic branch of our <tt>development</tt> branch (and rebase before submiting a pull request).
|
102
|
+
|
82
103
|
Please include tests with your patches. There are a few gems required to run the tests:
|
83
104
|
|
84
105
|
$ bundle install
|
@@ -88,3 +109,4 @@ Make sure the tests pass against the version of Rails specified in the Gemfile
|
|
88
109
|
$ rake spec test
|
89
110
|
|
90
111
|
Please report bugs or feature suggestions on GitHub - http://github.com/collectiveidea/acts_as_audited/issues
|
112
|
+
|
data/Rakefile
CHANGED
@@ -16,7 +16,7 @@ begin
|
|
16
16
|
gem.summary = %Q{ActiveRecord extension that logs all changes to your models in an audits table}
|
17
17
|
gem.email = "brandon@opensoul.org"
|
18
18
|
gem.homepage = "http://github.com/collectiveidea/acts_as_audited"
|
19
|
-
gem.authors = ["Brandon Keepers"]
|
19
|
+
gem.authors = ["Brandon Keepers", "Kenneth Kalmer"]
|
20
20
|
gem.rdoc_options << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
|
21
21
|
gem.version = ActsAsAudited::VERSION
|
22
22
|
|
data/acts_as_audited.gemspec
CHANGED
@@ -1,95 +1,98 @@
|
|
1
1
|
# Generated by jeweler
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
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 = "2.0.0.
|
8
|
+
s.version = "2.0.0.rc5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Brandon Keepers"]
|
12
|
-
s.date = %q{2011-02-
|
11
|
+
s.authors = ["Brandon Keepers", "Kenneth Kalmer"]
|
12
|
+
s.date = %q{2011-02-05}
|
13
13
|
s.email = %q{brandon@opensoul.org}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
16
|
-
|
16
|
+
"README.rdoc"
|
17
17
|
]
|
18
18
|
s.files = [
|
19
|
-
".
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
19
|
+
".yardopts",
|
20
|
+
"CHANGELOG",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"acts_as_audited.gemspec",
|
27
|
+
"autotest/discover.rb",
|
28
|
+
"lib/acts_as_audited.rb",
|
29
|
+
"lib/acts_as_audited/audit.rb",
|
30
|
+
"lib/acts_as_audited/audit_sweeper.rb",
|
31
|
+
"lib/acts_as_audited/auditor.rb",
|
32
|
+
"lib/generators/acts_as_audited/install_generator.rb",
|
33
|
+
"lib/generators/acts_as_audited/templates/add_association_to_audits.rb",
|
34
|
+
"lib/generators/acts_as_audited/templates/add_comment_to_audits.rb",
|
35
|
+
"lib/generators/acts_as_audited/templates/add_remote_address_to_audits.rb",
|
36
|
+
"lib/generators/acts_as_audited/templates/install.rb",
|
37
|
+
"lib/generators/acts_as_audited/templates/rename_changes_to_audited_changes.rb",
|
38
|
+
"lib/generators/acts_as_audited/templates/rename_parent_to_association.rb",
|
39
|
+
"lib/generators/acts_as_audited/upgrade_generator.rb",
|
40
|
+
"spec/acts_as_audited_spec.rb",
|
41
|
+
"spec/audit_spec.rb",
|
42
|
+
"spec/audit_sweeper_spec.rb",
|
43
|
+
"spec/audited_spec_helpers.rb",
|
44
|
+
"spec/db/schema.rb",
|
45
|
+
"spec/rails_app/config/application.rb",
|
46
|
+
"spec/rails_app/config/boot.rb",
|
47
|
+
"spec/rails_app/config/database.yml",
|
48
|
+
"spec/rails_app/config/environment.rb",
|
49
|
+
"spec/rails_app/config/environments/development.rb",
|
50
|
+
"spec/rails_app/config/environments/production.rb",
|
51
|
+
"spec/rails_app/config/environments/test.rb",
|
52
|
+
"spec/rails_app/config/initializers/backtrace_silencers.rb",
|
53
|
+
"spec/rails_app/config/initializers/inflections.rb",
|
54
|
+
"spec/rails_app/config/initializers/secret_token.rb",
|
55
|
+
"spec/rails_app/config/routes.rb",
|
56
|
+
"spec/spec_helper.rb",
|
57
|
+
"spec/spec_models.rb",
|
58
|
+
"test/db/version_1.rb",
|
59
|
+
"test/db/version_2.rb",
|
60
|
+
"test/db/version_3.rb",
|
61
|
+
"test/db/version_4.rb",
|
62
|
+
"test/install_generator_test.rb",
|
63
|
+
"test/test_helper.rb",
|
64
|
+
"test/upgrade_generator_test.rb"
|
63
65
|
]
|
64
66
|
s.homepage = %q{http://github.com/collectiveidea/acts_as_audited}
|
65
|
-
s.rdoc_options = ["--
|
67
|
+
s.rdoc_options = ["--main", "README.rdoc", "--line-numbers", "--inline-source"]
|
66
68
|
s.require_paths = ["lib"]
|
67
69
|
s.rubygems_version = %q{1.3.7}
|
68
70
|
s.summary = %q{ActiveRecord extension that logs all changes to your models in an audits table}
|
69
71
|
s.test_files = [
|
70
72
|
"spec/acts_as_audited_spec.rb",
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
73
|
+
"spec/audit_spec.rb",
|
74
|
+
"spec/audit_sweeper_spec.rb",
|
75
|
+
"spec/audited_spec_helpers.rb",
|
76
|
+
"spec/db/schema.rb",
|
77
|
+
"spec/rails_app/config/application.rb",
|
78
|
+
"spec/rails_app/config/boot.rb",
|
79
|
+
"spec/rails_app/config/environment.rb",
|
80
|
+
"spec/rails_app/config/environments/development.rb",
|
81
|
+
"spec/rails_app/config/environments/production.rb",
|
82
|
+
"spec/rails_app/config/environments/test.rb",
|
83
|
+
"spec/rails_app/config/initializers/backtrace_silencers.rb",
|
84
|
+
"spec/rails_app/config/initializers/inflections.rb",
|
85
|
+
"spec/rails_app/config/initializers/secret_token.rb",
|
86
|
+
"spec/rails_app/config/routes.rb",
|
87
|
+
"spec/spec_helper.rb",
|
88
|
+
"spec/spec_models.rb",
|
89
|
+
"test/db/version_1.rb",
|
90
|
+
"test/db/version_2.rb",
|
91
|
+
"test/db/version_3.rb",
|
92
|
+
"test/db/version_4.rb",
|
93
|
+
"test/install_generator_test.rb",
|
94
|
+
"test/test_helper.rb",
|
95
|
+
"test/upgrade_generator_test.rb"
|
93
96
|
]
|
94
97
|
|
95
98
|
if s.respond_to? :specification_version then
|
@@ -97,15 +100,33 @@ Gem::Specification.new do |s|
|
|
97
100
|
s.specification_version = 3
|
98
101
|
|
99
102
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
103
|
+
s.add_runtime_dependency(%q<rails>, ["= 3.0.3"])
|
104
|
+
s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 0"])
|
105
|
+
s.add_runtime_dependency(%q<rspec-rails>, ["~> 2.4.0"])
|
106
|
+
s.add_runtime_dependency(%q<rcov>, [">= 0"])
|
107
|
+
s.add_runtime_dependency(%q<yard>, [">= 0"])
|
108
|
+
s.add_runtime_dependency(%q<jeweler>, [">= 0"])
|
100
109
|
s.add_runtime_dependency(%q<activerecord>, ["= 3.0.3"])
|
101
110
|
s.add_development_dependency(%q<rails>, ["= 3.0.3"])
|
102
111
|
s.add_development_dependency(%q<rspec-rails>, ["~> 2.4.0"])
|
103
112
|
else
|
113
|
+
s.add_dependency(%q<rails>, ["= 3.0.3"])
|
114
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
115
|
+
s.add_dependency(%q<rspec-rails>, ["~> 2.4.0"])
|
116
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
117
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
118
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
104
119
|
s.add_dependency(%q<activerecord>, ["= 3.0.3"])
|
105
120
|
s.add_dependency(%q<rails>, ["= 3.0.3"])
|
106
121
|
s.add_dependency(%q<rspec-rails>, ["~> 2.4.0"])
|
107
122
|
end
|
108
123
|
else
|
124
|
+
s.add_dependency(%q<rails>, ["= 3.0.3"])
|
125
|
+
s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
|
126
|
+
s.add_dependency(%q<rspec-rails>, ["~> 2.4.0"])
|
127
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
128
|
+
s.add_dependency(%q<yard>, [">= 0"])
|
129
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
109
130
|
s.add_dependency(%q<activerecord>, ["= 3.0.3"])
|
110
131
|
s.add_dependency(%q<rails>, ["= 3.0.3"])
|
111
132
|
s.add_dependency(%q<rspec-rails>, ["~> 2.4.0"])
|
data/lib/acts_as_audited.rb
CHANGED
@@ -24,7 +24,7 @@ require 'active_record'
|
|
24
24
|
|
25
25
|
# To get started, please review ActsAsAudited::Auditor::ClassMethods#acts_as_audited
|
26
26
|
module ActsAsAudited
|
27
|
-
VERSION = '2.0.0.
|
27
|
+
VERSION = '2.0.0.rc5'
|
28
28
|
|
29
29
|
mattr_accessor :current_user_method
|
30
30
|
# The method to be called to return the current user for logging in the audits.
|
@@ -12,6 +12,7 @@ require 'set'
|
|
12
12
|
class Audit < ActiveRecord::Base
|
13
13
|
belongs_to :auditable, :polymorphic => true
|
14
14
|
belongs_to :user, :polymorphic => true
|
15
|
+
belongs_to :association, :polymorphic => true
|
15
16
|
|
16
17
|
before_create :set_version_number, :set_audit_user
|
17
18
|
|
@@ -87,7 +88,7 @@ class Audit < ActiveRecord::Base
|
|
87
88
|
alias_method :user_as_model, :user
|
88
89
|
alias_method :user, :user_as_string
|
89
90
|
|
90
|
-
# Return an
|
91
|
+
# Return an instance of what the object looked like at this revision. If
|
91
92
|
# the object has been destroyed, this will be a new record.
|
92
93
|
def revision
|
93
94
|
clazz = auditable_type.constantize
|
@@ -54,6 +54,7 @@ module ActsAsAudited
|
|
54
54
|
|
55
55
|
class_inheritable_reader :non_audited_columns
|
56
56
|
class_inheritable_reader :auditing_enabled
|
57
|
+
class_inheritable_reader :audit_associated_with
|
57
58
|
|
58
59
|
if options[:only]
|
59
60
|
except = self.column_names - options[:only].flatten.map(&:to_s)
|
@@ -63,6 +64,7 @@ module ActsAsAudited
|
|
63
64
|
except |= Array(options[:except]).collect(&:to_s) if options[:except]
|
64
65
|
end
|
65
66
|
write_inheritable_attribute :non_audited_columns, except
|
67
|
+
write_inheritable_attribute :audit_associated_with, options[:associated_with]
|
66
68
|
|
67
69
|
if options[:comment_required]
|
68
70
|
validates_presence_of :audit_comment
|
@@ -89,6 +91,11 @@ module ActsAsAudited
|
|
89
91
|
|
90
92
|
write_inheritable_attribute :auditing_enabled, true
|
91
93
|
end
|
94
|
+
|
95
|
+
def has_associated_audits
|
96
|
+
has_many :associated_audits, :as => :association, :class_name => "Audit"
|
97
|
+
end
|
98
|
+
|
92
99
|
end
|
93
100
|
|
94
101
|
module InstanceMethods
|
@@ -202,6 +209,7 @@ module ActsAsAudited
|
|
202
209
|
end
|
203
210
|
|
204
211
|
def write_audit(attrs)
|
212
|
+
attrs[:association] = self.send(audit_associated_with) unless audit_associated_with.nil?
|
205
213
|
self.audit_comment = nil
|
206
214
|
self.audits.create attrs if auditing_enabled
|
207
215
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :audits, :association_id, :integer
|
4
|
+
add_column :audits, :association_type, :string
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
remove_column :audits, :association_type
|
9
|
+
remove_column :audits, :association_id
|
10
|
+
end
|
11
|
+
end
|
@@ -3,6 +3,8 @@ class <%= migration_class_name %> < ActiveRecord::Migration
|
|
3
3
|
create_table :audits, :force => true do |t|
|
4
4
|
t.column :auditable_id, :integer
|
5
5
|
t.column :auditable_type, :string
|
6
|
+
t.column :association_id, :integer
|
7
|
+
t.column :association_type, :string
|
6
8
|
t.column :user_id, :integer
|
7
9
|
t.column :user_type, :string
|
8
10
|
t.column :username, :string
|
@@ -15,6 +17,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration
|
|
15
17
|
end
|
16
18
|
|
17
19
|
add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index'
|
20
|
+
add_index :audits, [:association_id, :association_type], :name => 'association_index'
|
18
21
|
add_index :audits, [:user_id, :user_type], :name => 'user_index'
|
19
22
|
add_index :audits, :created_at
|
20
23
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
rename_column :audits, :auditable_parent_id, :association_id
|
4
|
+
rename_column :audits, :auditable_parent_type, :association_type
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
rename_column :audits, :association_type, :auditable_parent_type
|
9
|
+
rename_column :audits, :association_id, :auditable_parent_id
|
10
|
+
end
|
11
|
+
end
|
@@ -43,6 +43,14 @@ module ActsAsAudited
|
|
43
43
|
unless columns.include?( 'remote_address' )
|
44
44
|
yield :add_remote_address_to_audits
|
45
45
|
end
|
46
|
+
|
47
|
+
unless columns.include?( 'association_id' )
|
48
|
+
if columns.include?('auditable_parent_id')
|
49
|
+
yield :rename_parent_to_association
|
50
|
+
else
|
51
|
+
yield :add_association_to_audits
|
52
|
+
end
|
53
|
+
end
|
46
54
|
end
|
47
55
|
end
|
48
56
|
end
|
@@ -170,6 +170,35 @@ describe ActsAsAudited::Auditor do
|
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
+
describe "associated with" do
|
174
|
+
let(:owner) { Owner.create(:name => 'Owner') }
|
175
|
+
let(:owned_company) { OwnedCompany.create!(:name => 'The auditors', :owner => owner) }
|
176
|
+
|
177
|
+
it "should record the associated object on create" do
|
178
|
+
owned_company.audits.first.association.should == owner
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should store the associated object on update" do
|
182
|
+
owned_company.update_attribute(:name, 'The Auditors')
|
183
|
+
owned_company.audits.last.association.should == owner
|
184
|
+
end
|
185
|
+
|
186
|
+
it "should store the associated object on destroy" do
|
187
|
+
owned_company.destroy
|
188
|
+
owned_company.audits.last.association.should == owner
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "has associated audits" do
|
193
|
+
let!(:owner) { Owner.create!(:name => 'Owner') }
|
194
|
+
let!(:owned_company) { OwnedCompany.create!(:name => 'The auditors', :owner => owner) }
|
195
|
+
|
196
|
+
it "should list the associated audits" do
|
197
|
+
owner.associated_audits.length.should == 1
|
198
|
+
owner.associated_audits.first.auditable.should == owned_company
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
173
202
|
describe "revisions" do
|
174
203
|
let( :user ) { create_versions }
|
175
204
|
|
data/spec/db/schema.rb
CHANGED
@@ -12,11 +12,23 @@ ActiveRecord::Schema.define(:version => 0) do
|
|
12
12
|
|
13
13
|
create_table :companies, :force => true do |t|
|
14
14
|
t.column :name, :string
|
15
|
+
t.column :owner_id, :integer
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table :authors, :force => true do |t|
|
19
|
+
t.column :name, :string
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :books, :force => true do |t|
|
23
|
+
t.column :authord_id, :integer
|
24
|
+
t.column :title, :string
|
15
25
|
end
|
16
26
|
|
17
27
|
create_table :audits, :force => true do |t|
|
18
28
|
t.column :auditable_id, :integer
|
19
29
|
t.column :auditable_type, :string
|
30
|
+
t.column :association_id, :integer
|
31
|
+
t.column :association_type, :string
|
20
32
|
t.column :user_id, :integer
|
21
33
|
t.column :user_type, :string
|
22
34
|
t.column :username, :string
|
@@ -29,6 +41,7 @@ ActiveRecord::Schema.define(:version => 0) do
|
|
29
41
|
end
|
30
42
|
|
31
43
|
add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index'
|
44
|
+
add_index :audits, [:association_id, :association_type], :name => 'association_index'
|
32
45
|
add_index :audits, [:user_id, :user_type], :name => 'user_index'
|
33
46
|
add_index :audits, :created_at
|
34
47
|
end
|
data/spec/spec_models.rb
CHANGED
@@ -36,6 +36,18 @@ class Company < ActiveRecord::Base
|
|
36
36
|
acts_as_audited
|
37
37
|
end
|
38
38
|
|
39
|
+
class Owner < ActiveRecord::Base
|
40
|
+
set_table_name 'users'
|
41
|
+
has_associated_audits
|
42
|
+
end
|
43
|
+
|
44
|
+
class OwnedCompany < ActiveRecord::Base
|
45
|
+
set_table_name 'companies'
|
46
|
+
belongs_to :owner, :class_name => "Owner"
|
47
|
+
attr_accessible :name, :owner # declare attr_accessible before calling aaa
|
48
|
+
acts_as_audited :associated_with => :owner
|
49
|
+
end
|
50
|
+
|
39
51
|
class OnUpdateDestroy < ActiveRecord::Base
|
40
52
|
set_table_name 'companies'
|
41
53
|
acts_as_audited :on => [:update, :destroy]
|
@@ -0,0 +1,20 @@
|
|
1
|
+
ActiveRecord::Schema.define do
|
2
|
+
create_table :audits, :force => true do |t|
|
3
|
+
t.column :auditable_id, :integer
|
4
|
+
t.column :auditable_type, :string
|
5
|
+
t.column :user_id, :integer
|
6
|
+
t.column :user_type, :string
|
7
|
+
t.column :username, :string
|
8
|
+
t.column :action, :string
|
9
|
+
t.column :audited_changes, :text
|
10
|
+
t.column :version, :integer, :default => 0
|
11
|
+
t.column :comment, :string
|
12
|
+
t.column :created_at, :datetime
|
13
|
+
t.column :remote_address, :string
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index'
|
17
|
+
add_index :audits, [:user_id, :user_type], :name => 'user_index'
|
18
|
+
add_index :audits, :created_at
|
19
|
+
end
|
20
|
+
|
@@ -40,4 +40,15 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
|
|
40
40
|
assert_match /add_column :audits, :remote_address, :string/, content
|
41
41
|
end
|
42
42
|
end
|
43
|
+
|
44
|
+
test "should add 'associated_id' and 'associated_type' to audits table" do
|
45
|
+
load_schema 4
|
46
|
+
|
47
|
+
run_generator %w(upgrade)
|
48
|
+
|
49
|
+
assert_migration "db/migrate/add_association_to_audits.rb" do |content|
|
50
|
+
assert_match /add_column :audits, :association_id, :integer/, content
|
51
|
+
assert_match /add_column :audits, :association_type, :string/, content
|
52
|
+
end
|
53
|
+
end
|
43
54
|
end
|
metadata
CHANGED
@@ -6,11 +6,12 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 2
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.0.
|
9
|
+
- rc5
|
10
|
+
version: 2.0.0.rc5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brandon Keepers
|
14
|
+
- Kenneth Kalmer
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
@@ -169,10 +170,12 @@ files:
|
|
169
170
|
- lib/acts_as_audited/audit_sweeper.rb
|
170
171
|
- lib/acts_as_audited/auditor.rb
|
171
172
|
- lib/generators/acts_as_audited/install_generator.rb
|
173
|
+
- lib/generators/acts_as_audited/templates/add_association_to_audits.rb
|
172
174
|
- lib/generators/acts_as_audited/templates/add_comment_to_audits.rb
|
173
175
|
- lib/generators/acts_as_audited/templates/add_remote_address_to_audits.rb
|
174
176
|
- lib/generators/acts_as_audited/templates/install.rb
|
175
177
|
- lib/generators/acts_as_audited/templates/rename_changes_to_audited_changes.rb
|
178
|
+
- lib/generators/acts_as_audited/templates/rename_parent_to_association.rb
|
176
179
|
- lib/generators/acts_as_audited/upgrade_generator.rb
|
177
180
|
- spec/acts_as_audited_spec.rb
|
178
181
|
- spec/audit_spec.rb
|
@@ -195,6 +198,7 @@ files:
|
|
195
198
|
- test/db/version_1.rb
|
196
199
|
- test/db/version_2.rb
|
197
200
|
- test/db/version_3.rb
|
201
|
+
- test/db/version_4.rb
|
198
202
|
- test/install_generator_test.rb
|
199
203
|
- test/test_helper.rb
|
200
204
|
- test/upgrade_generator_test.rb
|
@@ -256,6 +260,7 @@ test_files:
|
|
256
260
|
- test/db/version_1.rb
|
257
261
|
- test/db/version_2.rb
|
258
262
|
- test/db/version_3.rb
|
263
|
+
- test/db/version_4.rb
|
259
264
|
- test/install_generator_test.rb
|
260
265
|
- test/test_helper.rb
|
261
266
|
- test/upgrade_generator_test.rb
|