appstats 0.21.1 → 0.21.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/appstats/audit.rb +12 -6
- data/lib/appstats/version.rb +1 -1
- data/spec/audit_spec.rb +9 -0
- data/spec/query_spec.rb +2 -0
- metadata +4 -4
data/lib/appstats/audit.rb
CHANGED
@@ -8,7 +8,8 @@ module Appstats
|
|
8
8
|
|
9
9
|
def self.audit_create(obj, options = {})
|
10
10
|
count = 0
|
11
|
-
return count
|
11
|
+
return count unless auditable?(obj)
|
12
|
+
|
12
13
|
table_name = obj.class.table_name
|
13
14
|
obj_name = obj.class.name
|
14
15
|
|
@@ -23,7 +24,7 @@ module Appstats
|
|
23
24
|
|
24
25
|
def self.audit_update(obj, options = {})
|
25
26
|
count = 0
|
26
|
-
return count
|
27
|
+
return count unless auditable?(obj)
|
27
28
|
|
28
29
|
obj.changed_attributes.each do |obj_attr,old_value|
|
29
30
|
new_value = obj.send("#{obj_attr}")
|
@@ -33,21 +34,26 @@ module Appstats
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def self.audit_destroy(obj, options = {})
|
36
|
-
count =
|
37
|
+
count = 0
|
38
|
+
return count unless auditable?(obj)
|
39
|
+
count += save_audit(obj, { :action => "destroyed" }, options)
|
37
40
|
count
|
38
41
|
end
|
39
42
|
|
40
43
|
private
|
44
|
+
|
45
|
+
def self.auditable?(obj)
|
46
|
+
return false if obj.nil?
|
47
|
+
return false if obj.class == Appstats::Audit # cannot audit yourself - infinite recursion issues
|
48
|
+
true
|
49
|
+
end
|
41
50
|
|
42
51
|
def self.save_audit(obj,custom_fields,options = {})
|
43
|
-
return 0 if obj.nil?
|
44
|
-
|
45
52
|
if custom_fields.key?(:obj_attr)
|
46
53
|
obj_attr = custom_fields[:obj_attr]
|
47
54
|
return 0 if (options.key?(:except) && options[:except].include?(obj_attr.to_sym))
|
48
55
|
return 0 if (options.key?(:only) && !options[:only].include?(obj_attr.to_sym))
|
49
56
|
end
|
50
|
-
|
51
57
|
column_type = custom_fields.key?(:obj_attr) ? obj.class.columns_hash[custom_fields[:obj_attr]].sql_type : nil
|
52
58
|
obj_type = custom_fields.key?(:obj_attr) ? obj.class.columns_hash[custom_fields[:obj_attr]].type : nil
|
53
59
|
default_fields = { :table_name => obj.class.table_name, :column_type => column_type, :obj_type => obj_type, :obj_name => obj.class.name, :obj_id => obj.id, :old_value_full => custom_fields[:old_value], :new_value_full => custom_fields[:new_value] }
|
data/lib/appstats/version.rb
CHANGED
data/spec/audit_spec.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
module Appstats
|
4
|
+
|
5
|
+
class Audit
|
6
|
+
acts_as_auditable
|
7
|
+
end
|
8
|
+
|
4
9
|
describe Audit do
|
5
10
|
|
6
11
|
before(:each) do
|
@@ -41,6 +46,10 @@ module Appstats
|
|
41
46
|
|
42
47
|
end
|
43
48
|
|
49
|
+
it "should ignore itself - even if requested" do
|
50
|
+
Audit.create(:table_name => "ignore")
|
51
|
+
end
|
52
|
+
|
44
53
|
describe "save a new object" do
|
45
54
|
|
46
55
|
it "should call audit_create" do
|
data/spec/query_spec.rb
CHANGED
@@ -496,6 +496,8 @@ module Appstats
|
|
496
496
|
result = query.run
|
497
497
|
result.count.should == 10
|
498
498
|
result.group_by.should == "service_provider, user"
|
499
|
+
|
500
|
+
# sometimes it is four?!?
|
499
501
|
result.sub_results.size.should == 3
|
500
502
|
|
501
503
|
result.sub_results[0].should == SubResult.new(:context_filter => "a, 1", :count => 5, :ratio_of_total => 0.50)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appstats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 79
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 21
|
9
|
-
-
|
10
|
-
version: 0.21.
|
9
|
+
- 2
|
10
|
+
version: 0.21.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andrew Forward
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-12 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|