auditor 2.1.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/auditor/recorder.rb +6 -4
- data/lib/auditor/version.rb +1 -1
- data/spec/auditable_spec.rb +9 -0
- metadata +4 -4
data/lib/auditor/recorder.rb
CHANGED
@@ -24,8 +24,11 @@ module Auditor
|
|
24
24
|
audit = Audit.new
|
25
25
|
audit.auditable_id = model.id
|
26
26
|
audit.auditable_type = model.class.name
|
27
|
-
audit.audited_changes = prepare_changes(model.changes) if
|
27
|
+
audit.audited_changes = prepare_changes(model.changes) if model.changed?
|
28
28
|
audit.action = action
|
29
|
+
|
30
|
+
return if noop?(audit)
|
31
|
+
|
29
32
|
audit.comment = @blk.call(model, user, action) if @blk
|
30
33
|
|
31
34
|
without_auditing do
|
@@ -44,9 +47,8 @@ module Auditor
|
|
44
47
|
chg.empty? ? nil : chg
|
45
48
|
end
|
46
49
|
|
47
|
-
def
|
48
|
-
|
50
|
+
def noop?(audit)
|
51
|
+
audit.action == :update && !audit.audited_changes.present?
|
49
52
|
end
|
50
|
-
|
51
53
|
end
|
52
54
|
end
|
data/lib/auditor/version.rb
CHANGED
data/spec/auditable_spec.rb
CHANGED
@@ -97,6 +97,15 @@ describe Auditor::Auditable do
|
|
97
97
|
m.attributes_at(ts4).should == {'name' => '2', 'id' => m.id}
|
98
98
|
end
|
99
99
|
|
100
|
+
it 'should not save an update record that does not have any audited changes' do
|
101
|
+
redefine_model { audit!(:update, :except => :name) }
|
102
|
+
|
103
|
+
lambda {
|
104
|
+
m = Model.create(:name => 'new')
|
105
|
+
m.update_attributes({:name => 'newer'})
|
106
|
+
}.should_not change(Audit, :count)
|
107
|
+
end
|
108
|
+
|
100
109
|
def verify_audit(audit, model, changes=nil)
|
101
110
|
audit.should_not be_nil
|
102
111
|
audit.auditable.should == model unless audit.action == 'destroy'
|
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:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 2.1.
|
9
|
+
- 1
|
10
|
+
version: 2.1.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-
|
18
|
+
date: 2011-07-05 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|