acts_as_audited 1.1.1 → 2.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.yardopts +3 -0
  2. data/Gemfile +8 -0
  3. data/Gemfile.lock +102 -0
  4. data/LICENSE +2 -2
  5. data/README.rdoc +90 -0
  6. data/Rakefile +32 -28
  7. data/acts_as_audited.gemspec +75 -34
  8. data/autotest/discover.rb +1 -0
  9. data/lib/acts_as_audited.rb +18 -212
  10. data/lib/acts_as_audited/audit.rb +58 -40
  11. data/lib/acts_as_audited/audit_sweeper.rb +5 -27
  12. data/lib/acts_as_audited/auditor.rb +263 -0
  13. data/lib/generators/acts_as_audited/install_generator.rb +28 -0
  14. data/lib/generators/acts_as_audited/templates/add_comment_to_audits.rb +9 -0
  15. data/lib/generators/acts_as_audited/templates/add_remote_address_to_audits.rb +10 -0
  16. data/{generators/audited_migration/templates/migration.rb → lib/generators/acts_as_audited/templates/install.rb} +6 -4
  17. data/lib/generators/acts_as_audited/templates/rename_changes_to_audited_changes.rb +9 -0
  18. data/lib/generators/acts_as_audited/upgrade_generator.rb +49 -0
  19. data/spec/acts_as_audited_spec.rb +426 -0
  20. data/spec/audit_spec.rb +190 -0
  21. data/spec/audit_sweeper_spec.rb +74 -0
  22. data/spec/audited_spec_helpers.rb +16 -0
  23. data/{test → spec}/db/schema.rb +8 -5
  24. data/spec/rails_app/config/application.rb +23 -0
  25. data/spec/rails_app/config/boot.rb +13 -0
  26. data/{test/db → spec/rails_app/config}/database.yml +10 -7
  27. data/spec/rails_app/config/environment.rb +5 -0
  28. data/spec/rails_app/config/environments/development.rb +19 -0
  29. data/spec/rails_app/config/environments/production.rb +33 -0
  30. data/spec/rails_app/config/environments/test.rb +33 -0
  31. data/spec/rails_app/config/initializers/backtrace_silencers.rb +7 -0
  32. data/spec/rails_app/config/initializers/inflections.rb +2 -0
  33. data/spec/rails_app/config/initializers/secret_token.rb +2 -0
  34. data/spec/rails_app/config/routes.rb +6 -0
  35. data/spec/spec_helper.rb +21 -0
  36. data/spec/spec_models.rb +76 -0
  37. data/test/db/version_1.rb +17 -0
  38. data/test/db/version_2.rb +18 -0
  39. data/test/db/version_3.rb +19 -0
  40. data/test/install_generator_test.rb +17 -0
  41. data/test/test_helper.rb +11 -67
  42. data/test/upgrade_generator_test.rb +43 -0
  43. metadata +179 -41
  44. data/.gitignore +0 -4
  45. data/README +0 -70
  46. data/VERSION +0 -1
  47. data/generators/audited_migration/USAGE +0 -7
  48. data/generators/audited_migration/audited_migration_generator.rb +0 -7
  49. data/init.rb +0 -1
  50. data/rails/init.rb +0 -8
  51. data/test/acts_as_audited_test.rb +0 -374
  52. data/test/audit_sweeper_test.rb +0 -31
  53. data/test/audit_test.rb +0 -179
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --no-private
2
+ --title acts_as_audited
3
+ --exclude lib/generators
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :gemcutter
2
+
3
+ gem "rails", "3.0.3"
4
+ gem "sqlite3-ruby"
5
+ gem "rspec-rails", "~> 2.4.0"
6
+ gem "rcov"
7
+ gem "yard"
8
+ gem "jeweler"
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.3)
6
+ actionpack (= 3.0.3)
7
+ mail (~> 2.2.9)
8
+ actionpack (3.0.3)
9
+ activemodel (= 3.0.3)
10
+ activesupport (= 3.0.3)
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.6)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.3)
19
+ activesupport (= 3.0.3)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4)
22
+ activerecord (3.0.3)
23
+ activemodel (= 3.0.3)
24
+ activesupport (= 3.0.3)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.3)
28
+ activemodel (= 3.0.3)
29
+ activesupport (= 3.0.3)
30
+ activesupport (3.0.3)
31
+ arel (2.0.7)
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)
46
+ i18n (>= 0.4.0)
47
+ mime-types (~> 1.16)
48
+ treetop (~> 1.4.8)
49
+ mime-types (1.16)
50
+ polyglot (0.3.1)
51
+ rack (1.2.1)
52
+ rack-mount (0.6.13)
53
+ rack (>= 1.0.0)
54
+ rack-test (0.5.7)
55
+ rack (>= 1.0)
56
+ rails (3.0.3)
57
+ actionmailer (= 3.0.3)
58
+ actionpack (= 3.0.3)
59
+ activerecord (= 3.0.3)
60
+ activeresource (= 3.0.3)
61
+ activesupport (= 3.0.3)
62
+ bundler (~> 1.0)
63
+ railties (= 3.0.3)
64
+ railties (3.0.3)
65
+ actionpack (= 3.0.3)
66
+ activesupport (= 3.0.3)
67
+ rake (>= 0.8.7)
68
+ thor (~> 0.14.4)
69
+ rake (0.8.7)
70
+ rcov (0.9.9)
71
+ rspec (2.4.0)
72
+ rspec-core (~> 2.4.0)
73
+ rspec-expectations (~> 2.4.0)
74
+ rspec-mocks (~> 2.4.0)
75
+ rspec-core (2.4.0)
76
+ rspec-expectations (2.4.0)
77
+ diff-lcs (~> 1.1.2)
78
+ rspec-mocks (2.4.0)
79
+ rspec-rails (2.4.1)
80
+ actionpack (~> 3.0)
81
+ activesupport (~> 3.0)
82
+ railties (~> 3.0)
83
+ rspec (~> 2.4.0)
84
+ rubyforge (2.0.4)
85
+ json_pure (>= 1.1.7)
86
+ sqlite3-ruby (1.3.2)
87
+ thor (0.14.6)
88
+ treetop (1.4.9)
89
+ polyglot (>= 0.3.1)
90
+ tzinfo (0.3.24)
91
+ yard (0.6.1)
92
+
93
+ PLATFORMS
94
+ ruby
95
+
96
+ DEPENDENCIES
97
+ jeweler
98
+ rails (= 3.0.3)
99
+ rcov
100
+ rspec-rails (~> 2.4.0)
101
+ sqlite3-ruby
102
+ yard
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright © 2008 Brandon Keepers - Collective Idea
1
+ Copyright © 2010 Brandon Keepers - Collective Idea
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
16
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
17
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
18
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- THE SOFTWARE.
19
+ THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,90 @@
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>rails2</tt> branch.
7
+
8
+ == Installation
9
+
10
+ In <tt>Gemfile</tt>:
11
+
12
+ gem "acts_as_audited", "2.0.0.rc1"
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
+ == Upgrading
33
+
34
+ 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:
35
+
36
+ $ rails g acts_as_audited:upgrade
37
+
38
+ The upgrade generator will only generate migrations that are missing, or no migrations at all if you are up to date.
39
+
40
+ == Usage
41
+
42
+ Declare +acts_as_audited+ on your models:
43
+
44
+ class User < ActiveRecord::Base
45
+ acts_as_audited :except => [:password, :mistress]
46
+ end
47
+
48
+ 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>
49
+ before create/update/destroy. If the <tt>:comment_required</tt> option is given to +acts_as_audited+,
50
+ the save/update/destroy action will fail with add an error on <tt>model.audit_comment</tt> and triggering a
51
+ transaction rollback if <tt>model.audit_comment</tt> is nil.
52
+
53
+ To record a user in the audits outside of a web request, you can use +as_user+:
54
+
55
+ Audit.as_user(user) do
56
+ # Perform changes on audited models
57
+ end
58
+
59
+ == Caveats
60
+
61
+ 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.
62
+
63
+ class User < ActiveRecord::Base
64
+ acts_as_audited :protect => false
65
+ attr_accessible :name
66
+ end
67
+
68
+ == Compatability
69
+
70
+ +acts_as_audited+ works with Rails 3.0.0 or later. For older versions of Rails, please see the <tt>rails2</tt> branch.
71
+
72
+ == Getting Help
73
+
74
+ Review the documentation at http://rdoc.info/github/collectiveidea/acts_as_audited
75
+
76
+ Join the mailing list for getting help or offering suggestions - http://groups.google.com/group/acts_as_audited
77
+
78
+ == Contributing
79
+
80
+ Contributions are always welcome. Checkout the latest code on GitHub - http://github.com/collectiveidea/acts_as_audited
81
+
82
+ Please include tests with your patches. There are a few gems required to run the tests:
83
+
84
+ $ bundle install
85
+
86
+ Make sure the tests pass against the version of Rails specified in the Gemfile
87
+
88
+ $ rake spec test
89
+
90
+ Please report bugs or feature suggestions on GitHub - http://github.com/collectiveidea/acts_as_audited/issues
data/Rakefile CHANGED
@@ -1,10 +1,13 @@
1
1
  require 'rake'
