Skip to content

Commit

Permalink
Merge branch 'master' into braintreeps-master
Browse files Browse the repository at this point in the history
Conflicts:
	lib/audited/sweeper.rb
  • Loading branch information
kennethkalmer committed Jan 6, 2015
2 parents 4703a53 + 36d2874 commit 158a6db
Show file tree
Hide file tree
Showing 48 changed files with 875 additions and 380 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -1,6 +1,12 @@
*.iml
*.ipr
*.iws
*.log
*.swp
.bundle
.rakeTasks
.ruby-gemset
.ruby-version
.rvmrc
.yardoc
coverage/
Expand Down
16 changes: 6 additions & 10 deletions .travis.yml
@@ -1,13 +1,9 @@
language: ruby
services: mongodb
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- ruby-head
branches:
only:
- master
- v3
- 2.0.0
- 2.1.2
gemfile:
- gemfiles/rails30.gemfile
- gemfiles/rails31.gemfile
- gemfiles/rails32.gemfile
- gemfiles/rails40.gemfile
- gemfiles/rails41.gemfile
14 changes: 6 additions & 8 deletions Appraisals
@@ -1,11 +1,9 @@
appraise 'rails30' do
gem 'rails', '~> 3.0.0'
appraise 'rails40' do
gem 'rails', '~> 4.0.0'
gem 'rails-observers'
end

appraise 'rails31' do
gem 'rails', '~> 3.1.0'
end

