Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ActsAsAudited.ignored_attributes accessor to set ignored attributes #56

Merged
merged 1 commit into from

2 participants

@senny

We have some attributes in our Application which are distributed over different tables but should never go into the audits-table (like the delta attribute for ThinkingSphinx). I changed the source slightly to make the list of ignored-attributes configurable on the ActsAsAudited Module.

Cheers
-- Yves

@danielmorrison danielmorrison merged commit a7f6b7a into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
8 lib/acts_as_audited.rb
@@ -26,6 +26,14 @@
module ActsAsAudited
VERSION = '2.0.0.rc7'
+ class << self
+ attr_accessor_with_default :ignored_attributes, ['lock_version',
+ 'created_at',
+ 'updated_at',
+ 'created_on',
+ 'updated_on']
+ end
+
mattr_accessor :current_user_method
# The method to be called to return the current user for logging in the audits.
@@current_user_method = :current_user
View
3  lib/acts_as_audited/auditor.rb
@@ -59,8 +59,7 @@ def acts_as_audited(options = {})
if options[:only]
except = self.column_names - options[:only].flatten.map(&:to_s)
else
- except = [self.primary_key, inheritance_column, 'lock_version',
- 'created_at', 'updated_at', 'created_on', 'updated_on']
+ except = [self.primary_key, inheritance_column] + ActsAsAudited.ignored_attributes
except |= Array(options[:except]).collect(&:to_s) if options[:except]
end
write_inheritable_attribute :non_audited_columns, except
View
9 spec/acts_as_audited_spec.rb
@@ -17,6 +17,15 @@
end
end
+ it "should be configurable which attributes are not audited" do
+ ActsAsAudited.ignored_attributes = ['delta', 'top_secret', 'created_at']
+ class Secret < ActiveRecord::Base
+ acts_as_audited
+ end
+
+ Secret.non_audited_columns.should include('delta', 'top_secret', 'created_at')
+ end
+
it "should not save non-audited columns" do
create_user.audits.first.audited_changes.keys.any? { |col| ['created_at', 'updated_at', 'password'].include?( col ) }.should be_false
end
Something went wrong with that request. Please try again.