2
- require 'load_multi_rails_rake_tasks'
2
+ require 'rspec/core/rake_task'
3
3
  require 'rake/testtask'
4
- require 'rake/rdoctask'
5
4
 
6
- desc 'Default: run tests.'
7
- task :default => :test
5
+ $:.unshift File.expand_path('../lib', __FILE__)
6
+
7
+ require 'acts_as_audited'
8
+
9
+ desc 'Default: run specs and tests'
10
+ task :default => [:spec, :test]
8
11
 
9
12
  begin
10
13
  require 'jeweler'
@@ -14,44 +17,45 @@ begin
14
17
  gem.email = "brandon@opensoul.org"
15
18
  gem.homepage = "http://github.com/collectiveidea/acts_as_audited"
16
19
  gem.authors = ["Brandon Keepers"]
17
- gem.add_dependency 'activerecord', '>=2.1'
18
- gem.add_development_dependency "thoughtbot-shoulda"
19
- gem.add_development_dependency "jnunemaker-matchy"
20
+ gem.rdoc_options << '--main' << 'README.rdoc' << '--line-numbers' << '--inline-source'
21
+ gem.version = ActsAsAudited::VERSION
22
+
23
+ gem.add_dependency 'activerecord', '3.0.3'
24
+ gem.add_development_dependency "rails", '3.0.3'
25
+ gem.add_development_dependency "rspec-rails", '~> 2.4.0'
20
26
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
21
27
  end