appraise 'rails32' do
gem 'rails', '~> 3.2.0'
appraise 'rails41' do
gem 'rails', '~> 4.1.0'
gem 'rails-observers'
end
96 changes: 84 additions & 12 deletions README.md
@@ -1,16 +1,17 @@
Audited [![Build Status](https://secure.travis-ci.org/collectiveidea/audited.png)](http://travis-ci.org/collectiveidea/audited) [![Dependency Status](https://gemnasium.com/collectiveidea/audited.png)](https://gemnasium.com/collectiveidea/audited)
Audited [![Build Status](https://secure.travis-ci.org/collectiveidea/audited.png)](http://travis-ci.org/collectiveidea/audited) [![Dependency Status](https://gemnasium.com/collectiveidea/audited.png)](https://gemnasium.com/collectiveidea/audited)[![Code Climate](https://codeclimate.com/github/collectiveidea/audited.png)](https://codeclimate.com/github/collectiveidea/audited)
=======

**Audited** (previously acts_as_audited) is an ORM extension that logs all changes to your models. Audited also allows you to record who made those changes, save comments and associate models related to the changes. Audited works with Rails 3.
**Audited** (previously acts_as_audited) is an ORM extension that logs all changes to your models. Audited also allows you to record who made those changes, save comments and associate models related to the changes.

Audited currently (4.x) works with Rails 4. For Rails 3, use gem version 3.0 or see the [3.0-stable branch](https://github.com/collectiveidea/audited/tree/3.0-stable).

## Supported Rubies

Audited supports and is [tested against](http://travis-ci.org/collectiveidea/audited) the following Ruby versions:

* 1.8.7
* 1.9.2
* 1.9.3
* Head
* 2.0.0
* 2.1.2

Audited may work just fine with a Ruby version not listed above, but we can't guarantee that it will. If you'd like to maintain a Ruby that isn't listed, please let us know with a [pull request](https://github.com/collectiveidea/audited/pulls).

Expand All @@ -30,7 +31,7 @@ The installation process depends on what ORM your app is using.
Add the appropriate gem to your Gemfile:

```ruby
gem "audited-activerecord", "~> 3.0"
gem "audited-activerecord", "~> 4.0"
```

Then, from your Rails app directory, create the `audits` table:
Expand All @@ -54,7 +55,7 @@ Upgrading will only make changes if changes are needed.
### MongoMapper

```ruby
gem "audited-mongo_mapper", "~> 3.0"
gem "audited-mongo_mapper", "~> 4.0"
```

## Usage
Expand Down Expand Up @@ -87,6 +88,40 @@ audit.action # => "update"
audit.audited_changes # => {"name"=>["Steve", "Ryan"]}
```

### Specifying columns

By default, a new audit is created for any attribute changes. You can, however, limit the columns to be considered.

```ruby
class User < ActiveRecord::Base
# All fields
# audited

# Single field
# audited only: :name

# Multiple fields
# audited only: [:name, :address]

# All except certain fields
# audited except: :password
end
```

### Specifying callbacks

By default, a new audit is created for any Create, Update or Destroy action. You can, however, limit the actions audited.

```ruby
class User < ActiveRecord::Base
# All fields and actions
# audited

# Single field, only audit Update and Destroy (not Create)
# audited only: :name, on: [:update, :destroy]
end
```

### Comments

You can attach comments to each audit using an `audit_comment` attribute on your model.
Expand Down Expand Up @@ -118,7 +153,7 @@ class PostsController < ApplicationController
end
```

To use a method other than `current_user`, put the following in an intializer:
To use a method other than `current_user`, put the following in an initializer:

```ruby
Audited.current_user_method = :authenticated_user
Expand All @@ -127,7 +162,7 @@ Audited.current_user_method = :authenticated_user
Outside of a request, Audited can still record the user with the `as_user` method:

```ruby
Audit.as_user(User.find(1)) do
Audited.audit_class.as_user(User.find(1)) do
post.update_attribute!(:title => "Hello, world!")
end
post.audits.last.user # => #<User id: 1>
Expand Down Expand Up @@ -172,20 +207,57 @@ user.audits.last.associated # => #<Company name: "Collective Idea">
company.associated_audits.last.auditable # => #<User name: "Steve Richert">
```

### Disabling auditing

If you want to disable auditing temporarily doing certain tasks, there are a few
methods available.

To disable auditing on a save:

```ruby
@user.save_without_auditing
```

or:

```ruby
@user.without_auditing do
@user.save
end
```

To disable auditing on a column:

```ruby
User.non_audited_columns = [:first_name, :last_name]
```

To disable auditing on an entire model:

```ruby
User.auditing_enabled = false
```

## Gotchas

### Accessible Attributes
### Using attr_protected or strong_parameters

Audited assumes you are using `attr_accessible`, however, if you are using `attr_protected` or just going at it unprotected you will have to set the `:allow_mass_assignment => true` option.
Audited assumes you are using `attr_accessible`. If you're using
`attr_protected` or `strong_parameters`, you'll have to take an extra step or
two.

If using `attr_protected` be sure to add `audit_ids` to the list of protected attributes to prevent data loss.

If you're using `strong_parameters` with Rails 3.x, be sure to add `:allow_mass_assignment => true` to your `audited` call; otherwise Audited will
interfere with `strong_parameters` and none of your `save` calls will work.

```ruby
class User < ActiveRecord::Base
audited :allow_mass_assignment => true
end
```

If using `attr_protected`, add `:allow_mass_assignment => true`, and also be sure to add `audit_ids` to the list of protected attributes to prevent data loss.

```ruby
class User < ActiveRecord::Base
audited :allow_mass_assignment => true
Expand Down
15 changes: 12 additions & 3 deletions Rakefile 100644 → 100755
Expand Up @@ -2,6 +2,7 @@

require 'bundler/gem_helper'
require 'rspec/core/rake_task'
require 'rake/testtask'
require 'appraisal'

Bundler::GemHelper.install_tasks(:name => 'audited')
Expand All @@ -17,8 +18,16 @@ ADAPTERS.each do |adapter|
end
end

RSpec::Core::RakeTask.new(:spec => ADAPTERS) do |t|
t.pattern = 'spec/audited/*_spec.rb'
task :spec do
ADAPTERS.each do |adapter|
Rake::Task[adapter].invoke
end
end

Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
end

task :default => :spec
task :default => [:spec, :test]
12 changes: 9 additions & 3 deletions audited-activerecord.gemspec
@@ -1,19 +1,25 @@
# encoding: utf-8

$:.push File.expand_path("../lib", __FILE__)
require "audited/version"
require "audited/active_record/version"

Gem::Specification.new do |gem|
gem.name = 'audited-activerecord'
gem.version = '3.0.0.rc2'
gem.version = Audited::ActiveRecord::VERSION

gem.authors = ['Brandon Keepers', 'Kenneth Kalmer', 'Daniel Morrison', 'Brian Ryckbost', 'Steve Richert', 'Ryan Glover']
gem.email = 'info@collectiveidea.com'
gem.description = 'Log all changes to your ActiveRecord models'
gem.summary = gem.description
gem.homepage = 'https://github.com/collectiveidea/audited'
gem.license = 'MIT'

gem.add_dependency 'audited', gem.version
gem.add_dependency 'activerecord', '~> 3.0'
gem.add_dependency 'audited', Audited::VERSION
gem.add_dependency 'activerecord', '~> 4.0'

gem.files = `git ls-files lib`.split($\).grep(/(active_?record|generators)/)
gem.files << 'LICENSE'
gem.require_paths = ['lib']
end

12 changes: 9 additions & 3 deletions audited-mongo_mapper.gemspec
@@ -1,19 +1,25 @@
# encoding: utf-8

$:.push File.expand_path("../lib", __FILE__)
require "audited/version"
require "audited/mongo_mapper/version"

Gem::Specification.new do |gem|
gem.name = 'audited-mongo_mapper'
gem.version = '3.0.0.rc2'
gem.version = Audited::MongoMapper::VERSION

gem.authors = ['Brandon Keepers', 'Kenneth Kalmer', 'Daniel Morrison', 'Brian Ryckbost', 'Steve Richert', 'Ryan Glover']
gem.email = 'info@collectiveidea.com'
gem.description = 'Log all changes to your MongoMapper models'
gem.summary = gem.description
gem.homepage = 'https://github.com/collectiveidea/audited'
gem.license = 'MIT'

gem.add_dependency 'audited', gem.version
gem.add_dependency 'mongo_mapper', '~> 0.11'
gem.add_dependency 'audited', Audited::VERSION
gem.add_dependency 'mongo_mapper', '~> 0.12.0'

gem.files = `git ls-files lib`.split($\).grep(/mongo_mapper/)
gem.files << 'LICENSE'
gem.require_paths = ['lib']
end

18 changes: 11 additions & 7 deletions audited.gemspec
@@ -1,24 +1,28 @@
# encoding: utf-8
$:.push File.expand_path("../lib", __FILE__)
require "audited/version"

Gem::Specification.new do |gem|
gem.name = 'audited'
gem.version = '3.0.0.rc2'
gem.version = Audited::VERSION

gem.authors = ['Brandon Keepers', 'Kenneth Kalmer', 'Daniel Morrison', 'Brian Ryckbost', 'Steve Richert', 'Ryan Glover']
gem.email = 'info@collectiveidea.com'
gem.description = 'Log all changes to your models'
gem.summary = gem.description
gem.homepage = 'https://github.com/collectiveidea/audited'
gem.license = 'MIT'

gem.add_development_dependency 'activerecord', '~> 3.0'
gem.add_development_dependency 'appraisal', '~> 0.4'
gem.add_dependency 'rails-observers', '~> 0.1.2'
gem.add_development_dependency "protected_attributes"
gem.add_development_dependency 'appraisal', '~> 1.0.0'
gem.add_development_dependency 'bson_ext', '~> 1.6'
gem.add_development_dependency 'mongo_mapper', '~> 0.11'
gem.add_development_dependency 'rails', '~> 3.0'
gem.add_development_dependency 'rspec-rails', '~> 2.0'
gem.add_development_dependency 'mongo_mapper', '~> 0.13.0.beta2'
gem.add_development_dependency 'rails', '~> 4.0.0'
gem.add_development_dependency 'rspec-rails', '~> 3.0'
gem.add_development_dependency 'sqlite3', '~> 1.0'

gem.files = `git ls-files`.split($\).reject{|f| f =~ /(lib\/audited\-|adapters|generators)/ }
gem.files = `git ls-files`.split($\).reject{|f| f =~ /(\.gemspec|lib\/audited\-|adapters|generators)/ }
gem.test_files = gem.files.grep(/^spec\//)
gem.require_paths = ['lib']
end
Expand Down
7 changes: 0 additions & 7 deletions gemfiles/rails30.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/rails31.gemfile

This file was deleted.

7 changes: 0 additions & 7 deletions gemfiles/rails32.gemfile

This file was deleted.

8 changes: 8 additions & 0 deletions gemfiles/rails40.gemfile
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 4.0.0"
gem "rails-observers"

gemspec :name => "audited", :path => "../"
8 changes: 8 additions & 0 deletions gemfiles/rails41.gemfile
@@ -0,0 +1,8 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 4.1.0"
gem "rails-observers"

gemspec :name => "audited", :path => "../"
4 changes: 4 additions & 0 deletions lib/audited-rspec.rb
@@ -0,0 +1,4 @@
require 'audited/rspec_matchers'
module RSpec::Matchers
include Audited::RspecMatchers
end

0 comments on commit 158a6db

Please sign in to comment.