auditor 2.0.0 → 2.0.1

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/lib/auditor/audit.rb CHANGED
@@ -11,7 +11,7 @@ class Audit < ActiveRecord::Base
11
11
  serialize :audited_changes
12
12
 
13
13
  default_scope order(:version, :created_at)
14
- scope :modifying, lambda { where('action in (?)', Auditor::Config.modifying_actions) }
14
+ scope :modifying, lambda { where('audited_changes is not null') }
15
15
  scope :trail, lambda { |audit|
16
16
  where('auditable_id = ? and auditable_type = ? and version <= ?',
17
17
  audit.auditable_id, audit.auditable_type, audit.version)
@@ -43,7 +43,7 @@ private
43
43
  :auditable_type => auditable_type
44
44
  ).maximum(:version) || 0
45
45
 
46
- self.version = Auditor::Config.modifying_actions.include?(self.action.to_sym) ? max + 1 : max
46
+ self.version = self.audited_changes == nil ? max : max + 1
47
47
  end
48
48
 
49
49
  def set_user
@@ -7,10 +7,6 @@ module Auditor
7
7
  @valid_actions ||= [:create, :find, :update, :destroy]
8
8
  end
9
9
 
10
- def self.modifying_actions
11
- @modifying_actions ||= [:create, :update, :destroy]
12
- end
13
-
14
10
  def initialize(*args)
15
11
  @options = (args.pop if args.last.kind_of?(Hash)) || {}
16
12
  normalize_options(@options)
@@ -22,7 +22,8 @@ module Auditor
22
22
  user = Auditor::User.current_user
23
23
 
24
24
  audit = Audit.new
25
- audit.auditable = model
25
+ audit.auditable_id = model.id
26
+ audit.auditable_type = model.class.name
26
27
  audit.audited_changes = prepare_changes(model.changes) if changes_available?(action)
27
28
  audit.action = action
28
29
  audit.comment = @blk.call(model, user) if @blk
@@ -32,8 +33,8 @@ module Auditor
32
33
 
33
34
  def prepare_changes(changes)
34
35
  chg = changes.dup
35
- chg = chg.delete_if { |key, value| @options[:except].include?(key) } unless @options[:except].empty?
36
- chg = chg.delete_if { |key, value| !@options[:only].include?(key) } unless @options[:only].empty?
36
+ chg = chg.delete_if { |key, value| @options[:except].include?(key) } unless @options[:except].blank?
37
+ chg = chg.delete_if { |key, value| !@options[:only].include?(key) } unless @options[:only].blank?
37
38
  chg.empty? ? nil : chg
38
39
  end
39
40
 
@@ -1,3 +1,3 @@
1
1
  module Auditor
2
- VERSION = "2.0.0"
2
+ VERSION = "2.0.1"
3
3
  end
data/spec/audit_spec.rb CHANGED
@@ -8,7 +8,7 @@ describe Audit do
8
8
  end
9
9
 
10
10
  it 'should set the version number on save' do
11
- audit = Audit.create(:auditable => @auditable, :user => @user, :action => :create)
11
+ audit = Audit.create(:auditable => @auditable, :audited_changes => { :name => [nil, 'new']}, :user => @user, :action => :create)
12
12
  audit.version.should == 1
13
13
  end
14
14
 
@@ -35,8 +35,8 @@ describe Audit do
35
35
 
36
36
  describe 'modifying scope' do
37
37
  it 'should return all audit records that were a result of modifying the audited object attributes' do
38
- audit1 = Audit.create(:auditable => @auditable, :user => @user, :action => :create)
39
- audit2 = Audit.create(:auditable => @auditable, :user => @user, :action => :update, :audited_changes => {'name' => [nil, 'n1'], 'value' => [nil, 'v1']})
38
+ audit1 = Audit.create(:auditable => @auditable, :user => @user, :action => :create, :audited_changes => {'name' => [nil, 'n0']})
39
+ audit2 = Audit.create(:auditable => @auditable, :user => @user, :action => :update, :audited_changes => {'name' => ['n0', 'n1'], 'value' => [nil, 'v1']})
40
40
  audit3 = Audit.create(:auditable => @auditable, :user => @user, :action => :find)
41
41
  audit4 = Audit.create(:auditable => @auditable, :user => @user, :action => :update, :audited_changes => {'value' => [nil, 'v2']})
42
42
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auditor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 0
10
- version: 2.0.0
9
+ - 1
10
+ version: 2.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jeff Kunkle
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-16 00:00:00 -04:00
18
+ date: 2011-03-21 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency