auditable 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ - CHANGELOG.md
@@ -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 `Auditable::Auditing#audited_changes` below.
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}
@@ -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
- last_audit.update_attribute(:tag, tag) if last_audit
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
@@ -1,3 +1,3 @@
1
1
  module Auditable
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -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 " do
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
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 00:00:00.000000000 Z
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: &2156151900 !ruby/object:Gem::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: *2156151900
24
+ version_requirements: *2164398120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2156151400 !ruby/object:Gem::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: *2156151400
35
+ version_requirements: *2164397600
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: watchr
38
- requirement: &2156150840 !ruby/object:Gem::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: *2156150840
46
+ version_requirements: *2164397060
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &2156150280 !ruby/object:Gem::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: *2156150280
57
+ version_requirements: *2164396480
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: yard
60
- requirement: &2156149760 !ruby/object:Gem::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: *2156149760
68
+ version_requirements: *2164395960
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdiscount
71
- requirement: &2156149340 !ruby/object:Gem::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: *2156149340
79
+ version_requirements: *2164395540
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activesupport
82
- requirement: &2156148740 !ruby/object:Gem::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: *2156148740
90
+ version_requirements: *2164395020
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: activerecord
93
- requirement: &2156147660 !ruby/object:Gem::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: *2156147660
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: -2973896956305891645
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: -2973896956305891645
155
+ hash: 3768124813629379873
154
156
  requirements: []
155
157
  rubyforge_project:
156
158
  rubygems_version: 1.8.17