acts_as_audited 2.0.0.rc7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,10 @@
1
+ acts_as_audited_plugin.sqlite3.db
2
+ *.log
3
+ doc/
4
+ coverage/
5
+ pkg
6
+ *.swp
7
+ .bundle
8
+ tmp/*
9
+ .yardoc
10
+ .rvmrc
data/CHANGELOG CHANGED
@@ -1,12 +1,11 @@
1
1
  acts_as_audited ChangeLog
2
2
  -------------------------------------------------------------------------------
3
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
-
4
+ * 2011-09-09 - Rails 3.x support
5
+ Support for associated audits
6
+ Support for remote IP address storage
7
+ Plenty of bug fixes and refactoring
8
+ [kennethkalmer, ineu, PatrickMa, jrozner, dwarburton, bsiggelkow, dgm]
10
9
  * 2009-01-27 - Store old and new values for updates, and store all attributes on destroy.
11
10
  Refactored revisioning methods to work as expected
12
11
  * 2008-10-10 - changed to make it work in development mode
data/Gemfile CHANGED
@@ -1,11 +1,7 @@
1
- source :gemcutter
1
+ source 'http://rubygems.org'
2
2
 
3
3
  gem "rails", ">= 3.0.3"
4
-
5
- group :development do
6
- gem "sqlite3-ruby"
7
- gem "rspec-rails", "~> 2.4.0"
8
- gem "rcov"
9
- gem "yard"
10
- gem "jeweler"
11
- end
4
+ gem "sqlite3"
5
+ gem "rspec-rails", "~> 2.4.0"
6
+ gem "rcov"
7
+ gem "yard"
@@ -1,73 +1,76 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- abstract (1.0.0)
5
- actionmailer (3.0.4)
6
- actionpack (= 3.0.4)
7
- mail (~> 2.2.15)
8
- actionpack (3.0.4)
9
- activemodel (= 3.0.4)
10
- activesupport (= 3.0.4)
11
- builder (~> 2.1.2)
12
- erubis (~> 2.6.6)
13
- i18n (~> 0.4)
14
- rack (~> 1.2.1)
15
- rack-mount (~> 0.6.13)
16
- rack-test (~> 0.5.7)
17
- tzinfo (~> 0.3.23)
18
- activemodel (3.0.4)
19
- activesupport (= 3.0.4)
20
- builder (~> 2.1.2)
21
- i18n (~> 0.4)
22
- activerecord (3.0.4)
23
- activemodel (= 3.0.4)
24
- activesupport (= 3.0.4)
25
- arel (~> 2.0.2)
26
- tzinfo (~> 0.3.23)
27
- activeresource (3.0.4)
28
- activemodel (= 3.0.4)
29
- activesupport (= 3.0.4)
30
- activesupport (3.0.4)
31
- arel (2.0.8)
32
- builder (2.1.2)
33
- diff-lcs (1.1.2)
34
- erubis (2.6.6)
35
- abstract (>= 1.0.0)
36
- gemcutter (0.6.1)
37
- git (1.2.5)
38
- i18n (0.5.0)
39
- jeweler (1.4.0)
40
- gemcutter (>= 0.1.0)
41
- git (>= 1.2.5)
42
- rubyforge (>= 2.0.0)
43
- json_pure (1.4.6)
44
- mail (2.2.15)
45
- activesupport (>= 2.3.6)
4
+ actionmailer (3.1.0)
5
+ actionpack (= 3.1.0)
6
+ mail (~> 2.3.0)
7
+ actionpack (3.1.0)
8
+ activemodel (= 3.1.0)
9
+ activesupport (= 3.1.0)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ i18n (~> 0.6)
13
+ rack (~> 1.3.2)
14
+ rack-cache (~> 1.0.3)
15
+ rack-mount (~> 0.8.2)
16
+ rack-test (~> 0.6.1)
17
+ sprockets (~> 2.0.0)
18
+ activemodel (3.1.0)
19
+ activesupport (= 3.1.0)
20
+ bcrypt-ruby (~> 3.0.0)
21
+ builder (~> 3.0.0)
22
+ i18n (~> 0.6)
23
+ activerecord (3.1.0)
24
+ activemodel (= 3.1.0)
25
+ activesupport (= 3.1.0)
26
+ arel (~> 2.2.1)
27
+ tzinfo (~> 0.3.29)
28
+ activeresource (3.1.0)
29
+ activemodel (= 3.1.0)
30
+ activesupport (= 3.1.0)
31
+ activesupport (3.1.0)
32
+ multi_json (~> 1.0)
33
+ arel (2.2.1)
34
+ bcrypt-ruby (3.0.0)
35
+ builder (3.0.0)
36
+ diff-lcs (1.1.3)
37
+ erubis (2.7.0)
38
+ hike (1.2.1)
39
+ i18n (0.6.0)
40
+ mail (2.3.0)
46
41
  i18n (>= 0.4.0)
47
42
  mime-types (~> 1.16)
48
43
  treetop (~> 1.4.8)
49
44
  mime-types (1.16)
50
- polyglot (0.3.1)
51
- rack (1.2.1)
52
- rack-mount (0.6.13)
45
+ multi_json (1.0.3)
46
+ polyglot (0.3.2)
47
+ rack (1.3.2)
48
+ rack-cache (1.0.3)
49
+ rack (>= 0.4)
50
+ rack-mount (0.8.3)
53
51
  rack (>= 1.0.0)
54
- rack-test (0.5.7)
52
+ rack-ssl (1.3.2)
53
+ rack
54
+ rack-test (0.6.1)
55
55
  rack (>= 1.0)
56
- rails (3.0.4)
57
- actionmailer (= 3.0.4)
58
- actionpack (= 3.0.4)
59
- activerecord (= 3.0.4)
60
- activeresource (= 3.0.4)
61
- activesupport (= 3.0.4)
56
+ rails (3.1.0)
57
+ actionmailer (= 3.1.0)
58
+ actionpack (= 3.1.0)
59
+ activerecord (= 3.1.0)
60
+ activeresource (= 3.1.0)
61
+ activesupport (= 3.1.0)
62
62
  bundler (~> 1.0)
63
- railties (= 3.0.4)
64
- railties (3.0.4)
65
- actionpack (= 3.0.4)
66
- activesupport (= 3.0.4)
63
+ railties (= 3.1.0)
64
+ railties (3.1.0)
65
+ actionpack (= 3.1.0)
66
+ activesupport (= 3.1.0)
67
+ rack-ssl (~> 1.3.2)
67
68
  rake (>= 0.8.7)
68
- thor (~> 0.14.4)
69
- rake (0.8.7)
70
- rcov (0.9.9)
69
+ rdoc (~> 3.4)
70
+ thor (~> 0.14.6)
71
+ rake (0.9.2)
72
+ rcov (0.9.10)
73
+ rdoc (3.9.4)
71
74
  rspec (2.4.0)
72
75
  rspec-core (~> 2.4.0)
73
76
  rspec-expectations (~> 2.4.0)
@@ -81,22 +84,25 @@ GEM
81
84
  activesupport (~> 3.0)
82
85
  railties (~> 3.0)
83
86
  rspec (~> 2.4.0)
84
- rubyforge (2.0.4)
85
- json_pure (>= 1.1.7)
86
- sqlite3-ruby (1.3.2)
87
+ sprockets (2.0.0)
88
+ hike (~> 1.2)
89
+ rack (~> 1.0)
90
+ tilt (!= 1.3.0, ~> 1.1)
91
+ sqlite3 (1.3.4)
87
92
  thor (0.14.6)
88
- treetop (1.4.9)
93
+ tilt (1.3.3)
94
+ treetop (1.4.10)
95
+ polyglot
89
96
  polyglot (>= 0.3.1)
90
- tzinfo (0.3.24)
91
- yard (0.6.1)
97
+ tzinfo (0.3.29)
98
+ yard (0.7.2)
92
99
 
93
100
  PLATFORMS
94
101
  ruby
95
102
 
96
103
  DEPENDENCIES
97
- jeweler
98
- rails (>= 3.0.4)
104
+ rails (>= 3.0.3)
99
105
  rcov
100
106
  rspec-rails (~> 2.4.0)
101
- sqlite3-ruby
107
+ sqlite3
102
108
  yard
@@ -0,0 +1,143 @@
1
+ h1. acts_as_audited
2
+
3
+ +acts_as_audited+ is an ActiveRecord extension that logs all changes to your
4
+ models in an audits table, with optional revision comments. +acts_as_audited+
5
+ has been updated to work with Rails 3, to use it with older version of Rails,
6
+ please see the <tt>1.1-stable</tt> branch.
7
+
8
+ h2. Installation
9
+
10
+ In <tt>Gemfile</tt>:
11
+
12
+ @gem "acts_as_audited", "2.0.0"@
13
+
14
+ In your application root, run:
15
+
16
+ @$ bundle install@
17
+
18
+ Generate the migration:
19
+
20
+ * If installing without a previous version of +acts_as_audited+ or you do not mind overwriting your audits table:
21
+
22
+ @$ rails g acts_as_audited:install@
23
+
24
+ * If upgrading from a previous version of +acts_as_audited+ you might need some alterations to the audits table:
25
+
26
+ @$ rails g acts_as_audited:upgrade@
27
+
28
+ * After running one of the generators:
29
+
30
+ @$ rake db:migrate@
31
+
32
+ h2. Rails deprecation warning
33
+
34
+ Currently the gem causes the following deprecation warning to be emitted:
35
+
36
+ @DEPRECATION WARNING: reorder is deprecated. Please use except(:order).order(...) instead. (called from <class:Audit> at /Users/kenneth/Code/FOSS/acts_as_audited/lib/acts_as_audited/audit.rb:26)@
37
+
38
+ I'm well aware of the fact, and working towards a solution. The issue has also been brought up on the Rails lighthouse as "#6011":https://rails.lighthouseapp.com/projects/8994/tickets/6011-exceptorderorder-is-not-working-in-scopes. I'm keeping an eye on the issue and working towards another possible solution.
39
+
40
+ h2. Upgrading
41
+
42
+ Upgrading to Rails 3, or even between point releases of +acts_as_audited+, might require alterations to the audits table. After every upgrade please run the following generator:
43
+
44
+ @$ rails g acts_as_audited:upgrade@
45
+
46
+ The upgrade generator will only generate migrations that are missing, or no migrations at all if you are up to date.
47
+
48
+ h2. Usage
49
+
50
+ Declare +acts_as_audited+ on your models:
51
+
52
+ <pre><code>class User < ActiveRecord::Base
53
+ acts_as_audited :except => [:password, :mistress]
54
+ end
55
+ </code></pre>
56
+
57
+ Within a web request, will automatically record the user that made the change if your controller has a +current_user+ method. Comments can be added to an audit by setting <tt>model.audit_comments</tt>
58
+ before create/update/destroy. If the <tt>:comment_required</tt> option is given to +acts_as_audited+,
59
+ the save/update/destroy action will fail with add an error on <tt>model.audit_comment</tt> and triggering a
60
+ transaction rollback if <tt>model.audit_comment</tt> is nil.
61
+
62
+ To record an audit for an associated model, use the <tt>:associated_with</tt> option.
63
+
64
+ <pre><code>class User < ActiveRecord::Base
65
+ acts_as_audited :associated_with => :company
66
+ end
67
+ </code></pre>
68
+
69
+ If desired, the associated model can access its audits using <tt>has_associated_audits</tt>.
70
+
71
+ <pre><code>class Company < ActiveRecord::Base
72
+ has_many :users
73
+ has_associated_audits
74
+ end
75
+ </code></pre>
76
+
77
+ To record a user in the audits outside of a web request, you can use +as_user+:
78
+
79
+ <pre><code>Audit.as_user(user) do
80
+ # Perform changes on audited models
81
+ end
82
+ </code></pre>
83
+
84
+ h2. Caveats
85
+
86
+ If your model declares +attr_accessible+ after +acts_as_audited+, you need to set <tt>:protect</tt> to false. acts_as_audited uses +attr_protected+ internally to prevent malicious users from unassociating your audits, and Rails does not allow both +attr_protected+ and +attr_accessible+. It will default to false if +attr_accessible+ is called before +acts_as_audited+, but needs to be explicitly set if it is called after.
87
+
88
+ <pre><code>class User < ActiveRecord::Base
89
+ acts_as_audited :protect => false
90
+ attr_accessible :name
91
+ end
92
+ </code></pre>
93
+
94
+ 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.
95
+
96
+ h2. Compatability
97
+
98
+ +acts_as_audited+ works with Rails 3.0.3 – 3.1.0. For older versions of Rails, please see the <tt>1.1-stable</tt> branch.
99
+
100
+ h2. Getting Help
101
+
102
+ Review the documentation at "http://rdoc.info/github/collectiveidea/acts_as_audited":http://rdoc.info/github/collectiveidea/acts_as_audited
103
+
104
+ Join "the mailing list":http://groups.google.com/group/acts_as_audited for getting help or offering suggestions.
105
+
106
+ h2. Branches
107
+
108
+ The <tt>master</tt> branch is considered stable, and you should be able to use it at any time.
109
+
110
+ h2. Contributing
111
+
112
+ In the spirit of "free software":http://www.fsf.org/licensing/essays/free-sw.html, **everyone** is encouraged to help improve this project.
113
+
114
+ Here are some ways *you* can contribute:
115
+
116
+ * using alpha, beta, and prerelease versions
117
+ * reporting bugs
118
+ * suggesting new features
119
+ * writing or editing documentation
120
+ * writing specifications
121
+ * writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
122
+ * refactoring code
123
+ * closing "issues":https://github.com/collectiveidea/acts_as_audited/issues
124
+ * reviewing patches
125
+
126
+ h2. Submitting an Issue
127
+
128
+ We use the "GitHub issue tracker":https://github.com/collectiveidea/acts_as_audited/issues to track bugs
129
+ and features. Before submitting a bug report or feature request, check to make sure it hasn't already
130
+ been submitted. You can indicate support for an existing issuse by voting it up. When submitting a
131
+ bug report, please include a "Gist":https://gist.github.com/ that includes a stack trace and any
132
+ details that may be necessary to reproduce the bug, including your gem version, Ruby version, and
133
+ operating system. Ideally, a bug report should include a pull request with failing specs.
134
+
135
+ h2. Submitting a Pull Request
136
+
137
+ 1. Fork the project.
138
+ 2. Create a topic branch.
139
+ 3. Implement your feature or bug fix.
140
+ 4. Add specs for your feature or bug fix.
141
+ 5. Run @bundle exec rake@. If your changes are not 100% covered and passing, go back to step 4.
142
+ 6. Commit and push your changes.
143
+ 7. Submit a pull request. Please do not include changes to the gemspec, version, or history file. (If you want to create your own version for some reason, please do so in a separate commit.)
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rake'
2
2
  require 'rspec/core/rake_task'
3
3
  require 'rake/testtask'
4
+ require 'bundler'
5
+ Bundler::GemHelper.install_tasks
4
6
 
5
7
  $:.unshift File.expand_path('../lib', __FILE__)
6
8
 
@@ -9,30 +11,11 @@ require 'acts_as_audited'
9
11
  desc 'Default: run specs and tests'
10
12
  task :default => [:spec, :test]
11
13
 
12
- begin
13
- require 'jeweler'
14
- Jeweler::Tasks.new do |gem|
15
- gem.name = "acts_as_audited"
16
- gem.summary = %Q{ActiveRecord extension that logs all changes to your models in an audits table}
17
- gem.email = "brandon@opensoul.org"
18
- gem.homepage = "http://github.com/collectiveidea/acts_as_audited"
19
- gem.authors = ["Brandon Keepers", "Kenneth Kalmer"]
20
- gem.rdoc_options << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
21
- gem.version = ActsAsAudited::VERSION
22
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
23
- end
24
- # Jeweler::GemcutterTasks.new
25
- rescue LoadError
26
- puts "Jeweler (or a dependency) not available. Install it with: bundle install"
27
- end
28
-
29
14
  RSpec::Core::RakeTask.new do |t|
30
15
  t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
31
16
  t.pattern = 'spec/*_spec.rb'
32
17
  end
33
18
 
34
- task :spec => :check_dependencies
35
-
36
19
  RSpec::Core::RakeTask.new(:rcov) do |t|
37
20
  t.rcov = true
38
21
  t.rcov_opts = %q[--exclude "spec"]
@@ -46,8 +29,6 @@ Rake::TestTask.new(:test) do |t|
46
29
  t.verbose = true
47
30
  end
48
31
 
49
- task :test => :check_dependencies
50
-
51
32
  begin
52
33
  require 'yard'
53
34
  YARD::Rake::YardocTask.new
@@ -1,126 +1,18 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{acts_as_audited}
8
- s.version = "2.0.0.rc7"
3
+ Gem::Specification.new do |gem|
4
+ gem.add_runtime_dependency(%q<rails>, [">= 3.0.3"])
9
5
 
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Brandon Keepers", "Kenneth Kalmer"]
12
- s.date = %q{2011-02-18}
13
- s.email = %q{brandon@opensoul.org}
14
- s.extra_rdoc_files = [
15
- "LICENSE",
16
- "README.rdoc"
17
- ]
18
- s.files = [
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"
65
- ]
66
- s.homepage = %q{http://github.com/collectiveidea/acts_as_audited}
67
- s.rdoc_options = ["--main", "README.rdoc", "--line-numbers", "--inline-source"]
68
- s.require_paths = ["lib"]
69
- s.rubygems_version = %q{1.3.7}
70
- s.summary = %q{ActiveRecord extension that logs all changes to your models in an audits table}
71
- s.test_files = [
72
- "spec/acts_as_audited_spec.rb",
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"
96
- ]
97
-
98
- if s.respond_to? :specification_version then
99
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
100
- s.specification_version = 3
101
-
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_development_dependency(%q<sqlite3-ruby>, [">= 0"])
105
- s.add_development_dependency(%q<rspec-rails>, ["~> 2.4.0"])
106
- s.add_development_dependency(%q<rcov>, [">= 0"])
107
- s.add_development_dependency(%q<yard>, [">= 0"])
108
- s.add_development_dependency(%q<jeweler>, [">= 0"])
109
- else
110
- s.add_dependency(%q<rails>, [">= 3.0.3"])
111
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
112
- s.add_dependency(%q<rspec-rails>, ["~> 2.4.0"])
113
- s.add_dependency(%q<rcov>, [">= 0"])
114
- s.add_dependency(%q<yard>, [">= 0"])
115
- s.add_dependency(%q<jeweler>, [">= 0"])
116
- end
117
- else
118
- s.add_dependency(%q<rails>, [">= 3.0.3"])
119
- s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
120
- s.add_dependency(%q<rspec-rails>, ["~> 2.4.0"])
121
- s.add_dependency(%q<rcov>, [">= 0"])
122
- s.add_dependency(%q<yard>, [">= 0"])
123
- s.add_dependency(%q<jeweler>, [">= 0"])
124
- end
6
+ gem.authors = ["Brandon Keepers", "Kenneth Kalmer"]
7
+ gem.email = 'brandon@opensoul.org'
8
+ gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
9
+ gem.files = `git ls-files`.split("\n")
10
+ gem.homepage = %q{http://github.com/collectiveidea/acts_as_audited}
11
+ gem.rdoc_options = ["--main", "README.rdoc", "--line-numbers", "--inline-source"]
12
+ gem.require_paths = ["lib"]
13
+ gem.name = 'acts_as_audited'
14
+ gem.summary = %q{ActiveRecord extension that logs all changes to your models in an audits table}
15
+ gem.test_files = `git ls-files -- spec/* test/*`.split("\n")
16
+ gem.version = "2.0.0"
125
17
  end
126
18
 
@@ -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.rc7'
27
+ VERSION = '2.0.0'
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,7 +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
+ belongs_to :associated, :polymorphic => true
16
16
 
17
17
  before_create :set_version_number, :set_audit_user
18
18
 
@@ -58,6 +58,8 @@ class Audit < ActiveRecord::Base
58
58
  # @private
59
59
  def assign_revision_attributes(record, attributes)
60
60
  attributes.each do |attr, val|
61
+ record = record.dup if record.frozen?
62
+
61
63
  if record.respond_to?("#{attr}=")
62
64
  record.attributes.has_key?(attr.to_s) ?
63
65
  record[attr] = val :
@@ -4,7 +4,7 @@ class AuditSweeper < ActionController::Caching::Sweeper
4
4
 
5
5
  def before_create(audit)
6
6
  audit.user ||= current_user
7
- audit.remote_address = controller.try(:request).try(:remote_ip)
7
+ audit.remote_address = controller.try(:request).try(:ip)
8
8
  end
9
9
 
10
10
  def current_user
@@ -52,9 +52,9 @@ module ActsAsAudited
52
52
 
53
53
  options = {:protect => accessible_attributes.empty?}.merge(options)
54
54
 
55
- class_inheritable_reader :non_audited_columns
56
- class_inheritable_reader :auditing_enabled
57
- class_inheritable_reader :audit_associated_with
55
+ class_attribute :non_audited_columns, :instance_writer => false
56
+ class_attribute :auditing_enabled, :instance_writer => false
57
+ class_attribute :audit_associated_with, :instance_writer => false
58
58
 
59
59
  if options[:only]
60
60
  except = self.column_names - options[:only].flatten.map(&:to_s)
@@ -63,8 +63,8 @@ module ActsAsAudited
63
63
  'created_at', 'updated_at', 'created_on', 'updated_on']
64
64
  except |= Array(options[:except]).collect(&:to_s) if options[:except]
65
65
  end
66
- write_inheritable_attribute :non_audited_columns, except
67
- write_inheritable_attribute :audit_associated_with, options[:associated_with]
66
+ self.non_audited_columns = except
67
+ self.audit_associated_with = options[:associated_with]
68
68
 
69
69
  if options[:comment_required]
70
70
  validates_presence_of :audit_comment, :if => :auditing_enabled
@@ -89,11 +89,11 @@ module ActsAsAudited
89
89
  extend ActsAsAudited::Auditor::SingletonMethods
90
90
  include ActsAsAudited::Auditor::InstanceMethods
91
91
 
92
- write_inheritable_attribute :auditing_enabled, true
92
+ self.auditing_enabled = true
93
93
  end
94
94
 
95
95
  def has_associated_audits
96
- has_many :associated_audits, :as => :association, :class_name => "Audit"
96
+ has_many :associated_audits, :as => :associated, :class_name => "Audit"
97
97
  end
98
98
 
99
99
  end
@@ -125,8 +125,11 @@ module ActsAsAudited
125
125
  def revisions(from_version = 1)
126
126
  audits = self.audits.where(['version >= ?', from_version])
127
127
  return [] if audits.empty?
128
- revision = self.audits.find_by_version(from_version).revision
129
- Audit.reconstruct_attributes(audits) {|attrs| revision.revision_with(attrs) }
128
+ revisions = []
129
+ audits.each do |audit|
130
+ revisions << audit.revision
131
+ end
132
+ revisions
130
133
  end
131
134
 
132
135
  # Get a specific revision specified by the version number, or +:previous+
@@ -210,7 +213,7 @@ module ActsAsAudited
210
213
  end
211
214
 
212
215
  def write_audit(attrs)
213
- attrs[:association] = self.send(audit_associated_with) unless audit_associated_with.nil?
216
+ attrs[:associated] = self.send(audit_associated_with) unless audit_associated_with.nil?
214
217
  self.audit_comment = nil
215
218
  self.audits.create attrs if auditing_enabled
216
219
  end
@@ -251,12 +254,12 @@ module ActsAsAudited
251
254
 
252
255
  # Disable auditing.
253
256
  def disable_auditing
254
- write_inheritable_attribute :auditing_enabled, false
257
+ self.auditing_enabled = false
255
258
  end
256
259
 
257
260
  # Enable auditing.
258
261
  def enable_auditing
259
- write_inheritable_attribute :auditing_enabled, true
262
+ self.auditing_enabled = true
260
263
  end
261
264
 
262
265
  # All audit operations during the block are recorded as being
@@ -3,8 +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
+ t.column :associated_id, :integer
7
+ t.column :associated_type, :string
8
8
  t.column :user_id, :integer
9
9
  t.column :user_type, :string
10
10
  t.column :username, :string
@@ -17,7 +17,7 @@ class <%= migration_class_name %> < ActiveRecord::Migration
17
17
  end
18
18
 
19
19
  add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index'
20
- add_index :audits, [:association_id, :association_type], :name => 'association_index'
20
+ add_index :audits, [:associated_id, :associated_type], :name => 'associated_index'
21
21
  add_index :audits, [:user_id, :user_type], :name => 'user_index'
22
22
  add_index :audits, :created_at
23
23
  end
@@ -0,0 +1,23 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ if index_exists? :audits, [:association_id, :association_type], :name => 'association_index'
4
+ remove_index :audits, :name => 'association_index'
5
+ end
6
+
7
+ rename_column :audits, :association_id, :associated_id
8
+ rename_column :audits, :association_type, :associated_type
9
+
10
+ add_index :audits, [:associated_id, :associated_type], :name => 'associated_index'
11
+ end
12
+
13
+ def self.down
14
+ if index_exists? :audits, [:associated_id, :associated_type], :name => 'associated_index'
15
+ remove_index :audits, :name => 'associated_index'
16
+ end
17
+
18
+ rename_column :audits, :associated_type, :association_type
19
+ rename_column :audits, :associated_id, :association_id
20
+
21
+ add_index :audits, [:association_id, :association_type], :name => 'association_index'
22
+ end
23
+ end
@@ -48,9 +48,15 @@ module ActsAsAudited
48
48
  if columns.include?('auditable_parent_id')
49
49
  yield :rename_parent_to_association
50
50
  else
51
- yield :add_association_to_audits
51
+ unless columns.include?( 'associated_id' )
52
+ yield :add_association_to_audits
53
+ end
52
54
  end
53
55
  end
56
+
57
+ if columns.include?( 'association_id' )
58
+ yield :rename_association_to_associated
59
+ end
54
60
  end
55
61
  end
56
62
  end
@@ -175,17 +175,17 @@ describe ActsAsAudited::Auditor do
175
175
  let(:owned_company) { OwnedCompany.create!(:name => 'The auditors', :owner => owner) }
176
176
 
177
177
  it "should record the associated object on create" do
178
- owned_company.audits.first.association.should == owner
178
+ owned_company.audits.first.associated.should == owner
179
179
  end
180
180
 
181
181
  it "should store the associated object on update" do
182
182
  owned_company.update_attribute(:name, 'The Auditors')
183
- owned_company.audits.last.association.should == owner
183
+ owned_company.audits.last.associated.should == owner
184
184
  end
185
185
 
186
186
  it "should store the associated object on destroy" do
187
187
  owned_company.destroy
188
- owned_company.audits.last.association.should == owner
188
+ owned_company.audits.last.associated.should == owner
189
189
  end
190
190
  end
191
191
 
@@ -27,8 +27,8 @@ ActiveRecord::Schema.define(:version => 0) do
27
27
  create_table :audits, :force => true do |t|
28
28
  t.column :auditable_id, :integer
29
29
  t.column :auditable_type, :string
30
- t.column :association_id, :integer
31
- t.column :association_type, :string
30
+ t.column :associated_id, :integer
31
+ t.column :associated_type, :string
32
32
  t.column :user_id, :integer
33
33
  t.column :user_type, :string
34
34
  t.column :username, :string
@@ -41,7 +41,7 @@ ActiveRecord::Schema.define(:version => 0) do
41
41
  end
42
42
 
43
43
  add_index :audits, [:auditable_id, :auditable_type], :name => 'auditable_index'
44
- add_index :audits, [:association_id, :association_type], :name => 'association_index'
44
+ add_index :audits, [:associated_id, :associated_type], :name => 'associated_index'
45
45
  add_index :audits, [:user_id, :user_type], :name => 'user_index'
46
46
  add_index :audits, :created_at
47
47
  end
@@ -0,0 +1,18 @@
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
+ t.column :association_id, :integer
15
+ t.column :association_type, :string
16
+ end
17
+ end
18
+
@@ -41,7 +41,7 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
41
41
  end
42
42
  end
43
43
 
44
- test "should add 'associated_id' and 'associated_type' to audits table" do
44
+ test "should add 'association_id' and 'association_type' to audits table" do
45
45
  load_schema 4
46
46
 
47
47
  run_generator %w(upgrade)
@@ -51,4 +51,15 @@ class UpgradeGeneratorTest < Rails::Generators::TestCase
51
51
  assert_match /add_column :audits, :association_type, :string/, content
52
52
  end
53
53
  end
54
+
55
+ test "should rename 'association_id' to 'associated_id' and 'association_type' to 'associated_type'" do
56
+ load_schema 5
57
+
58
+ run_generator %w(upgrade)
59
+
60
+ assert_migration "db/migrate/rename_association_to_associated.rb" do |content|
61
+ assert_match /rename_column :audits, :association_id, :associated_id/, content
62
+ assert_match /rename_column :audits, :association_type, :associated_type/, content
63
+ end
64
+ end
54
65
  end
metadata CHANGED
@@ -1,129 +1,41 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: acts_as_audited
3
- version: !ruby/object:Gem::Version
4
- hash: 977940584
5
- prerelease: true
6
- segments:
7
- - 2
8
- - 0
9
- - 0
10
- - rc7
11
- version: 2.0.0.rc7
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ prerelease:
12
6
  platform: ruby
13
- authors:
7
+ authors:
14
8
  - Brandon Keepers
15
9
  - Kenneth Kalmer
16
10
  autorequire:
17
11
  bindir: bin
18
12
  cert_chain: []
19
-
20
- date: 2011-02-18 00:00:00 +02:00
21
- default_executable:
22
- dependencies:
23
- - !ruby/object:Gem::Dependency
24
- prerelease: false
25
- type: :runtime
13
+ date: 2011-09-12 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
26
16
  name: rails
27
- version_requirements: &id001 !ruby/object:Gem::Requirement
17
+ requirement: &70322406432300 !ruby/object:Gem::Requirement
28
18
  none: false
29
- requirements:
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- hash: 1
33
- segments:
34
- - 3
35
- - 0
36
- - 3
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
37
22
  version: 3.0.3
38
- requirement: *id001
39
- - !ruby/object:Gem::Dependency
40
- prerelease: false
41
- type: :development
42
- name: sqlite3-ruby
43
- version_requirements: &id002 !ruby/object:Gem::Requirement
44
- none: false
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- hash: 3
49
- segments:
50
- - 0
51
- version: "0"
52
- requirement: *id002
53
- - !ruby/object:Gem::Dependency
54
- prerelease: false
55
- type: :development
56
- name: rspec-rails
57
- version_requirements: &id003 !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ~>
61
- - !ruby/object:Gem::Version
62
- hash: 31
63
- segments:
64
- - 2
65
- - 4
66
- - 0
67
- version: 2.4.0
68
- requirement: *id003
69
- - !ruby/object:Gem::Dependency
70
- prerelease: false
71
- type: :development
72
- name: rcov
73
- version_requirements: &id004 !ruby/object:Gem::Requirement
74
- none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
- version: "0"
82
- requirement: *id004
83
- - !ruby/object:Gem::Dependency
84
- prerelease: false
85
- type: :development
86
- name: yard
87
- version_requirements: &id005 !ruby/object:Gem::Requirement
88
- none: false
89
- requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- hash: 3
93
- segments:
94
- - 0
95
- version: "0"
96
- requirement: *id005
97
- - !ruby/object:Gem::Dependency
23
+ type: :runtime
98
24
  prerelease: false
99
- type: :development
100
- name: jeweler
101
- version_requirements: &id006 !ruby/object:Gem::Requirement
102
- none: false
103
- requirements:
104
- - - ">="
105
- - !ruby/object:Gem::Version
106
- hash: 3
107
- segments:
108
- - 0
109
- version: "0"
110
- requirement: *id006
25
+ version_requirements: *70322406432300
111
26
  description:
112
27
  email: brandon@opensoul.org
113
28
  executables: []
114
-
115
29
  extensions: []
116
-
117
- extra_rdoc_files:
118
- - LICENSE
119
- - README.rdoc
120
- files:
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
121
33
  - .yardopts
122
34
  - CHANGELOG
123
35
  - Gemfile
124
36
  - Gemfile.lock
125
37
  - LICENSE
126
- - README.rdoc
38
+ - README.textile
127
39
  - Rakefile
128
40
  - acts_as_audited.gemspec
129
41
  - autotest/discover.rb
@@ -136,6 +48,7 @@ files:
136
48
  - lib/generators/acts_as_audited/templates/add_comment_to_audits.rb
137
49
  - lib/generators/acts_as_audited/templates/add_remote_address_to_audits.rb
138
50
  - lib/generators/acts_as_audited/templates/install.rb
51
+ - lib/generators/acts_as_audited/templates/rename_association_to_associated.rb
139
52
  - lib/generators/acts_as_audited/templates/rename_changes_to_audited_changes.rb
140
53
  - lib/generators/acts_as_audited/templates/rename_parent_to_association.rb
141
54
  - lib/generators/acts_as_audited/upgrade_generator.rb
@@ -161,49 +74,40 @@ files:
161
74
  - test/db/version_2.rb
162
75
  - test/db/version_3.rb
163
76
  - test/db/version_4.rb
77
+ - test/db/version_5.rb
164
78
  - test/install_generator_test.rb
165
79
  - test/test_helper.rb
166
80
  - test/upgrade_generator_test.rb
167
- has_rdoc: true
168
81
  homepage: http://github.com/collectiveidea/acts_as_audited
169
82
  licenses: []
170
-
171
83
  post_install_message:
172
- rdoc_options:
84
+ rdoc_options:
173
85
  - --main
174
86
  - README.rdoc
175
87
  - --line-numbers
176
88
  - --inline-source
177
- require_paths:
89
+ require_paths:
178
90
  - lib
179
- required_ruby_version: !ruby/object:Gem::Requirement
91
+ required_ruby_version: !ruby/object:Gem::Requirement
180
92
  none: false
181
- requirements:
182
- - - ">="
183
- - !ruby/object:Gem::Version
184
- hash: 3
185
- segments:
186
- - 0
187
- version: "0"
188
- required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
98
  none: false
190
- requirements:
191
- - - ">"
192
- - !ruby/object:Gem::Version
193
- hash: 25
194
- segments:
195
- - 1
196
- - 3
197
- - 1
198
- version: 1.3.1
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: 1.3.6
199
103
  requirements: []
200
-
201
104
  rubyforge_project:
202
- rubygems_version: 1.3.7
105
+ rubygems_version: 1.8.6
203
106
  signing_key:
204
107
  specification_version: 3
205
- summary: ActiveRecord extension that logs all changes to your models in an audits table
206
- test_files:
108
+ summary: ActiveRecord extension that logs all changes to your models in an audits
109
+ table
110
+ test_files:
207
111
  - spec/acts_as_audited_spec.rb
208
112
  - spec/audit_spec.rb
209
113
  - spec/audit_sweeper_spec.rb
@@ -211,6 +115,7 @@ test_files:
211
115
  - spec/db/schema.rb
212
116
  - spec/rails_app/config/application.rb
213
117
  - spec/rails_app/config/boot.rb
118
+ - spec/rails_app/config/database.yml
214
119
  - spec/rails_app/config/environment.rb
215
120
  - spec/rails_app/config/environments/development.rb
216
121
  - spec/rails_app/config/environments/production.rb
@@ -225,6 +130,7 @@ test_files:
225
130
  - test/db/version_2.rb
226
131
  - test/db/version_3.rb
227
132
  - test/db/version_4.rb
133
+ - test/db/version_5.rb
228
134
  - test/install_generator_test.rb
229
135
  - test/test_helper.rb
230
136
  - test/upgrade_generator_test.rb
@@ -1,120 +0,0 @@
1
- = acts_as_audited
2
-
3
- +acts_as_audited+ is an ActiveRecord extension that logs all changes to your
4
- models in an audits table, with optional revision comments. +acts_as_audited+
5
- has been updated to work with Rails 3, to use it with older version of Rails,
6
- please see the <tt>1.1-stable</tt> branch.
7
-
8
- == Installation
9
-
10
- In <tt>Gemfile</tt>:
11
-
12
- gem "acts_as_audited", "2.0.0.rc5"
13
-
14
- In your application root, run:
15
-
16
- $ bundle install
17
-
18
- Generate the migration:
19
-
20
- * If installing without a previous version of +acts_as_audited+ or you do not mind overwriting your audits table:
21
-
22
- $ rails g acts_as_audited:install
23
-
24
- * If upgrading from a previous version of +acts_as_audited+ you might need some alterations to the audits table:
25
-
26
- $ rails g acts_as_audited:upgrade
27
-
28
- * After running one of the generators:
29
-
30
- $ rake db:migrate
31
-
32
- == Rails deprecation warning
33
-
34
- Currently the gem causes the following deprecation warning to be emitted:
35
-
36
- DEPRECATION WARNING: reorder is deprecated. Please use except(:order).order(...) instead. (called from <class:Audit> at /Users/kenneth/Code/FOSS/acts_as_audited/lib/acts_as_audited/audit.rb:26)
37
-
38
- I'm well aware of the fact, and working towards a solution. The issue has also been brought up on the Rails lighthouse as #6011[https://rails.lighthouseapp.com/projects/8994/tickets/6011-exceptorderorder-is-not-working-in-scopes]. I'm keeping an eye on the issue and working towards another possible solution.
39
-
40
- == Upgrading
41
-
42
- Upgrading to Rails 3, or even between point releases of +acts_as_audited+, might require alterations to the audits table. After every upgrade please run the following generator:
43
-
44
- $ rails g acts_as_audited:upgrade
45
-
46
- The upgrade generator will only generate migrations that are missing, or no migrations at all if you are up to date.
47
-
48
- == Usage
49
-
50
- Declare +acts_as_audited+ on your models:
51
-
52
- class User < ActiveRecord::Base
53
- acts_as_audited :except => [:password, :mistress]
54
- end
55
-
56
- Within a web request, will automatically record the user that made the change if your controller has a +current_user+ method. Comments can be added to an audit by setting <tt>model.audit_comments</tt>
57
- before create/update/destroy. If the <tt>:comment_required</tt> option is given to +acts_as_audited+,
58
- the save/update/destroy action will fail with add an error on <tt>model.audit_comment</tt> and triggering a
59
- transaction rollback if <tt>model.audit_comment</tt> is nil.
60
-
61
- To record an audit for an associated model, use the <tt>:associated_with</tt> option.
62
-
63
- class User < ActiveRecord::Base
64
- acts_as_audited :associated_with => :company
65
- end
66
-
67
- If desired, the associated model can access its audits using <tt>has_associated_audits</tt>.
68
-
69
- class Company < ActiveRecord::Base
70
- has_many :users
71
- has_associated_audits
72
- end
73
-
74
- To record a user in the audits outside of a web request, you can use +as_user+:
75
-
76
- Audit.as_user(user) do
77
- # Perform changes on audited models
78
- end
79
-
80
- == Caveats
81
-
82
- If your model declares +attr_accessible+ after +acts_as_audited+, you need to set <tt>:protect</tt> to false. acts_as_audited uses +attr_protected+ internally to prevent malicious users from unassociating your audits, and Rails does not allow both +attr_protected+ and +attr_accessible+. It will default to false if +attr_accessible+ is called before +acts_as_audited+, but needs to be explicitly set if it is called after.
83
-
84
- class User < ActiveRecord::Base
85
- acts_as_audited :protect => false
86
- attr_accessible :name
87
- end
88
-
89
- 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.
90
-
91
- == Compatability
92
-
93
- +acts_as_audited+ works with Rails 3.0.3. For older versions of Rails, please see the <tt>1.1-stable</tt> branch.
94
-
95
- == Getting Help
96
-
97
- Review the documentation at http://rdoc.info/github/collectiveidea/acts_as_audited
98
-
99
- Join the mailing list for getting help or offering suggestions - http://groups.google.com/group/acts_as_audited
100
-
101
- == Branches
102
-
103
- 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.
104
-
105
- == Contributing
106
-
107
- Contributions are always welcome. Checkout the latest code on GitHub - http://github.com/collectiveidea/acts_as_audited
108
-
109
- 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).
110
-
111
- Please include tests with your patches. There are a few gems required to run the tests:
112
-
113
- $ bundle install
114
-
115
- Make sure the tests pass against the version of Rails specified in the Gemfile
116
-
117
- $ rake spec test
118
-
119
- Please report bugs or feature suggestions on GitHub - http://github.com/collectiveidea/acts_as_audited/issues
120
-