22
28
  # Jeweler::GemcutterTasks.new
23
29
  rescue LoadError
24
- puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
30
+ puts "Jeweler (or a dependency) not available. Install it with: bundle install"
25
31
  end
26
32
 
27
- desc 'Test the acts_as_audited plugin'
33
+ RSpec::Core::RakeTask.new do |t|
34
+ t.rspec_opts = ["-c", "-f progress", "-r ./spec/spec_helper.rb"]
35
+ t.pattern = 'spec/*_spec.rb'
36
+ end
37
+
38
+ task :spec => :check_dependencies
39
+
40
+ RSpec::Core::RakeTask.new(:rcov) do |t|
41
+ t.rcov = true
42
+ t.rcov_opts = %q[--exclude "spec"]
43
+ end
44
+
45
+ desc 'Test the acts_as_audited generators'
28
46
  Rake::TestTask.new(:test) do |t|
29
47
  t.libs << 'lib'
30
- t.pattern = 'test/**/*_test.rb'
48
+ t.libs << 'test'
49
+ t.pattern = 'test/*_test.rb'
31
50
  t.verbose = true
32
51
  end
33
52
 
34
53
  task :test => :check_dependencies
35
54
 
36
55
  begin
37
- require 'rcov/rcovtask'
38
- Rcov::RcovTask.new do |test|
39
- test.libs << 'test'
40
- test.pattern = 'test/**/*_test.rb'
41
- test.verbose = true
42
- test.rcov_opts = %w(--exclude test,/usr/lib/ruby,/Library/Ruby,$HOME/.gem --sort coverage)
43
- end
56
+ require 'yard'
57
+ YARD::Rake::YardocTask.new
44
58
  rescue LoadError
