paper_trail 2.4.0 → 2.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +12 -1
- data/lib/paper_trail/has_paper_trail.rb +8 -2
- data/lib/paper_trail/version_number.rb +1 -1
- data/test/dummy/app/models/article.rb +1 -0
- data/test/dummy/db/migrate/20110208155312_set_up_test_tables.rb +1 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/unit/model_test.rb +29 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -215,6 +215,14 @@ This means that only changes to the `title` will save a version of the article:
|
|
215
215
|
|
216
216
|
Passing both `:ignore` and `:only` options will result in the article being saved if a changed attribute is included in `:only` but not in `:ignore`.
|
217
217
|
|
218
|
+
You can skip fields altogether with the `:skip` option. As with `:ignore`, updates to these fields will not create a new `Version`. In addition, these fields will not be included in the serialised version of the object whenever a new `Version` is created.
|
219
|
+
|
220
|
+
For example:
|
221
|
+
|
222
|
+
class Article < ActiveRecord::Base
|
223
|
+
has_paper_trail :skip => [:file_upload]
|
224
|
+
end
|
225
|
+
|
218
226
|
|
219
227
|
## Reverting And Undeleting A Model
|
220
228
|
|
@@ -461,7 +469,9 @@ PaperTrail will call your proc with the current article and store the result in
|
|
461
469
|
N.B. You must also:
|
462
470
|
|
463
471
|
* Add your metadata columns to the `versions` table.
|
464
|
-
* Declare your metadata columns using `attr_accessible
|
472
|
+
* Declare your metadata columns using `attr_accessible`.
|
473
|
+
|
474
|
+
For example:
|
465
475
|
|
466
476
|
# config/initializers/paper_trail.rb
|
467
477
|
class Version < ActiveRecord::Base
|
@@ -661,6 +671,7 @@ Many thanks to:
|
|
661
671
|
* [Eduard Tsech](https://github.com/edtsech)
|
662
672
|
* [Mathieu Arnold](https://github.com/mat813)
|
663
673
|
* [Nicholas Thrower](https://github.com/throwern)
|
674
|
+
* [Benjamin Curtis](https://github.com/stympy)
|
664
675
|
|
665
676
|
|
666
677
|
## Inspirations
|
@@ -16,6 +16,9 @@ module PaperTrail
|
|
16
16
|
# :class_name the name of a custom Version class. This class should inherit from Version.
|
17
17
|
# :ignore an array of attributes for which a new `Version` will not be created if only they change.
|
18
18
|
# :only inverse of `ignore` - a new `Version` will be created only for these attributes if supplied
|
19
|
+
# :skip fields to ignore completely. As with `ignore`, updates to these fields will not create
|
20
|
+
# a new `Version`. In addition, these fields will not be included in the serialized versions
|
21
|
+
# of the object whenever a new `Version` is created.
|
19
22
|
# :meta a hash of extra data to store. You must add a column to the `versions` table for each key.
|
20
23
|
# Values are objects or procs (which are called with `self`, i.e. the model with the paper
|
21
24
|
# trail). See `PaperTrail::Controller.info_for_paper_trail` for how to store data from
|
@@ -40,6 +43,9 @@ module PaperTrail
|
|
40
43
|
class_attribute :ignore
|
41
44
|
self.ignore = ([options[:ignore]].flatten.compact || []).map &:to_s
|
42
45
|
|
46
|
+
class_attribute :skip
|
47
|
+
self.skip = ([options[:skip]].flatten.compact || []).map &:to_s
|
48
|
+
|
43
49
|
class_attribute :only
|
44
50
|
self.only = ([options[:only]].flatten.compact || []).map &:to_s
|
45
51
|
|
@@ -191,7 +197,7 @@ module PaperTrail
|
|
191
197
|
end
|
192
198
|
|
193
199
|
def object_to_string(object)
|
194
|
-
object.attributes.to_yaml
|
200
|
+
object.attributes.except(*self.class.skip).to_yaml
|
195
201
|
end
|
196
202
|
|
197
203
|
def changed_notably?
|
@@ -203,7 +209,7 @@ module PaperTrail
|
|
203
209
|
end
|
204
210
|
|
205
211
|
def changed_and_not_ignored
|
206
|
-
changed - self.class.ignore
|
212
|
+
changed - self.class.ignore - self.class.skip
|
207
213
|
end
|
208
214
|
|
209
215
|
def switched_on?
|
data/test/dummy/db/test.sqlite3
CHANGED
Binary file
|
data/test/unit/model_test.rb
CHANGED
@@ -28,7 +28,36 @@ class HasPaperTrailModelTest < ActiveSupport::TestCase
|
|
28
28
|
setup { @article.update_attributes :abstract => 'Other abstract'}
|
29
29
|
should_not_change('the number of versions') { Version.count }
|
30
30
|
end
|
31
|
+
|
32
|
+
context 'which updates a skipped column' do
|
33
|
+
setup { @article.update_attributes :file_upload => 'Your data goes here' }
|
34
|
+
should_not_change('the number of versions') { Version.count }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'which updates a skipped column and a selected column' do
|
38
|
+
setup { @article.update_attributes :file_upload => 'Your data goes here', :content => 'Some text here.' }
|
39
|
+
should_change('the number of versions', :by => 1) { Version.count }
|
31
40
|
|
41
|
+
should 'have stored only non-skipped attributes' do
|
42
|
+
assert_equal ({'content' => [nil, 'Some text here.']}), @article.versions.last.changeset
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'and when updated again' do
|
46
|
+
setup do
|
47
|
+
@article.update_attributes :file_upload => 'More data goes here', :content => 'More text here.'
|
48
|
+
@old_article = @article.versions.last
|
49
|
+
end
|
50
|
+
|
51
|
+
should 'have removed the skipped attributes when saving the previous version' do
|
52
|
+
assert_equal nil, YAML::load(@old_article.object)['file_upload']
|
53
|
+
end
|
54
|
+
|
55
|
+
should 'have kept the non-skipped attributes in the previous version' do
|
56
|
+
assert_equal 'Some text here.', YAML::load(@old_article.object)['content']
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
32
61
|
end
|
33
62
|
|
34
63
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: paper_trail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 2.4.
|
9
|
+
- 1
|
10
|
+
version: 2.4.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andy Stewart
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09
|
18
|
+
date: 2011-11-09 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|