auditing 1.3.0 → 1.3.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/.gitignore +2 -0
- data/Gemfile.lock +12 -9
- data/README.markdown +1 -1
- data/auditing.gemspec +2 -0
- data/lib/auditing/auditor.rb +2 -2
- data/lib/auditing/base.rb +15 -7
- data/lib/auditing/version.rb +1 -1
- data/spec/auditing/base_spec.rb +0 -44
- data/spec/auditing/formats_spec.rb +91 -0
- data/spec/schema.rb +1 -0
- data/spec/spec_helper.rb +2 -2
- metadata +28 -4
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
auditing (1.
|
4
|
+
auditing (1.3.0)
|
5
5
|
activerecord (~> 3.0.0)
|
6
|
+
activesupport (~> 3.0.0)
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: http://rubygems.org/
|
9
10
|
specs:
|
10
|
-
activemodel (3.0.
|
11
|
-
activesupport (= 3.0.
|
11
|
+
activemodel (3.0.6)
|
12
|
+
activesupport (= 3.0.6)
|
12
13
|
builder (~> 2.1.2)
|
13
|
-
i18n (~> 0.
|
14
|
-
activerecord (3.0.
|
15
|
-
activemodel (= 3.0.
|
16
|
-
activesupport (= 3.0.
|
14
|
+
i18n (~> 0.5.0)
|
15
|
+
activerecord (3.0.6)
|
16
|
+
activemodel (= 3.0.6)
|
17
|
+
activesupport (= 3.0.6)
|
17
18
|
arel (~> 2.0.2)
|
18
19
|
tzinfo (~> 0.3.23)
|
19
|
-
activesupport (3.0.
|
20
|
+
activesupport (3.0.6)
|
20
21
|
arel (2.0.9)
|
21
22
|
builder (2.1.2)
|
22
23
|
diff-lcs (1.1.2)
|
@@ -33,7 +34,8 @@ GEM
|
|
33
34
|
sqlite3 (1.3.3)
|
34
35
|
sqlite3-ruby (1.3.3)
|
35
36
|
sqlite3 (>= 1.3.3)
|
36
|
-
|
37
|
+
timecop (0.3.5)
|
38
|
+
tzinfo (0.3.26)
|
37
39
|
|
38
40
|
PLATFORMS
|
39
41
|
ruby
|
@@ -43,3 +45,4 @@ DEPENDENCIES
|
|
43
45
|
rake (~> 0.8.7)
|
44
46
|
rspec (~> 2.4.0)
|
45
47
|
sqlite3-ruby
|
48
|
+
timecop
|
data/README.markdown
CHANGED
@@ -26,7 +26,7 @@ If you want to track the user, uncomment the t.integer :user_id above. See the
|
|
26
26
|
|
27
27
|
## Upgrading to 1.3.0
|
28
28
|
|
29
|
-
New installs will not need to do this. Anyone that is using 1.2.
|
29
|
+
New installs will not need to do this. Anyone that is using 1.2.X and below should upgrade
|
30
30
|
|
31
31
|
gem update auditing
|
32
32
|
# ... updates happen
|
data/auditing.gemspec
CHANGED
@@ -15,8 +15,10 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.add_development_dependency(%q<rspec>, ["~> 2.4.0"])
|
16
16
|
s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
|
17
17
|
s.add_development_dependency "sqlite3-ruby"
|
18
|
+
s.add_development_dependency "timecop"
|
18
19
|
|
19
20
|
s.add_dependency('activerecord', '~> 3.0.0')
|
21
|
+
s.add_dependency('activesupport', '~> 3.0.0')
|
20
22
|
|
21
23
|
s.rubyforge_project = "auditing"
|
22
24
|
|
data/lib/auditing/auditor.rb
CHANGED
@@ -7,12 +7,12 @@ module Auditing
|
|
7
7
|
|
8
8
|
def old_value
|
9
9
|
return nil unless read_attribute(:old_value)
|
10
|
-
Marshal.load(read_attribute(:old_value))
|
10
|
+
Marshal.load( ActiveSupport::Base64.decode64( read_attribute(:old_value) ) )
|
11
11
|
end
|
12
12
|
|
13
13
|
def new_value
|
14
14
|
return nil unless read_attribute(:new_value)
|
15
|
-
Marshal.load(read_attribute(:new_value))
|
15
|
+
Marshal.load( ActiveSupport::Base64.decode64( read_attribute(:new_value) ) )
|
16
16
|
end
|
17
17
|
|
18
18
|
def rollback
|
data/lib/auditing/base.rb
CHANGED
@@ -28,18 +28,26 @@ module Auditing
|
|
28
28
|
end
|
29
29
|
|
30
30
|
module InstanceMethods
|
31
|
+
# http://stackoverflow.com/questions/1906421/problem-saving-rails-marshal-in-sqlite3-db
|
32
|
+
|
33
|
+
def dump_data(value)
|
34
|
+
ActiveSupport::Base64.encode64(Marshal.dump(value))
|
35
|
+
end
|
36
|
+
|
31
37
|
def log_creation
|
32
38
|
add_audit(:action => 'created', :undoable => false)
|
33
39
|
end
|
34
|
-
|
40
|
+
|
35
41
|
def log_update
|
36
42
|
if changed?
|
37
43
|
changes.each.select {|k,v| auditing_fields.include?(k)}.each do |field, change|
|
38
44
|
next if change[0].to_s == change[1].to_s
|
45
|
+
|
39
46
|
add_audit(:action => 'updated',
|
40
47
|
:field_name => field,
|
41
|
-
:old_value =>
|
42
|
-
:new_value =>
|
48
|
+
:old_value => dump_data(change[0]),
|
49
|
+
:new_value => dump_data(change[1])
|
50
|
+
)
|
43
51
|
end
|
44
52
|
end
|
45
53
|
end
|
@@ -48,16 +56,16 @@ module Auditing
|
|
48
56
|
add_audit(:action => 'added',
|
49
57
|
:association => child_object,
|
50
58
|
:field_name => hash[:field],
|
51
|
-
:old_value =>
|
52
|
-
:new_value =>
|
59
|
+
:old_value => dump_data(nil),
|
60
|
+
:new_value => dump_data(hash[:value]) )
|
53
61
|
end
|
54
62
|
|
55
63
|
def log_association_update(child_object, hash)
|
56
64
|
add_audit(:action => 'updated',
|
57
65
|
:association => child_object,
|
58
66
|
:field_name => hash[:field],
|
59
|
-
:old_value =>
|
60
|
-
:new_value =>
|
67
|
+
:old_value => ( dump_data(hash[:old_value]) if hash[:old_value] ) || dump_data(nil),
|
68
|
+
:new_value => dump_data(hash[:new_value]) )
|
61
69
|
end
|
62
70
|
|
63
71
|
def log_association_destroy(item)
|
data/lib/auditing/version.rb
CHANGED
data/spec/auditing/base_spec.rb
CHANGED
@@ -204,48 +204,4 @@ describe "Base" do
|
|
204
204
|
end
|
205
205
|
end # belongs_to relationships
|
206
206
|
|
207
|
-
describe "text fields" do
|
208
|
-
before do
|
209
|
-
class Special < ActiveRecord::Base
|
210
|
-
audit_enabled
|
211
|
-
end
|
212
|
-
end
|
213
|
-
|
214
|
-
it "should properly work on creation" do
|
215
|
-
long_string = 'a'
|
216
|
-
2000.times do
|
217
|
-
long_string << 'b'
|
218
|
-
end
|
219
|
-
special = Special.create(:text_field => long_string)
|
220
|
-
special.audits.should_not be_nil
|
221
|
-
end
|
222
|
-
|
223
|
-
describe "updating a text field" do
|
224
|
-
before do
|
225
|
-
@long_string = 'a'
|
226
|
-
@new_long_string = 'c'
|
227
|
-
2000.times do
|
228
|
-
@long_string << 'b'
|
229
|
-
@new_long_string << 'd'
|
230
|
-
end
|
231
|
-
@special = Special.create(:text_field => @long_string)
|
232
|
-
end
|
233
|
-
|
234
|
-
it "should create an audit log when we update a text field" do
|
235
|
-
lambda {@special.update_attributes(:text_field => @new_long_string)
|
236
|
-
}.should change { Audit.count }.by(1)
|
237
|
-
end
|
238
|
-
|
239
|
-
it "should allow access to the old and new values" do
|
240
|
-
@special.update_attributes(:text_field => @new_long_string)
|
241
|
-
audit = @special.audits.first
|
242
|
-
audit.old_value.should eql(@long_string)
|
243
|
-
audit.new_value.should eql(@new_long_string)
|
244
|
-
end
|
245
|
-
|
246
|
-
end
|
247
|
-
|
248
|
-
|
249
|
-
end
|
250
|
-
|
251
207
|
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'timecop'
|
3
|
+
|
4
|
+
describe "formats" do
|
5
|
+
|
6
|
+
describe "text fields" do
|
7
|
+
before do
|
8
|
+
class Special < ActiveRecord::Base
|
9
|
+
audit_enabled
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should properly work on creation" do
|
14
|
+
long_string = 'a'
|
15
|
+
2000.times do
|
16
|
+
long_string << 'b'
|
17
|
+
end
|
18
|
+
special = Special.create(:text_field => long_string)
|
19
|
+
special.audits.should_not be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "updating a text field" do
|
23
|
+
before do
|
24
|
+
@long_string = 'a'
|
25
|
+
@new_long_string = 'c'
|
26
|
+
2000.times do
|
27
|
+
@long_string << 'b'
|
28
|
+
@new_long_string << 'd'
|
29
|
+
end
|
30
|
+
@special = Special.create(:text_field => @long_string)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should create an audit log when we update a text field" do
|
34
|
+
lambda {@special.update_attributes(:text_field => @new_long_string)
|
35
|
+
}.should change { Audit.count }.by(1)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should allow access to the old and new values" do
|
39
|
+
@special.update_attributes(:text_field => @new_long_string)
|
40
|
+
audit = @special.audits.first
|
41
|
+
audit.old_value.should eql(@long_string)
|
42
|
+
audit.new_value.should eql(@new_long_string)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "date_fields" do
|
48
|
+
before do
|
49
|
+
class Special < ActiveRecord::Base
|
50
|
+
audit_enabled
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should properly work on creation" do
|
55
|
+
special = Special.create(:date_field => Date.today)
|
56
|
+
special.audits.should_not be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it "can update a blank date field" do
|
60
|
+
special = Special.create
|
61
|
+
special.date_field = Date.today
|
62
|
+
lambda { special.save }.should change { Audit.count }.by(1)
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "updating a date field" do
|
66
|
+
before do
|
67
|
+
new_time = Time.local(2008, 9, 1, 12, 0, 0)
|
68
|
+
Timecop.freeze(new_time) # 2008-09-01
|
69
|
+
@special = Special.create(:date_field => Date.today)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should create an audit log when we update a text field" do
|
73
|
+
lambda {@special.update_attributes(:date_field => Date.today + 1)
|
74
|
+
}.should change { Audit.count }.by(1)
|
75
|
+
Timecop.return
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should allow access to the old and new values" do
|
79
|
+
@special.update_attributes(:date_field => Date.today + 1)
|
80
|
+
audit = @special.audits.first
|
81
|
+
audit.old_value.should eql(Date.today)
|
82
|
+
audit.new_value.should eql(Date.today + 1)
|
83
|
+
|
84
|
+
Timecop.return
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
data/spec/schema.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: auditing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.3.
|
5
|
+
version: 1.3.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brad Cantin
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-15 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -47,16 +47,38 @@ dependencies:
|
|
47
47
|
type: :development
|
48
48
|
version_requirements: *id003
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
50
|
+
name: timecop
|
51
51
|
prerelease: false
|
52
52
|
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: activerecord
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
53
64
|
none: false
|
54
65
|
requirements:
|
55
66
|
- - ~>
|
56
67
|
- !ruby/object:Gem::Version
|
57
68
|
version: 3.0.0
|
58
69
|
type: :runtime
|
59
|
-
version_requirements: *
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: activesupport
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 3.0.0
|
80
|
+
type: :runtime
|
81
|
+
version_requirements: *id006
|
60
82
|
description: acts_as_versioned is good. This allows an attribute level rollback instead
|
61
83
|
email:
|
62
84
|
- brad.cantin@gmail.com
|
@@ -96,6 +118,7 @@ files:
|
|
96
118
|
- spec/auditing/audit_relationship_spec.rb
|
97
119
|
- spec/auditing/auditor_spec.rb
|
98
120
|
- spec/auditing/base_spec.rb
|
121
|
+
- spec/auditing/formats_spec.rb
|
99
122
|
- spec/auditing/with_users_spec.rb
|
100
123
|
- spec/schema.rb
|
101
124
|
- spec/spec_helper.rb
|
@@ -131,6 +154,7 @@ test_files:
|
|
131
154
|
- spec/auditing/audit_relationship_spec.rb
|
132
155
|
- spec/auditing/auditor_spec.rb
|
133
156
|
- spec/auditing/base_spec.rb
|
157
|
+
- spec/auditing/formats_spec.rb
|
134
158
|
- spec/auditing/with_users_spec.rb
|
135
159
|
- spec/schema.rb
|
136
160
|
- spec/spec_helper.rb
|