45
- task :rcov do
46
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
47
- end
59
+ puts "YARD (or a dependency) not available. Install it with: bundle install"
48
60
  end
49
61
 
50
- desc 'Generate documentation for the acts_as_audited plugin.'
51
- Rake::RDocTask.new(:rdoc) do |rdoc|
52
- rdoc.rdoc_dir = 'doc'
53
- rdoc.title = 'acts_as_audited'
54
- rdoc.options << '--line-numbers' << '--inline-source'
55
- rdoc.rdoc_files.include('README')
56
- rdoc.rdoc_files.include('lib/**/*.rb')
57
- end
@@ -5,69 +5,110 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_audited}
8
- s.version = "1.1.1"
8
+ s.version = "2.0.0.rc3"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Brandon Keepers"]
12
- s.date = %q{2010-04-03}
12
+ s.date = %q{2011-02-02}
13
13
  s.email = %q{brandon@opensoul.org}
14
14
  s.extra_rdoc_files = [
15
15
  "LICENSE",
16
- "README"
16
+ "README.rdoc"
17
17
  ]
18
18
  s.files = [
19
19
  ".gitignore",
20
+ ".yardopts",
20
21
  "CHANGELOG",
22
+ "Gemfile",
23
+ "Gemfile.lock",
21
24
  "LICENSE",
22
- "README",
25
+ "README.rdoc",
23
26
  "Rakefile",
24
- "VERSION",
25
27
  "acts_as_audited.gemspec",
26
- "generators/audited_migration/USAGE",
27
- "generators/audited_migration/audited_migration_generator.rb",
28
- "generators/audited_migration/templates/migration.rb",
29
- "init.rb",
28
+ "autotest/discover.rb",
30
29
  "lib/acts_as_audited.rb",
31
30
  "lib/acts_as_audited/audit.rb",
32
31
  "lib/acts_as_audited/audit_sweeper.rb",
33
- "rails/init.rb",
34
- "test/acts_as_audited_test.rb",
35
- "test/audit_sweeper_test.rb",
36
- "test/audit_test.rb",
37
- "test/db/database.yml",
38
- "test/db/schema.rb",
39
- "test/test_helper.rb"
32
+ "lib/acts_as_audited/auditor.rb",
33
+ "lib/generators/acts_as_audited/install_generator.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/upgrade_generator.rb",
39
+ "spec/acts_as_audited_spec.rb",
40
+ "spec/audit_spec.rb",
41
+ "spec/audit_sweeper_spec.rb",
42
+ "spec/audited_spec_helpers.rb",
43
+ "spec/db/schema.rb",
44
+ "spec/rails_app/config/application.rb",
45
+ "spec/rails_app/config/boot.rb",
46
+ "spec/rails_app/config/database.yml",
47
+ "spec/rails_app/config/environment.rb",
48
+ "spec/rails_app/config/environments/development.rb",
49
+ "spec/rails_app/config/environments/production.rb",
50
+ "spec/rails_app/config/environments/test.rb",
51
+ "spec/rails_app/config/initializers/backtrace_silencers.rb",
52
+ "spec/rails_app/config/initializers/inflections.rb",
53
+ "spec/rails_app/config/initializers/secret_token.rb",
54
+ "spec/rails_app/config/routes.rb",
55
+ "spec/spec_helper.rb",
56
+ "spec/spec_models.rb",
57
+ "test/db/version_1.rb",
58
+ "test/db/version_2.rb",
59
+ "test/db/version_3.rb",
60
+ "test/install_generator_test.rb",
61
+ "test/test_helper.rb",
62
+ "test/upgrade_generator_test.rb"
40
63
  ]
41
64
  s.homepage = %q{http://github.com/collectiveidea/acts_as_audited}
42
- s.rdoc_options = ["--charset=UTF-8"]
65
+ s.rdoc_options = ["--charset=UTF-8", "--main", "README.rdoc", "--line-numbers", "--inline-source"]
43
66
  s.require_paths = ["lib"]
44
- s.rubygems_version = %q{1.3.6}
67
+ s.rubygems_version = %q{1.3.7}
45
68
  s.summary = %q{ActiveRecord extension that logs all changes to your models in an audits table}
46
69
  s.test_files = [
47
- "test/acts_as_audited_test.rb",
48
- "test/audit_sweeper_test.rb",
49
- "test/audit_test.rb",
50
- "test/db/schema.rb",
51
- "test/test_helper.rb"
70
+ "spec/acts_as_audited_spec.rb",
71
+ "spec/audit_spec.rb",
72
+ "spec/audit_sweeper_spec.rb",
73
+ "spec/audited_spec_helpers.rb",
74
+ "spec/db/schema.rb",
75
+ "spec/rails_app/config/application.rb",
76
+ "spec/rails_app/config/boot.rb",
77
+ "spec/rails_app/config/environment.rb",
78
+ "spec/rails_app/config/environments/development.rb",
79
+ "spec/rails_app/config/environments/production.rb",
80
+ "spec/rails_app/config/environments/test.rb",
81
+ "spec/rails_app/config/initializers/backtrace_silencers.rb",
82
+ "spec/rails_app/config/initializers/inflections.rb",
83
+ "spec/rails_app/config/initializers/secret_token.rb",
84
+ "spec/rails_app/config/routes.rb",
85
+ "spec/spec_helper.rb",
86
+ "spec/spec_models.rb",
87
+ "test/db/version_1.rb",
88
+ "test/db/version_2.rb",
89
+ "test/db/version_3.rb",
90
+ "test/install_generator_test.rb",
91
+ "test/test_helper.rb",
92
+ "test/upgrade_generator_test.rb"
52
93
  ]
53
94
 
54
95
  if s.respond_to? :specification_version then
55
96
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
56
97
  s.specification_version = 3
57
98
 
58
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
- s.add_runtime_dependency(%q<activerecord>, [">= 2.1"])
60
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
61
- s.add_development_dependency(%q<jnunemaker-matchy>, [">= 0"])
99
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
100
+ s.add_runtime_dependency(%q<activerecord>, ["= 3.0.3"])
101
+ s.add_development_dependency(%q<rails>, ["= 3.0.3"])
102
+ s.add_development_dependency(%q<rspec-rails>, ["~> 2.4.0"])
62
103
  else
63
- s.add_dependency(%q<activerecord>, [">= 2.1"])
64
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
65
- s.add_dependency(%q<jnunemaker-matchy>, [">= 0"])
104
+ s.add_dependency(%q<activerecord>, ["= 3.0.3"])
105
+ s.add_dependency(%q<rails>, ["= 3.0.3"])
106
+ s.add_dependency(%q<rspec-rails>, ["~> 2.4.0"])
66
107
  end
67
108
  else
68
- s.add_dependency(%q<activerecord>, [">= 2.1"])
69
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
70
- s.add_dependency(%q<jnunemaker-matchy>, [">= 0"])
109
+ s.add_dependency(%q<activerecord>, ["= 3.0.3"])
110
+ s.add_dependency(%q<rails>, ["= 3.0.3"])
111
+ s.add_dependency(%q<rspec-rails>, ["~> 2.4.0"])
71
112
  end
72
113
  end
73
114