auditrail 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +5 -1
- data/lib/audit_options.rb +27 -0
- data/lib/auditrail.rb +2 -26
- data/lib/auditrail/version.rb +1 -1
- data/spec/audit_options_spec.rb +19 -0
- data/spec/auditrail_spec.rb +11 -2
- metadata +12 -5
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# auditrail
|
2
|
-
An easy and unobtrusive way to track changes on Active Record models.
|
2
|
+
An easy and unobtrusive way to track changes on Active Record models (only tested with Ruby 1.9.2).
|
3
3
|
|
4
4
|
|
5
5
|
## How it works
|
@@ -84,6 +84,10 @@ Nothing yet.
|
|
84
84
|
* Let the implementor configure where to store the audits.
|
85
85
|
* What the audit table name will be.
|
86
86
|
|
87
|
+
# Changelog
|
88
|
+
|
89
|
+
* 0.0.4 Fixed validation to check unchanged attributes when updating.
|
90
|
+
|
87
91
|
# About the Author
|
88
92
|
[Crowd Interactive](http://www.crowdint.com) is an American web design and development
|
89
93
|
company that happens to work in Colima, Mexico. We specialize in building and growing
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Auditrail
|
2
|
+
module ClassMethods
|
3
|
+
class AuditOptions
|
4
|
+
|
5
|
+
def initialize(&block)
|
6
|
+
instance_eval &block if block
|
7
|
+
end
|
8
|
+
|
9
|
+
def user
|
10
|
+
@user
|
11
|
+
end
|
12
|
+
|
13
|
+
def attributes
|
14
|
+
@attributes
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def by_user(user = nil, &block)
|
19
|
+
@user = block ? block.call : user
|
20
|
+
end
|
21
|
+
|
22
|
+
def for_attributes(*attributes)
|
23
|
+
@attributes = attributes
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/auditrail.rb
CHANGED
@@ -3,6 +3,7 @@ require 'active_support/concern'
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'generators/migrations'
|
5
5
|
require 'generators/model'
|
6
|
+
require 'audit_options'
|
6
7
|
|
7
8
|
module Auditrail
|
8
9
|
|
@@ -10,31 +11,6 @@ module Auditrail
|
|
10
11
|
|
11
12
|
module ClassMethods
|
12
13
|
|
13
|
-
class AuditOptions
|
14
|
-
|
15
|
-
def initialize(&block)
|
16
|
-
instance_eval &block if block
|
17
|
-
end
|
18
|
-
|
19
|
-
def user
|
20
|
-
@user
|
21
|
-
end
|
22
|
-
|
23
|
-
def attributes
|
24
|
-
@attributes
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
def by_user(user = nil, &block)
|
29
|
-
@user = block ? block.call : user
|
30
|
-
end
|
31
|
-
|
32
|
-
def for_attributes(*attributes)
|
33
|
-
@attributes = attributes
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
14
|
def auditable(&block)
|
39
15
|
audit_options = block ? AuditOptions.new(&block) : AuditOptions.new
|
40
16
|
|
@@ -60,7 +36,7 @@ module Auditrail
|
|
60
36
|
|
61
37
|
private
|
62
38
|
def attributes_changed?(*options)
|
63
|
-
(options - changes.keys) != options || options.empty?
|
39
|
+
((options - changes.keys) != options || options.empty?) & changed?
|
64
40
|
end
|
65
41
|
|
66
42
|
|
data/lib/auditrail/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Auditrail::ClassMethods::AuditOptions do
|
4
|
+
before {Object.const_set(:AuditOptions, Class.new(Auditrail::ClassMethods::AuditOptions))}
|
5
|
+
|
6
|
+
context 'methods' do
|
7
|
+
before {@audit_options = AuditOptions.new}
|
8
|
+
|
9
|
+
it 'should contain a method to obtain a user' do
|
10
|
+
@audit_options.should respond_to(:user)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should contain a method to obtain a attributes' do
|
14
|
+
@audit_options.should respond_to(:attributes)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should accept a block as aparameter'
|
19
|
+
end
|
data/spec/auditrail_spec.rb
CHANGED
@@ -72,13 +72,22 @@ describe 'A test class' do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
context 'updates an existing object' do
|
75
|
-
it "should receive
|
75
|
+
it "should receive an updating status" do
|
76
76
|
instance = @test_class.first
|
77
77
|
instance.name = "Text change"
|
78
78
|
instance.save
|
79
79
|
@audit_class.last.action.should eq("updating")
|
80
80
|
end
|
81
|
-
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context 'updates an existing object' do
|
84
|
+
it "should no receive more elements when there is no changes" do
|
85
|
+
lambda{
|
86
|
+
instance = @test_class.first
|
87
|
+
instance.name = "Text"
|
88
|
+
instance.save}.should change(@audit_class, :count).by(0)
|
89
|
+
end
|
90
|
+
end
|
82
91
|
|
83
92
|
end
|
84
93
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Luis Galaviz
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-01-05 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -95,12 +95,14 @@ files:
|
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
97
|
- auditrail.gemspec
|
98
|
+
- lib/audit_options.rb
|
98
99
|
- lib/auditrail.rb
|
99
100
|
- lib/auditrail/version.rb
|
100
101
|
- lib/generators/migrations.rb
|
101
102
|
- lib/generators/model.rb
|
102
103
|
- lib/generators/templates/audit_model.rb
|
103
104
|
- lib/generators/templates/audits_table.rb
|
105
|
+
- spec/audit_options_spec.rb
|
104
106
|
- spec/auditrail_spec.rb
|
105
107
|
- spec/migrations_spec.rb
|
106
108
|
- spec/model_generator_spec.rb
|
@@ -138,5 +140,10 @@ rubygems_version: 1.3.7
|
|
138
140
|
signing_key:
|
139
141
|
specification_version: 3
|
140
142
|
summary: An easy and unobtrusive way to track changes on Active Record models
|
141
|
-
test_files:
|
142
|
-
|
143
|
+
test_files:
|
144
|
+
- spec/audit_options_spec.rb
|
145
|
+
- spec/auditrail_spec.rb
|
146
|
+
- spec/migrations_spec.rb
|
147
|
+
- spec/model_generator_spec.rb
|
148
|
+
- spec/spec_helper.rb
|
149
|
+
- spec/support/active_record.rb
|