auditable 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -0
- data/CHANGELOG.md +18 -0
- data/README.md +7 -4
- data/lib/auditable/auditing.rb +8 -2
- data/lib/auditable/version.rb +1 -1
- data/spec/lib/auditable_spec.rb +8 -2
- metadata +22 -20
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
- CHANGELOG.md
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# 0.0.5 (2012-03-12)
|
2
|
+
|
3
|
+
## Changes
|
4
|
+
|
5
|
+
Easier to explain with code
|
6
|
+
|
7
|
+
# Given
|
8
|
+
>> s = Survey.create :title => "something"
|
9
|
+
>> s.audits.delete_all
|
10
|
+
|
11
|
+
# Before 0.0.5
|
12
|
+
>> s.audit_tag_with("some tag") # do nothing when no audits exist
|
13
|
+
>> s.audits.empty? # => true
|
14
|
+
|
15
|
+
# From 0.0.5 onwards
|
16
|
+
>> s.audit_tag_with("some tag") # create an audit with tag if no audits exist
|
17
|
+
>> s.audits.first.tag == "some tag"
|
18
|
+
|
data/README.md
CHANGED
@@ -18,9 +18,9 @@ Basically:
|
|
18
18
|
* I don't want the default to track all my columns. Only the attributes or methods I specify please.
|
19
19
|
* I don't want to deal with association mess. Use methods instead.
|
20
20
|
* I care about tracking the values of certain virtual attributes or methods, not just database columns
|
21
|
-
* I want something simple, similar to [ActiveRecord::Dirty#changes](http://ar.rubyonrails.org/classes/ActiveRecord/Dirty.html#M000291) but persistent across saves. See
|
21
|
+
* I want something simple, similar to [ActiveRecord::Dirty#changes](http://ar.rubyonrails.org/classes/ActiveRecord/Dirty.html#M000291) but persistent across saves. See the usage of {Auditable::Auditing#audited_changes} below.
|
22
22
|
|
23
|
-
See examples under Usage section.
|
23
|
+
See examples under {file:README.md#Usage Usage} section. Please check the {file:CHANGELOG.md} as well.
|
24
24
|
|
25
25
|
## Installation
|
26
26
|
|
@@ -130,12 +130,11 @@ If you want to store the user who made the changed to the record, just assigned
|
|
130
130
|
>> @survey.changed_action = "add page"
|
131
131
|
>> @survey.update_attribute :page_count, 2
|
132
132
|
|
133
|
-
**Don't store a new row in `audits` table if the `modifications` column is the same as the one immediately before it. This makes it easier to review change**
|
134
|
-
|
135
133
|
That's all I can do for this README Driven approach. Back soon.
|
136
134
|
|
137
135
|
## TODO
|
138
136
|
|
137
|
+
* **Don't store a new row in the `audits` table if the `modifications` column is the same as the one immediately before it. This makes it easier to review change**
|
139
138
|
* improve api (still clumsy) -- come up with better syntax
|
140
139
|
* get some suggestions and feedback
|
141
140
|
* update README
|
@@ -152,3 +151,7 @@ e.g. right now, changes are serialized into `audits.modifications` column, but w
|
|
152
151
|
3. Commit your changes (`git commit -am 'Added some feature'`)
|
153
152
|
4. Push to the branch (`git push origin my-new-feature`)
|
154
153
|
5. Create new Pull Request
|
154
|
+
|
155
|
+
## CHANGELOG
|
156
|
+
|
157
|
+
{include:file:CHANGELOG.md}
|
data/lib/auditable/auditing.rb
CHANGED
@@ -40,9 +40,15 @@ module Auditable
|
|
40
40
|
audits.last
|
41
41
|
end
|
42
42
|
|
43
|
-
# Mark the latest record in order to easily find and perform diff against later
|
43
|
+
# Mark the latest record with a tag in order to easily find and perform diff against later
|
44
|
+
# If there are no audits for this record, create a new audit with this tag
|
44
45
|
def audit_tag_with(tag)
|
45
|
-
|
46
|
+
if last_audit
|
47
|
+
last_audit.update_attribute(:tag, tag)
|
48
|
+
else
|
49
|
+
self.audit_tag = tag
|
50
|
+
snap!
|
51
|
+
end
|
46
52
|
end
|
47
53
|
|
48
54
|
# Take a snapshot of and save the current state of the audited record's audited attributes
|
data/lib/auditable/version.rb
CHANGED
data/spec/lib/auditable_spec.rb
CHANGED
@@ -23,18 +23,24 @@ describe Auditable do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should not not fail with errors" do
|
26
|
-
survey.audit_tag_with("something") # no audit to tag but should be ok with it
|
27
26
|
survey.audits.count.should == 0
|
28
27
|
survey.audited_changes.should == {}
|
29
28
|
survey.audited_changes(:tag => "something").should == {}
|
30
29
|
end
|
31
30
|
|
32
|
-
it "should work after first update
|
31
|
+
it "should work after first update" do
|
33
32
|
survey.update_attributes :title => "new title"
|
34
33
|
survey.audited_changes.should == {"title" => ["test survey", "new title"]}
|
35
34
|
survey.audited_changes(:tag => "something").should == {"title" => [nil, "new title"]}
|
36
35
|
survey.audits.count.should == 1
|
37
36
|
end
|
37
|
+
|
38
|
+
it "should create a new audit when calling audit_tag_with without existing audits" do
|
39
|
+
survey.audits.count.should == 0
|
40
|
+
survey.audit_tag_with("something") # no audit to tag but should be ok with it
|
41
|
+
survey.audits.count.should == 1
|
42
|
+
survey.audits.last.tag.should == "something"
|
43
|
+
end
|
38
44
|
end
|
39
45
|
|
40
46
|
it "should behave similar to ActiveRecord::Dirty#changes" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auditable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &2164398120 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2164398120
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &2164397600 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '2'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2164397600
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: watchr
|
38
|
-
requirement: &
|
38
|
+
requirement: &2164397060 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2164397060
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sqlite3
|
49
|
-
requirement: &
|
49
|
+
requirement: &2164396480 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2164396480
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: yard
|
60
|
-
requirement: &
|
60
|
+
requirement: &2164395960 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2164395960
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rdiscount
|
71
|
-
requirement: &
|
71
|
+
requirement: &2164395540 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2164395540
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: activesupport
|
82
|
-
requirement: &
|
82
|
+
requirement: &2164395020 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '3.0'
|
88
88
|
type: :runtime
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2164395020
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: activerecord
|
93
|
-
requirement: &
|
93
|
+
requirement: &2164394000 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '3.0'
|
99
99
|
type: :runtime
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *2164394000
|
102
102
|
description: A simple gem that audit models' attributes or methods by taking snapshots
|
103
103
|
and diff them for you. Starting from scratch to work with Rails 3.2.2 onwards
|
104
104
|
email:
|
@@ -111,6 +111,8 @@ files:
|
|
111
111
|
- .rspec
|
112
112
|
- .rvmrc
|
113
113
|
- .travis.yml
|
114
|
+
- .yardopts
|
115
|
+
- CHANGELOG.md
|
114
116
|
- Gemfile
|
115
117
|
- LICENSE
|
116
118
|
- README.md
|
@@ -141,7 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
141
143
|
version: '0'
|
142
144
|
segments:
|
143
145
|
- 0
|
144
|
-
hash:
|
146
|
+
hash: 3768124813629379873
|
145
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
148
|
none: false
|
147
149
|
requirements:
|
@@ -150,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
152
|
version: '0'
|
151
153
|
segments:
|
152
154
|
- 0
|
153
|
-
hash:
|
155
|
+
hash: 3768124813629379873
|
154
156
|
requirements: []
|
155
157
|
rubyforge_project:
|
156
158
|
rubygems_version: 1.8.17
|